1. Luke Plant
  2. django-output-validator

Commits

Luke Plant  committed babef40

Used URL reversing throughout.

  • Participants
  • Parent commits f110e91
  • Branches default

Comments (0)

Files changed (4)

File output_validator/templates/output_validator/validationfailure_detail.html

View file
 {% extends "output_validator/base.html" %}
 {% load output_validator %}
+{% load url from future %}
 {% block content %}
-<a href="../">[up]</a>
+<a href="{% url 'output_validator.list' %}">[up]</a>
 <h2>Validation failure details</h2>
 
-<form method="post" action="delete/">{% csrf_token %}<div>
+<form method="post" action="{% url 'output_validator.delete' pk=object.id %}">{% csrf_token %}<div>
 <input type="submit" name="delete" value="Delete" />
 </div>
 </form>

File output_validator/templates/output_validator/validationfailure_list.html

View file
 {% extends "output_validator/base.html" %}
+{% load url from future %}
 {% block content %}
 
 {% if object_list %}
-	<form method="post" action="delete/">{% csrf_token %}
+	<form method="post" action="{% url 'output_validator.bulkdelete' %}">{% csrf_token %}
 	<div class="errorsfound"><p>{{ object_list|length }} page(s) with errors</p></div>
 	<div>
 	<table>
 		<tr {% if forloop.counter|divisibleby:"2" %}class="alt"{% endif %}>
 			<td>{{ failure.timestamp|date:"d M Y h:i" }}</td>
 			<td><span class="method">{{ failure.method }}</span> <span class="path">{{ failure.path|escape }}</span></td>
-			<td><a href="{{ failure.id }}/">Details</a></td>
+			<td><a href="{% url 'output_validator.detail' object_id=failure.id %}">Details</a></td>
 			<td><input type="checkbox" name="deleteitem{{ failure.id }}" /></td>
 		</tr>
 		{% endfor %}

File output_validator/urls.py

View file
 }
 
 urlpatterns = patterns('',
-    (r'^$',
+    url(r'^$',
         'django.views.generic.list_detail.object_list',
-        dict(info_dict, allow_empty=True)),
-    (r'^(?P<object_id>\d+)/$',
+        dict(info_dict, allow_empty=True),
+        name='output_validator.list'),
+    url(r'^(?P<object_id>\d+)/$',
         'django.views.generic.list_detail.object_detail',
-        info_dict),
-    (r'^(?P<object_id>\d+)/delete/$',
-        'output_validator.views.delete'),
-    (r'^delete/$',
-        'output_validator.views.bulkdelete'),
+        info_dict,
+        name='output_validator.detail'),
+    url(r'^(?P<pk>\d+)/delete/$',
+        'output_validator.views.delete',
+        name='output_validator.delete'),
+    url(r'^delete/$',
+        'output_validator.views.bulkdelete',
+        name='output_validator.bulkdelete'),
 )

File output_validator/views.py

View file
+from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect
 
 from output_validator.models import ValidationFailure
                     except ValidationFailure.DoesNotExist:
                         pass
 
-    return HttpResponseRedirect("../")
+    return HttpResponseRedirect(reverse('output_validator.list'))
 
 
-def delete(request, object_id):
+def delete(request, pk):
     if request.POST:
         try:
-            vf = ValidationFailure.objects.get(id=object_id)
+            vf = ValidationFailure.objects.get(pk=pk)
             vf.delete()
         except ValidationFailure.DoesNotExist:
             pass
-    return HttpResponseRedirect("../../")
+    return HttpResponseRedirect(reverse('output_validator.list'))