-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
45 lines (34 loc) · 1.06 KB
/
views.py
File metadata and controls
45 lines (34 loc) · 1.06 KB
1
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
34
35
36
37
38
39
40
41
42
43
44
45
from annoying.decorators import render_to, ajax_request
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_POST
from basic.widgets import CalendarWidget
from basic.models import Person, Location
from basic.forms import PersonForm, PriorityForm
@render_to('index.html')
def index(request):
person = Person.objects.get(pk=1)
return locals()
@render_to('requests.html')
def requests(request):
priority = request.GET.get('priority', 0)
form = PriorityForm({'priority': priority})
locations = Location.objects.filter(priority=priority)[:10]
return locals()
@login_required
@render_to('edit.html')
def edit(request):
form = PersonForm(instance=Person.objects.get(pk=1))
calendar = CalendarWidget()
return locals()
@login_required
@require_POST
@ajax_request
def save(request):
form = PersonForm(request.POST, request.FILES,
instance=Person.objects.get(pk=1))
if form.is_valid():
form.save()
return {'result': 1}
else:
return {'result': 0, 'errors': form.errors}