Andrey Stelmashenko avatar Andrey Stelmashenko committed c9e7c8a

Added delete repository feature.

Comments (0)

Files changed (7)

hgate/app/forms.py

         else:
             messages.warning(request,
                 _("There is already a group with such a name. Group '%s' wasn`t changed.") % old_name)
-        return HttpResponseRedirect(reverse('index'))
+        return HttpResponseRedirect(reverse('index'))

hgate/app/modhg/repository.py

         hgweb.add_paths(name, path)
 
 
-def delete(path, name="", has_no_group=False):
+def delete(path, name=""):
     """
     Deletes single repository with it directory tree.
     """
         shutil.rmtree(path) #, ignore_errors=True - to ignore any problem like "Permission denied"
     except shutil.Error as e: #probably more specific exception is needed
         raise RepositoryException("Repository [%s] is not removed, because of error: %s" % (path, str(e)))
-    if has_no_group:
+    if name != "": # no group
         hgweb = HGWeb(settings.HGWEB_CONFIG)
         hgweb.del_paths(name)
 

hgate/app/views/index.py

     edit_group_form = ManageGroupsForm(hgweb_cfg_hash, prefix=EDIT_GROUP_FORM_PREFIX)
 
     model = {"tree": tree,
-             "groups": _ext_groups_with_amount_of_repos_and_collection_flag(groups, collection_names, _tree)}
+             "groups": _ext_groups_with_amount_of_repos_and_collection_flag(groups, collection_names, _tree),
+             "default_path": settings.REPOSITORIES_ROOT}
 
     if request.method == 'POST':
         if "create_group" in request.POST:

hgate/app/views/repo.py

 from hgate.app import modhg
 from hgate.app.forms import RepositoryForm, FileHashForm
 from hgate.app.modhg.HGWeb import HGWeb
-from hgate.app.modhg.repository import get_absolute_repository_path
+from hgate.app.modhg import repository
 from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect
 from django.contrib import messages
                 form.export_values(hgweb, request.POST)
                 file_hash = md5_for_file(settings.HGWEB_CONFIG)
                 messages.success(request, _("Global settings saved successfully."))
-        # re-set errors if any occurs in the is_valid method.
+                # re-set errors if any occurs in the is_valid method.
     errors = None
     if form is not None:
         errors = form._errors
     tree = prepare_tree(modhg.repository.get_tree(hgweb.get_paths(), hgweb.get_collections()))
     form = None
     model = {"tree": tree, "global": False, "repo_path": repo_path}
-    full_repository_path = get_absolute_repository_path(repo_path)
+    full_repository_path = repository.get_absolute_repository_path(repo_path)
     hgrc_path = os.path.join(full_repository_path, ".hg", "hgrc")
     _check_access_local_hgrc(request, hgrc_path)
     try:
         hgrc = None
         file_hash = None
 
+    #DELETE_REPO_FORM_PREFIX = "delete_repo_form"
+    delete_repo_form = FileHashForm(file_hash)
+
     repo_field_delete_form = FileHashForm(file_hash)
 
     if request.method == 'POST' and hgrc is not None:
                 repo_field_delete_form = FileHashForm(file_hash)
                 messages.success(request, _("Repository settings saved successfully."))
         elif 'delete_field' in request.POST:
-            if request.method == 'POST':
-                repo_field_delete_form = FileHashForm(file_hash, request.POST)
-                if repo_field_delete_form.is_valid():
-                    parameter = request.POST.get('parameter')
-                    hgrc.del_web_key(parameter)
-                    return HttpResponseRedirect(reverse("repository", args=[repo_path]))
-        # re-set errors if any occurs in the is_valid method.
+            repo_field_delete_form = FileHashForm(file_hash, request.POST)
+            if repo_field_delete_form.is_valid():
+                parameter = request.POST.get('parameter')
+                hgrc.del_web_key(parameter)
+                return HttpResponseRedirect(reverse("repository", args=[repo_path]))
+        elif 'sure_delete' in request.POST:
+            delete_repo_form = FileHashForm(file_hash, request.POST)
+            if delete_repo_form.is_valid():
+                repository.delete(full_repository_path, repo_path)
+                messages.success(request, _("Repository '%s' deleted successfully.") % repo_path)
+                return HttpResponseRedirect(reverse("index"))
+
+
+    # re-set errors if any occurs in the is_valid method.
     errors = None
     if form is not None:
         errors = form._errors
 
     model["form"] = form
     model["repo_field_delete_form"] = repo_field_delete_form
