Mercurial > public > sg101
comparison gcalendar/views.py @ 1031:e1c03da72818
Get rid of some warnings in Django 1.8.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 20 Dec 2015 22:18:59 -0600 |
parents | 68c3343f3318 |
children | 110bbc78a482 |
comparison
equal
deleted
inserted
replaced
1030:d9610b1e2a3d | 1031:e1c03da72818 |
---|---|
8 from django.http import HttpResponse | 8 from django.http import HttpResponse |
9 from django.http import HttpResponseBadRequest | 9 from django.http import HttpResponseBadRequest |
10 from django.http import HttpResponseForbidden | 10 from django.http import HttpResponseForbidden |
11 from django.http import HttpResponseRedirect | 11 from django.http import HttpResponseRedirect |
12 from django.http import Http404 | 12 from django.http import Http404 |
13 from django.shortcuts import render_to_response | |
14 from django.shortcuts import get_object_or_404 | 13 from django.shortcuts import get_object_or_404 |
15 from django.template import RequestContext | 14 from django.shortcuts import render |
16 | 15 |
17 from gcalendar.forms import EventEntryForm | 16 from gcalendar.forms import EventEntryForm |
18 from gcalendar.models import Event | 17 from gcalendar.models import Event |
19 | 18 |
20 | 19 |
23 if user.is_authenticated(): | 22 if user.is_authenticated(): |
24 tz = user.profile.time_zone | 23 tz = user.profile.time_zone |
25 else: | 24 else: |
26 tz = 'US/Pacific' | 25 tz = 'US/Pacific' |
27 | 26 |
28 return render_to_response('gcalendar/index.html', { | 27 return render(request, 'gcalendar/index.html', { |
29 'tz': tz, | 28 'tz': tz, |
30 }, | 29 }) |
31 context_instance = RequestContext(request)) | |
32 | 30 |
33 | 31 |
34 @login_required | 32 @login_required |
35 def add_event(request): | 33 def add_event(request): |
36 if request.method == 'POST': | 34 if request.method == 'POST': |
42 event.save(html=form.html) | 40 event.save(html=form.html) |
43 return HttpResponseRedirect(reverse('gcalendar-add_thanks')) | 41 return HttpResponseRedirect(reverse('gcalendar-add_thanks')) |
44 else: | 42 else: |
45 form = EventEntryForm() | 43 form = EventEntryForm() |
46 | 44 |
47 return render_to_response('gcalendar/event.html', { | 45 return render(request, 'gcalendar/event.html', { |
48 'title': 'Add Calendar Event', | 46 'title': 'Add Calendar Event', |
49 'form': form, | 47 'form': form, |
50 }, | 48 }) |
51 context_instance = RequestContext(request)) | |
52 | 49 |
53 | 50 |
54 @login_required | 51 @login_required |
55 def add_thanks(request): | 52 def add_thanks(request): |
56 return render_to_response('gcalendar/thanks_add.html', { | 53 return render(request, 'gcalendar/thanks_add.html', { |
57 }, | 54 }) |
58 context_instance = RequestContext(request)) | |
59 | 55 |
60 | 56 |
61 @login_required | 57 @login_required |
62 def edit_events(request): | 58 def edit_events(request): |
63 events = Event.objects.filter(user=request.user, status=Event.ON_CAL).\ | 59 events = Event.objects.filter(user=request.user, status=Event.ON_CAL).\ |
69 except PageNotAnInteger: | 65 except PageNotAnInteger: |
70 page = paginator.page(1) | 66 page = paginator.page(1) |
71 except EmptyPage: | 67 except EmptyPage: |
72 page = paginator.page(paginator.num_pages) | 68 page = paginator.page(paginator.num_pages) |
73 | 69 |
74 return render_to_response('gcalendar/edit.html', { | 70 return render(request, 'gcalendar/edit.html', { |
75 'page': page, | 71 'page': page, |
76 }, | 72 }) |
77 context_instance = RequestContext(request)) | |
78 | 73 |
79 | 74 |
80 @login_required | 75 @login_required |
81 def edit_event(request, event_id): | 76 def edit_event(request, event_id): |
82 event = get_object_or_404(Event, pk=event_id) | 77 event = get_object_or_404(Event, pk=event_id) |
93 event.save() | 88 event.save() |
94 return HttpResponseRedirect(reverse('gcalendar-edit_thanks')) | 89 return HttpResponseRedirect(reverse('gcalendar-edit_thanks')) |
95 else: | 90 else: |
96 form = EventEntryForm(instance=event) | 91 form = EventEntryForm(instance=event) |
97 | 92 |
98 return render_to_response('gcalendar/event.html', { | 93 return render(request, 'gcalendar/event.html', { |
99 'title': 'Change Calendar Event', | 94 'title': 'Change Calendar Event', |
100 'form': form, | 95 'form': form, |
101 }, | 96 }) |
102 context_instance = RequestContext(request)) | |
103 | 97 |
104 | 98 |
105 @login_required | 99 @login_required |
106 def edit_thanks(request): | 100 def edit_thanks(request): |
107 return render_to_response('gcalendar/thanks_edit.html', { | 101 return render(request, 'gcalendar/thanks_edit.html', { |
108 }, | 102 }) |
109 context_instance = RequestContext(request)) | |
110 | 103 |
111 | 104 |
112 def delete_event(request): | 105 def delete_event(request): |
113 """This view marks an event for deletion. It is called via AJAX.""" | 106 """This view marks an event for deletion. It is called via AJAX.""" |
114 if request.user.is_authenticated(): | 107 if request.user.is_authenticated(): |
125 event.status = Event.DEL_REQ | 118 event.status = Event.DEL_REQ |
126 event.save() | 119 event.save() |
127 return HttpResponse(id) | 120 return HttpResponse(id) |
128 | 121 |
129 return HttpResponseForbidden() | 122 return HttpResponseForbidden() |
130 | |
131 | |
132 # vim: ts=4 sw=4 |