views.py 1.3 KB
Newer Older
stef's avatar
stef committed
1 2 3
from forms import AddViolation
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response
4 5 6
from django.template import RequestContext
from models import Violation
import json
stef's avatar
stef committed
7 8 9

def add(request):
    if request.method == 'POST': # If the form has been submitted...
10
        form = AddViolation(request.POST) # A form bound to the POST data
stef's avatar
stef committed
11 12 13
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
14
            print 'asdf',form.cleaned_data
stef's avatar
stef committed
15 16 17 18
            return HttpResponseRedirect('/') # Redirect after POST
    else:
        form = AddViolation() # An unbound form

19 20 21
    return render_to_response('add.html',
                              { 'form': form, },
                              context_instance=RequestContext(request))
stef's avatar
stef committed
22

23 24 25 26 27 28 29
def ajax(request, country=None, operator=None):
    if not operator:
        print 'c',sorted(list(set([x.operator for x in Violation.objects.filter(country=country)])))
        return HttpResponse('["Vodafone", "T-Mobile", "T-Home", "UPC Chello", "Orange"]')
    else:
        print 'co', sorted(list(set([x.operator for x in Violation.objects.filter(country=country).filter(operator=operator)])))
        return HttpResponse('["Basic", "Surfer", "Gamer", "Pro", "Business"]')