Commit ea0bc654 authored by Olivier Girardot's avatar Olivier Girardot

create cannonical url for violations and refactored templates to use them

parent a56b53f1
......@@ -12,7 +12,7 @@ class RssSiteNewsFeed(Feed):
return Violation.objects.filter(activationid='').order_by('-id')[:10]
def item_link(self, item):
return "/view/%s" % item.pk
return item.get_absolute_url()
def item_title(self, item):
return "%s (%s) %s" % (item.operator, item.country, item.contract)
......
......@@ -81,6 +81,11 @@ class Violation(models.Model):
class Admin:
pass
@models.permalink
def get_absolute_url(self):
return ('violation_url', (),
{'id': self.pk })
def __unicode__(self):
return "#%s %s/%s" % (self.pk, self.country, self.operator)
......
from forms import AddViolation, SearchViolation
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.core.files import File
from django.core.servers.basehttp import FileWrapper
......@@ -80,9 +80,9 @@ def moderate(request):
messages.add_message(request, messages.INFO, _('No such key'))
return HttpResponseRedirect('/') # Redirect after POST
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['From'] = 'nnmon@respectmynet.eu'
msg['To'] = v.comment_set.get().submitter_email
......@@ -96,7 +96,7 @@ def moderate(request):
pass
v.activationid=''
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':
v.delete()
messages.add_message(request, messages.INFO, _('Thank you for deleting the submission.'))
......
......@@ -144,7 +144,7 @@ $(document).ready(function(){
<tbody>
{% for violation in violations %}
<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">
<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>
......
......@@ -97,13 +97,13 @@
<tbody>
{% for violation in violations %}
<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="/view/{{violation.pk}}">{{ violation.country|country }}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ violation.operator }}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ violation.contract }}</a></td>
<td><a class="cell-link" href="/view/{{violation.pk}}">{{ 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="/view/{{violation.pk}}">{{ violation.media|media }}</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="{{ violation.get_absolute_url }}">{{ violation.country|country }}</a></td>
<td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.operator }}</a></td>
<td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.contract }}</a></td>
<td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.resource_name }}</a></td>
<td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.type|type }}</a></td>
<td><a class="cell-link" href="{{ violation.get_absolute_url }}">{{ violation.media|media }}</a></td>
<td>{{ violation.confirmations }}</td>
<td>
<div class="confirm"><a class="button">{% trans "Me too!" %}</a>
......
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.contrib import admin
from bt import views as bt
......@@ -24,15 +24,17 @@ urlpatterns = patterns('',
url(r'^add/$',
view=bt.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]*)$',
view=bt.view,
name="view"),
name="violation_url"),
url(r'^attach/(?P<id>[0-9]*)$',
view=bt.get_attach,
name="attach"),
url(r'^(?P<id>[0-9]*)$',
view=bt.view,
name="violation_view"),
# different data outputs
url(r'^csv$',
view=bt.ascsv,
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