Mercurial > public > sg101
changeset 817:74e84f5fc948
For issue #72, paginate calendar events.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 10 Sep 2014 19:38:55 -0500 |
parents | 97f8fab9b1a3 |
children | cf486a8e8b43 |
files | gcalendar/views.py sg101/templates/gcalendar/edit.html |
diffstat | 2 files changed, 16 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/gcalendar/views.py Wed Sep 10 19:21:59 2014 -0500 +++ b/gcalendar/views.py Wed Sep 10 19:38:55 2014 -0500 @@ -4,6 +4,7 @@ from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse +from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage from django.http import HttpResponse from django.http import HttpResponseBadRequest from django.http import HttpResponseForbidden @@ -59,9 +60,19 @@ @login_required def edit_events(request): - events = Event.objects.filter(user=request.user, status=Event.ON_CAL).order_by('start_date') + events = Event.objects.filter(user=request.user, status=Event.ON_CAL).\ + order_by('-start_date') + paginator = Paginator(events, 25) + num = request.GET.get('page') + try: + page = paginator.page(num) + except PageNotAnInteger: + page = paginator.page(1) + except EmptyPage: + page = paginator.page(paginator.num_pages) + return render_to_response('gcalendar/edit.html', { - 'events': events, + 'page': page, }, context_instance = RequestContext(request))
--- a/sg101/templates/gcalendar/edit.html Wed Sep 10 19:21:59 2014 -0500 +++ b/sg101/templates/gcalendar/edit.html Wed Sep 10 19:38:55 2014 -0500 @@ -6,7 +6,7 @@ {% block content %} <div class="breadcrumbs"><a href="{% url 'gcalendar-index' %}">Calendar</a> » Edit Events</div> <h2>Edit Calendar Events</h2> -{% if events %} +{% if page.object_list %} <p>You have the following events on our calendar. Click on the event title to edit it, or click the <img src="{{ STATIC_URL }}icons/cross.png" alt="Cross" /> to delete it. Your changes will be submitted to the site staff for approval, and won't be reflected on the Google @@ -14,13 +14,14 @@ keep our calendar up to date! </p> <ul> -{% for event in events %} +{% for event in page.object_list %} <li>{{ event.start_date|date:"M d, Y"}} • <a href="{% url 'gcalendar-edit_event' event.id %}" title="Edit Event">{{ event.what }}</a> <a class="gcal-del" id="gcal-{{ event.id }}" href="#"><img src="{{ STATIC_URL }}icons/cross.png" alt="Delete Event" title="Delete Event" /></a> </li> {% endfor %} </ul> +{% include 'core/django_pagination.html' with page_obj=page %} {% else %} <p>You either have no events on our calendar, or all your events have pending changes that require admin review.</p>