views.py 1.12 KB
Newer Older
1
# Create your views here.
stef's avatar
stef committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

from forms import AddViolation
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response

def add(request):
    if request.method == 'POST': # If the form has been submitted...
        form = ViolationForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            return HttpResponseRedirect('/') # Redirect after POST
    else:
        form = AddViolation() # An unbound form

    return render_to_response('add.html', {
        'form': form,
    })

def edit(request):
    if request.method == 'POST': # If the form has been submitted...
        form = ViolationForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            return HttpResponseRedirect('/') # Redirect after POST
    else:
        form = AddViolation() # An unbound form

    return render_to_response('add.html', {
        'form': form,
    })