+    model["delete_repo_form"] = delete_repo_form
+
     return model
 
 # helpers

hgate/media/css/main.css

     color: #CC4400;
 }
 
+.repo_edit {
+    margin-top: 2em;
+}
+
 .repo_edit th{
     text-align: left;
     padding-right: 5px;
     display: none;
 }
 
+.repo_name .spoiler-head {
+    background-color: #D3D9E5;
+    padding: 3px 0 3px 9px;
+    cursor: pointer;
+}
+
+.repo_name .folded span {
+    background:  url(../images/treeview-default.gif) -50px -47px no-repeat;
+    height: 16px;
+    width: 16px;
+    margin-left: -6px;
+    float: left;
+}
+
+.repo_name .unfolded span {
+    background:  url(../images/treeview-default.gif) -18px -91px no-repeat;
+    height: 16px;
+    width: 16px;
+    margin-left: -6px;
+    float: left;
+}
+
+.repo_name h2 {
+    margin-bottom: 0.25em;
+}
+
+.repo_name .spoiler-body, table {
+    background-color: #ECECEC;
+}
+
+.repo_name .spoiler-body {
+    padding: 7px 0 7px 10px;
+}
+
+.repo_name td {
+    background-color: #F4F4F4;
+}
+
+.repo_name .repo_delete {
+    color: #FF6666;
+}
+
 /*Errors page*/
 .text {
     text-align: center;

hgate/templates/index.html

                 $("#delete_group_form input[name='group_name']").val('');
             }
         }
