Commit ea0bc654 authored by Olivier Girardot's avatar Olivier Girardot
Browse files

create cannonical url for violations and refactored templates to use them

parent a56b53f1
...@@ -12,7 +12,7 @@ class RssSiteNewsFeed(Feed): ...@@ -12,7 +12,7 @@ class RssSiteNewsFeed(Feed):
return Violation.objects.filter(activationid='').order_by('-id')[:10] return Violation.objects.filter(activationid='').order_by('-id')[:10]
def item_link(self, item): def item_link(self, item):
return "/view/%s" % item.pk return item.get_absolute_url()
def item_title(self, item): def item_title(self, item):
return "%s (%s) %s" % (item.operator, item.country, item.contract) return "%s (%s) %s" % (item.operator, item.country, item.contract)
......
...@@ -81,6 +81,11 @@ class Violation(models.Model): ...@@ -81,6 +81,11 @@ class Violation(models.Model):
class Admin: class Admin:
pass pass
@models.permalink
def get_absolute_url(self):
return ('violation_url', (),
{'id': self.pk })
def __unicode__(self): def __unicode__(self):
return "#%s %s/%s" % (self.pk, self.country, self.operator) return "#%s %s/%s" % (self.pk, self.country, self.operator)
......
from forms import AddViolation, SearchViolation from forms import AddViolation, SearchViolation
from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext, loader, Context from django.template import RequestContext, loader, Context
from django.core.files import File from django.core.files import File
from django.core.servers.basehttp import FileWrapper from django.core.servers.basehttp import FileWrapper
...@@ -80,9 +80,9 @@ def moderate(request): ...@@ -80,9 +80,9 @@ def moderate(request):
messages.add_message(request, messages.INFO, _('No such key')) messages.add_message(request, messages.INFO, _('No such key'))
return HttpResponseRedirect('/') # Redirect after POST return HttpResponseRedirect('/') # Redirect after POST
if request.GET.get('action','')=='approve': if request.GET.get('action','')=='approve':
messages.add_message(request, messages.INFO, _('Thank you for approving the <a href="/view/%s">submission</a>.' % v.id)) messages.add_message(request, messages.INFO, _('Thank you for approving the <a href="%s">submission</a>.' % v.get_absolute_url))
msg = MIMEText(_("Your report has been approved.\nTo see it, please visit: %s/view/%s") % (settings.ROOT_URL or 'http://localhost:8001/', v.id), _charset="utf-8") msg = MIMEText(_("Your report has been approved.\nTo see it, please visit: %s%s") % (settings.ROOT_URL or 'http://localhost:8001/', v.get_absolute_url()), _charset="utf-8")
msg['Subject'] = Header(_('NNMon submission approved').encode("Utf-8"), 'utf-8') msg['Subject'] = Header(_('NNMon submission approved').encode("Utf-8"), 'utf-8')
msg['From'] = 'nnmon@respectmynet.eu' msg['From'] = 'nnmon@respectmynet.eu'
msg['To'] = v.comment_set.get().submitter_email msg['To'] = v.comment_set.get().submitter_email
...@@ -96,7 +96,7 @@ def moderate(request): ...@@ -96,7 +96,7 @@ def moderate(request):
pass pass
v.activationid='' v.activationid=''
v.save() v.save()
return HttpResponseRedirect('/view/%s' % v.id ) # Redirect after POST return redirect(v) # Redirect after POST to violation url
if request.GET.get('action','')=='delete': if request.GET.get('action','')=='delete':
v.delete() v.delete()
messages.add_message(request, messages.INFO, _('Thank you for deleting the submission.')) messages.add_message(request, messages.INFO, _('Thank you for deleting the submission.'))
......
...@@ -144,7 +144,7 @@ $(document).ready(function(){ ...@@ -144,7 +144,7 @@ $(document).ready(function(){
<tbody> <tbody>
{% for violation in violations %} {% for violation in violations %}
<tr> <tr>
<td><a href="/view/{{violation.pk}}">{{ violation.operator }} ({{ violation.country|country }}) {{ violation.contract }}</a> <td><a href="{{ violation.get_absolute_url }}">{{ violation.operator }} ({{ violation.country|country }}) {{ violation.contract }}</a>
<div class="info-validate"> <div class="info-validate">
<form method="get" id="{{ violation.pk }}" class="confirm_form" > <form method="get" id="{{ violation.pk }}" class="confirm_form" >
<label>{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label> <label>{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
......
...@@ -97,13 +97,13 @@ ...@@ -97,13 +97,13 @@
<tbody> <tbody>
{% for violation in violations %} {% for violation in violations %}
<tr class="{%if violation.state%}{{violation.state}}{%else%}new{%endif%}-status"> <tr class="{%if violation.state%}{{violation.state}}{%else%}new{%endif%}-status">
<td><a class="cell-link" href="/view/{{violation.pk}}">{%if violation.state%}{{violation.state|status}}{%else%}{% trans "New" %}{%endif%}</a></td> <td><a class="cell-link" href="{{ violation.get_absolute_url }}">{%if violation.state%}{{violation.state|status}}{%else%}{% trans "New" %}{%endif%}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ violation.country|country }}</a></td> <td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.country|country }}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ violation.operator }}</a></td> <td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.operator }}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ violation.contract }}</a></td> <td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.contract }}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ violation.resource_name }}</a></td> <td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.resource_name }}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ violation.type|type }}</a></td> <td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.type|type }}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ violation.media|media }}</a></td> <td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.media|media }}</a></td>
<td>{{ violation.confirmations }}</td> <td>{{ violation.confirmations }}</td>
<td> <td>
<div class="confirm"><a class="button">{% trans "Me too!" %}</a> <div class="confirm"><a class="button">{% trans "Me too!" %}</a>
......
from django.conf.urls.defaults import patterns, include, url from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import direct_to_template from django.views.generic.simple import direct_to_template, redirect_to
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
from bt import views as bt from bt import views as bt
...@@ -24,15 +24,17 @@ urlpatterns = patterns('', ...@@ -24,15 +24,17 @@ urlpatterns = patterns('',
url(r'^add/$', url(r'^add/$',
view=bt.add, view=bt.add,
name="add"), name="add"),
# violation cannonical url and redirections
url(r'^(?P<id>[0-9]*)$',
redirect_to,
{'url': '/view/%(id)s'}),
url(r'^view/(?P<id>[0-9]*)$', url(r'^view/(?P<id>[0-9]*)$',
view=bt.view, view=bt.view,
name="view"), name="violation_url"),
url(r'^attach/(?P<id>[0-9]*)$', url(r'^attach/(?P<id>[0-9]*)$',
view=bt.get_attach, view=bt.get_attach,
name="attach"), name="attach"),
url(r'^(?P<id>[0-9]*)$', # different data outputs
view=bt.view,
name="violation_view"),
url(r'^csv$', url(r'^csv$',
view=bt.ascsv, view=bt.ascsv,
name="csv_output"), name="csv_output"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment