Commits

Matthew Marshall committed b9b15d6

Added delete page.

Comments (0)

Files changed (7)

 
 RewriteRule ^(u/\w+/\w+/?)$ dispatch.fcgi/$1 [L]
 RewriteRule ^(u/\w+/\w+/edit/?)$ dispatch.fcgi/$1 [L]
+RewriteRule ^(u/\w+/\w+/delete/?)$ dispatch.fcgi/$1 [L]
 
 RewriteRule ^(u/.+)$ hgfcgi/dispatch.fcgi/$1 [L]
 
             form=form,
         ), context_instance=RequestContext(request)
     )
+
+@login_required
+def delete_repo(request, username, reponame):
+    if username != request.user.username:
+        from django.http import HttpResponseForbidden
+        return HttpResponseForbidden(
+                "You don't have permission to delete this repository.")
+    repo = get_object_or_404(Repo, owner__username=username, name=reponame)
+
+    if request.POST.get('confirm'):
+        repo.delete()
+        return HttpResponseRedirect('/repo_deleted/')
+    return render_to_response('repos/delete.html',
+            dict(repo=repo),
+            context_instance=RequestContext(request))

templates/profile.html

 
 {% if user.repo_set.count %}
 <div class="span-14 clear">
+    <table>
     {% for repo in user.repo_set.all %}
-        <p><a href="{{repo.get_absolute_url}}">
-            {% if repo.long_name %}{{repo.long_name}}
-            {% else %}{{repo.name}}{% endif %}
-        </a></p>
+        <tr><td><a href="{{repo.get_absolute_url}}">
+            {{repo.get_long_name}}
+        </a></td><td><a href="{{repo.get_absolute_url}}edit/">edit</a> | <a href="{{repo.get_absolute_url}}delete/">delete</a></td></tr>
     {% endfor %}
+    </table>
 </div>
 {% endif %}
 

templates/repos/delete.html

+{% extends "base.html" %}
+
+{% block title %}Delete {{repo.get_long_name}}?{%endblock%}
+
+{% block content %}
+<div class="span-14">
+    <form method="POST" action='.'>
+        <fieldset>
+            <legend>Delet repository?</legend>
+            <p>
+                Are you sure you want to permanently delete {{repo.get_long_name}}?
+            </p>
+            <input type="submit" value="KILL! KILL! KILL!" name="confirm" />
+            <br />
+            <a href="{{repo.get_absolute_url}}">Nevermind...</a>
+        </fieldset>
+    </form>
+</div>
+{% endblock %}

templates/repos/deleted.html

+{% extends "base.html" %}
+
+{% block title %}Repository deleted{%endblock%}
+
+{% block content %}
+<div class="span-14">
+    <p>
+        The repository has been deleted.
+    </p>
+    <p>
+        <a href="/">Back to homepage</a>
+    </p>
+</div>
+{% endblock %}

templates/repos/edit.html

 {% block title %}Editing information for {{repo.get_long_name}}{% endblock %}
 
 {% block content %}
-<div class="span-14 last">
+<div class="span-14">
     <form method="POST" action=".">
         <fieldset>
             <legend>Edit information for <a href="{{repo.get_absolute_url}}">{{repo.get_long_name}}</a>:</legend>
+            <p><a href="{{repo.get_absolute_url}}delete/">Delete this repository.</a></p>
             {% for field in form %}
                     <div class="form-row {%if field.field.required %}required{%endif%} {%if field.errors%}errors{%endif%}">
                         {% if field.errors %}{{field.errors}}{% endif %}
     (r'^u/(?P<username>\w+)/(?P<reponame>\w+)/$', 'freehg.repos.views.summary'),
     (r'^u/(?P<username>\w+)/(?P<reponame>\w+)/edit/$',
             'freehg.repos.views.edit_repo'),
+    (r'^u/(?P<username>\w+)/(?P<reponame>\w+)/delete/$',
+            'freehg.repos.views.delete_repo'),
+    (r'^repo_deleted/$', direct_to_template, {'template':'repos/deleted.html'}),
+    
 
     # Uncomment this for admin:
     (r'^admin/', include('django.contrib.admin.urls')),