comparison gcalendar/views.py @ 817:74e84f5fc948

For issue #72, paginate calendar events.
author Brian Neal <bgneal@gmail.com>
date Wed, 10 Sep 2014 19:38:55 -0500
parents 9e803323a0d0
children 68c3343f3318
comparison
equal deleted inserted replaced
816:97f8fab9b1a3 817:74e84f5fc948
2 Views for the gcalendar application. 2 Views for the gcalendar application.
3 """ 3 """
4 4
5 from django.contrib.auth.decorators import login_required 5 from django.contrib.auth.decorators import login_required
6 from django.core.urlresolvers import reverse 6 from django.core.urlresolvers import reverse
7 from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
7 from django.http import HttpResponse 8 from django.http import HttpResponse
8 from django.http import HttpResponseBadRequest 9 from django.http import HttpResponseBadRequest
9 from django.http import HttpResponseForbidden 10 from django.http import HttpResponseForbidden
10 from django.http import HttpResponseRedirect 11 from django.http import HttpResponseRedirect
11 from django.http import Http404 12 from django.http import Http404
57 context_instance = RequestContext(request)) 58 context_instance = RequestContext(request))
58 59
59 60
60 @login_required 61 @login_required
61 def edit_events(request): 62 def edit_events(request):
62 events = Event.objects.filter(user=request.user, status=Event.ON_CAL).order_by('start_date') 63 events = Event.objects.filter(user=request.user, status=Event.ON_CAL).\
64 order_by('-start_date')
65 paginator = Paginator(events, 25)
66 num = request.GET.get('page')
67 try:
68 page = paginator.page(num)
69 except PageNotAnInteger:
70 page = paginator.page(1)
71 except EmptyPage:
72 page = paginator.page(paginator.num_pages)
73
63 return render_to_response('gcalendar/edit.html', { 74 return render_to_response('gcalendar/edit.html', {
64 'events': events, 75 'page': page,
65 }, 76 },
66 context_instance = RequestContext(request)) 77 context_instance = RequestContext(request))
67 78
68 79
69 @login_required 80 @login_required