Commit 01f91674 authored by stef's avatar stef

[enh] added filters for list by country + operator

parent 96ded2fd
...@@ -9,7 +9,7 @@ from django.core.exceptions import ObjectDoesNotExist ...@@ -9,7 +9,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from models import Violation, Attachment, Comment, Confirmation from models import Violation, Attachment, Comment, Confirmation, COUNTRIES
from tempfile import mkstemp from tempfile import mkstemp
from datetime import datetime from datetime import datetime
import hashlib, os, re, json, smtplib import hashlib, os, re, json, smtplib
...@@ -198,6 +198,15 @@ def index(request): ...@@ -198,6 +198,15 @@ def index(request):
'violations': v_list }, 'violations': v_list },
context_instance=RequestContext(request)) context_instance=RequestContext(request))
def filter_violations(request, country, operator=None):
if country not in map(itemgetter(0),COUNTRIES):
raise Http404
if not operator:
violations = Violation.objects.filter(activationid='', country=country)
else:
violations = Violation.objects.filter(activationid='', country=country, operator=operator)
return render_to_response('list.html', {"violations": violations},context_instance=RequestContext(request))
def list_violations(request): def list_violations(request):
violations = Violation.objects.filter(activationid='') violations = Violation.objects.filter(activationid='')
return render_to_response('list.html', {"violations": violations},context_instance=RequestContext(request)) return render_to_response('list.html', {"violations": violations},context_instance=RequestContext(request))
......
...@@ -11,6 +11,7 @@ admin.autodiscover() ...@@ -11,6 +11,7 @@ admin.autodiscover()
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^$', bt.index), (r'^$', bt.index),
(r'^list/$', bt.list_violations), (r'^list/$', bt.list_violations),
(r'^list/(?P<country>[^/]*)(/(?P<operator>[^/]*))?$', bt.filter_violations),
(r'^ajax/(?P<country>[^/]*)(/(?P<operator>[^/]*))?$', bt.ajax), (r'^ajax/(?P<country>[^/]*)(/(?P<operator>[^/]*))?$', bt.ajax),
(r'^add/$', bt.add), (r'^add/$', bt.add),
(r'^view/(?P<id>[0-9]*)$', bt.view), (r'^view/(?P<id>[0-9]*)$', bt.view),
......
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