views.py 1.4 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
11
12
13
        form = AddViolation(request.POST) # A form bound to the POST data
        print form.errors
        v=Violation(**form.cleaned_data)
        print 'v',v
stef's avatar
stef committed
14
15
16
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
17
18
            v=Violation(**form.values)
            print 'v',v
stef's avatar
stef committed
19
20
21
22
23
24
            return HttpResponseRedirect('/') # Redirect after POST
    else:
        form = AddViolation() # An unbound form

    return render_to_response('add.html', {
        'form': form,
25
    }, context_instance=RequestContext(request))
stef's avatar
stef committed
26
27

def edit(request):
28
    return add(request)
stef's avatar
stef committed
29

30
31
32
33
34
35
36
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"]')