-        $(document).ready(function() {
+        $(document).ready(function () {
             $("td.action span:first-child").click(function () {//edit
                 $(this).nextAll().show();
                 $(this).hide();
                 tdpath.html('');
                 $("<input type='text' value='" + path + "' />").filter("input")
                         .width(path_width)
+//                        .keypress(function(e) {
+//                            if(e.keyCode == 13) {
+//                                todo commit by enter
+//                            }
+//                        })
                         .end().appendTo(tdpath);
                 tdname.html('');
                 $("<input type='text' value='" + name + "' />").filter("input")
                         .end().appendTo(tdname);
 
                 $("<span>{% trans 'cancel' %}</span>").filter("span").click(
-                        function() {
+                        function () {
                             tdpath.html(path);
                             tdname.html(name);
                             $(this).prev().prev().show();
                             $(this).remove();
                         }).end().insertAfter(this);
                 $("<span style='padding-right:10pt;'>{% trans 'save' %}</span>").filter("span").click(
-                        function() {
+                        function () {
                             $("#old_group_name").val(name);
                             $("#old_group_path").val(path);
                             //getting td with collection
                         }).end().insertAfter(this);
             });
             $(".group_list tbody tr").hover(
-                    function() {
+                    function () {
                         $(this).addClass("rowHover")
                     },
-                    function() {
+                    function () {
                         $(this).removeClass("rowHover");
                     }
             );
             $(".tooltip").tooltip({
-                        delay: 1000,
-                        showBody: " : ",
-                        showURL: false
-                    });
-            $("#is_collection").click(function() {
+                delay:1000,
+                showBody:" : ",
+                showURL:false
+            });
+            $("#is_collection").click(function () {
                 $("#id_is_collection").val(this.checked ? 'True' : 'False');
             });
         })
             <tr>
                 <td colspan="2" class="bottom">
                     <input class="submit" type="submit" name="create_repo" value="{% trans "Create" %}"/>
-                    <span title="{% trans 'Create new repository : Path: default path if no group is specified or concrete group path.<br>Name: specified name.<br>This action creates dir with repository name and makes &apos;hg init&apos; in that dir.' %}"
+                    <span title="
+                            {% blocktrans %} Create new repository : Path: default path ({{ default_path }}) if no group is specified or concrete group path.<br>Name: specified name.<br>This action creates dir with repository name and makes &apos;hg init&apos; in that dir. {% endblocktrans %} %}"
                           class="tooltip">[ ? ]</span>
                 </td>
             </tr>
                     <label for="is_collection">{% trans "Collection" %}:</label>
                 </th>
                 <td align="left">
-                    <input type="checkbox" id="is_collection" style="width: auto;" />
+                    <input type="checkbox" id="is_collection" style="width: auto;"/>
                 </td>
             </tr>
             <tr>
         {% for gr_key, gr_path, rep_count, is_collection in groups %}
             <tr class="{% cycle odd,even %}">
                 <td>
-                    <input type="hidden" value="{{ is_collection }}" />
-                    {% if is_collection%}
+                    <input type="hidden" value="{{ is_collection }}"/>
+                    {% if is_collection %}
                         [collections]
                     {% else %}
                         [paths]
                 <td>{{ gr_key }}</td>
                 <td>{{ gr_path }}</td>
                 <td class="action">
-{#                    {% if gr_key not in collections %}#}
                     <span title="{% trans 'Click to start editing this group: you can change name and path.' %}">
                         {% trans "edit" %}
                     </span>&nbsp;&nbsp;
                           title="{% trans 'Delete the group: removes record about this group from hgweb.config. Deletes group`s dir and all it`s subdirectories.' %}">
                          {% trans "delete" %}
                     </span>
-{#                    {% endif %}#}
                     {% if gr_key == old_group_name and gr_path == old_group_path %}
                         <div id="error_here">
                             <script type="text/javascript">
-                                $(document).ready(function() {
+                                $(document).ready(function () {
                                     $("#error_here").prev().prev().click();
                                     var td_path_html = $("#error_here").parent().prev().html();
                                     var td_name_html = $("#error_here").parent().prev().prev().html();

hgate/templates/repository.html

 {% load repository_extra %}
 
 {% block head %}
-{{ block.super }}
-<script>
-    $(document).ready(function(){
-    $(".repo_edit input:visible, .repo_edit select").attr("disabled","disabled");
-    $(".repo_edit input.submit").removeAttr("disabled");
-    $(".repo_field_edit_link").click(function(){
-        $(this).hide();
-        var row = $(this).parents("tr:first");
-        row.find(".repo_field_cancel_link").show();
-        var inp = row.find("input, select");
-        inp.removeAttr("disabled");
-        inp.focus();
-        return false;
-    });
-    $(".repo_field_cancel_link").click(function(){
-        $(this).hide();
-        var row = $(this).parents("tr:first");
-        row.find(".repo_field_edit_link").show();
-        var inp = row.find("input, select");
-        inp.attr("disabled","disabled");
-        return false;
-    });
-    $(".repo_field_delete_link").click(function(){
-        var field = $(this).parents("tr:first").find("th").text();
-        if (confirm("{% trans "Are you sure you want to delete parameter " %}" + "\"" + field + "\"" + "{% trans " from hgrc file" %}" + "?")) {
-            $('#repo_field_delete_form #parameter').val(field);
-            $('#repo_field_delete_form').submit();
-        }
-    });
-    $(".tooltip").tooltip({
-                delay: 1000,
-                showBody: " : ",
-                showURL: false
+    {{ block.super }}
+    <script>
+        $(document).ready(function () {
+            $(".repo_edit input:visible, .repo_edit select").attr("disabled", "disabled");
+            $(".repo_edit input.submit").removeAttr("disabled");
+            $(".repo_field_edit_link").click(function () {
+                $(this).hide();
+                var row = $(this).parents("tr:first");
+                row.find(".repo_field_cancel_link").show();
+                var inp = row.find("input, select");
+                inp.removeAttr("disabled");
+                inp.focus();
+                return false;
             });
-    })
-</script>
+            $(".repo_field_cancel_link").click(function () {
+                $(this).hide();
+                var row = $(this).parents("tr:first");
+                row.find(".repo_field_edit_link").show();
+                var inp = row.find("input, select");
+                inp.attr("disabled", "disabled");
+                return false;
+            });
+            $(".repo_field_delete_link").click(function () {
+                var field = $(this).parents("tr:first").find("th").text();
+                if (confirm("{% trans "Are you sure you want to delete parameter " %}" + "\"" + field + "\"" + "{% trans " from hgrc file" %}" + "?")) {
+                    $('#repo_field_delete_form #parameter').val(field);
+                    $('#repo_field_delete_form').submit();
+                }
+            });
+            $(".tooltip").tooltip({
+                delay:1000,
+                showBody:" : ",
+                showURL:false
+            });
+            $('.spoiler-body').hide();
+            $('.spoiler-head').click(function(){
+                $(this).toggleClass("folded").toggleClass("unfolded").next().toggle()
+            });
+            $("#repo_delete").click(function() {
+                if($("#sure_delete").is(':checked')) {
+                    $("#delete_repo_form").submit();
+                }
+            });
+        })
+    </script>
 {% endblock %}
 
 {% block menu_extra %}
 {% endblock %}
 
 {% block content %}
-{% if global %}
-    <h2>{% trans "HgWeb config" %}</h2>
-    {% url hgweb as repo_url %}
-{% else %}
-    <h2>{% trans "Repository" %}: {{ repo_path }}</h2>
-    {% url repository repo_path as repo_url %}
-{% endif %}
+    {% if global %}
+        <h2>{% trans "HgWeb config" %}</h2>
+        {% url hgweb as repo_url %}
+    {% else %}
+        {% url repository repo_path as repo_url %}
+        <div class="repo_name">
+            <h2>{% trans "Repository" %}: {{ repo_path }}</h2>
+            <div class="spoiler-head folded"><span></span>Actions</div>
+            <div class="spoiler-body">
+                <table>
+                    <tr><th colspan="3" align="left">{% trans "Change repository:" %} <span title="{% trans 'TODO.' %}" class="tooltip">[ ? ]</span></th></tr>
+                    <tr>
+                        <td>
+                            <label for="repo_name">Name: </label><input type="text" id="repo_name" value="{{ repo_path }}"/>
+                        </td>
+                        <td>
+                            <label for="repo_path">Path: </label><input type="text" id="repo_path" value="{{ repo_path }}"/>
+                        </td>
+                        <td><a href="#">Save</a></td>
+                    </tr>
+                    <tr><th colspan="3" align="left">{% trans "Delete repository:" %} <span title="{% trans 'TODO.' %}" class="tooltip">[ ? ]</span></th></tr>
+                    <tr>
+                        <td colspan="2">
+                            <form style="padding: 0; margin: 0;" action="{{ repo_url }}" id="delete_repo_form" method="post">
+                                <label>Sure delete?
+                                    <input type="checkbox" id="sure_delete" name="sure_delete" />
+                                </label>
+                                {{ repo_field_delete_form.non_field_errors }}
+                                {% for hidden in repo_field_delete_form.hidden_fields %}
+                                    {{ hidden }}
+                                {% endfor %}
+                            </form>
+                        </td>
+                        <td><a class="repo_delete" id="repo_delete" href="#">Delete</a></td>
+                    </tr>
+                </table>
+            </div>
+        </div>
+    {% endif %}
 
-<form action="{{ repo_url }}" id="repo_field_delete_form" name="repo_field_delete_form" method="post">
-    {{ repo_field_delete_form.non_field_errors }}
-    {% for hidden in repo_field_delete_form.hidden_fields %}
-        {{ hidden }}
-    {% endfor %}
-    <input type="hidden" name="parameter" id="parameter" value="" />
-    <input type="hidden" name="delete_field" />
-</form>
+    <form action="{{ repo_url }}" id="repo_field_delete_form" name="repo_field_delete_form" method="post">
+        {{ repo_field_delete_form.non_field_errors }}
+        {% for hidden in repo_field_delete_form.hidden_fields %}
+            {{ hidden }}
+        {% endfor %}
+        <input type="hidden" name="parameter" id="parameter" value=""/>
+        <input type="hidden" name="delete_field"/>
+    </form>
 
-<form class="repo_edit" action="{{ repo_url }}" method="post">
-    {{ form.non_field_errors }}
-    {% for hidden in form.hidden_fields %}
-        {{ hidden }}
-    {% endfor %}
-    <table>
-        {% for field in form.visible_fields %}
-            <tr class="{{ form|field_class:field }}">
-                <th>{{ field.label_tag }}</th>
-                <td class="action">{{ field.errors }}{{ field }}<span title="{% trans "Delete parameter : remove this parameter from the local hgrc file" %}" class="tooltip repo_field_delete_link"></span></td>
-                <td><a href="#" class="repo_field_edit_link">{% trans "Edit" %}</a><a href="#" class="repo_field_cancel_link">{% trans "Cancel" %}</a></td>
+    <form class="repo_edit" action="{{ repo_url }}" method="post">
+        {{ form.non_field_errors }}
+        {% for hidden in form.hidden_fields %}
+            {{ hidden }}
+        {% endfor %}
+        <table>
+            {% for field in form.visible_fields %}
+                <tr class="{{ form|field_class:field }}">
+                    <th>{{ field.label_tag }}</th>
+                    <td class="action">{{ field.errors }}{{ field }}<span
+                            title="{% trans "Delete parameter : remove this parameter from the local hgrc file" %}"
+                            class="tooltip repo_field_delete_link"></span></td>
+                    <td><a href="#" class="repo_field_edit_link">{% trans "Edit" %}</a><a href="#"
+                                                                                          class="repo_field_cancel_link">{% trans "Cancel" %}</a>
+                    </td>
+                </tr>
+            {% endfor %}
+            <tr>
+                <td colspan="2" class="bottom">
+                    <input class="submit" type="submit" name="save" value="{% trans "Save" %}"/>
+                    {% if global %}
+                        <span title="{% trans 'Save global configuration : Modifies [web] section in the hgweb.config.' %}"
+                              class="tooltip">[ ? ]</span>
+                    {% else %}
+                        <span title="{% trans 'Save repository configuration : Modifies [web] section of the hgrc of the repository.' %}"
+                              class="tooltip">[ ? ]</span>
+                    {% endif %}
+                </td>
             </tr>
-        {% endfor %}
+        </table>
+    </form>
+    <table class="legend">
         <tr>
-            <td colspan="2" class="bottom">
-                <input class="submit" type="submit" name="save" value="{% trans "Save" %}" />
-                {% if global %}
-                    <span title="{% trans 'Save global configuration : Modifies [web] section in the hgweb.config.' %}"
-                          class="tooltip">[ ? ]</span>
-                {% else %}
-                    <span title="{% trans 'Save repository configuration : Modifies [web] section of the hgrc of the repository.' %}"
-                          class="tooltip">[ ? ]</span>
-                {% endif %}
-            </td>
+            <th>Colors:</th>
         </tr>
+        {% if not global %}
+            <tr>
+                <td class="r_val_local">{% trans "Value is set in the local hgrc file" %}</td>
+            </tr>
+        {% endif %}
+        <tr>
+            <td class="r_val_global">{% trans "Value is set in the hgweb config" %}</td>
+        </tr>
+        {% if not global %}
+            <tr>
+                <td class="r_val_default">{% trans "Value not set in any config" %}</td>
+            </tr>
+        {% endif %}
+        {% if global %}
+            <tr>
+                <td class="r_val_default">{% trans "Value not set in hgweb config" %}</td>
+            </tr>
+        {% endif %}
     </table>
-</form>
-<table class="legend">
-<tr><th>Colors:</th></tr>
-{% if not global %}
-<tr><td class="r_val_local">{% trans "Value is set in the local hgrc file" %}</td></tr>
-{% endif %}
-<tr><td class="r_val_global">{% trans "Value is set in the hgweb config" %}</td></tr>
-{% if not global %}
-<tr><td class="r_val_default">{% trans "Value not set in any config" %}</td></tr>
-{% endif %}
-{% if global %}
-<tr><td class="r_val_default">{% trans "Value not set in hgweb config" %}</td></tr>
-{% endif %}
-</table>
+
+
 {% endblock %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.