Skip to content
Browse files

Pagination added

  • Loading branch information...
1 parent ec424aa commit 76ac4205bb97639d0b533c639effe72351820bb5 @alfredo alfredo committed Mar 2, 2012
View
10 apps/challenges/views.py
@@ -18,7 +18,7 @@
import jingo
from tower import ugettext as _
from voting.models import Vote
-
+from commons.helpers import get_page
from challenges.forms import (EntryForm, EntryLinkForm, InlineLinkFormSet,
JudgingForm)
from challenges.models import (Challenge, Phase, Submission, Category,
@@ -65,17 +65,11 @@ def show(request, project, slug, template_name='challenges/show.html', category=
if category:
entry_set = entry_set.filter(category__name=category)
paginator = Paginator(entry_set, 25)
-
- try:
- page = int(request.GET.get('page', '1'))
- except (ValueError, TypeError):
- page = 1
-
+ page = get_page(request.GET)
try:
entries = paginator.page(page)
except (EmptyPage, InvalidPage):
entries = paginator.page(paginator.num_pages)
-
return jingo.render(request, template_name, {
'challenge': challenge,
'project': project,
View
9 apps/commons/helpers.py
@@ -66,3 +66,12 @@ def _urlencode(items):
def urlencode(txt):
"""Url encode a path."""
return urllib.quote_plus(txt)
+
+
+def get_page(data):
+ """Determines the page number"""
+ try:
+ page = int(data.get('page', '1'))
+ except (ValueError, TypeError):
+ page = 1
+ return page
View
14 apps/webcast/views.py
@@ -2,11 +2,13 @@
from datetime import datetime
+from django.conf import settings
+from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.contrib.auth.decorators import login_required
from django.http import Http404
+from commons.helpers import get_page
from timeslot.models import TimeSlot
-
@login_required
def upcoming(request, template='webcast/upcoming.html'):
"""Lists the upcoming webcasts for this user"""
@@ -30,10 +32,16 @@ def webcast_list(request, slug='all', template=None):
if not slug in filters:
raise Http404
queryset = filters[slug]
- upcoming_list = TimeSlot.objects.select_related('submission').\
+ upcoming_qs = TimeSlot.objects.select_related('submission').\
filter(is_booked=True, **queryset)
+ paginator = Paginator(upcoming_qs, settings.PAGINATOR_SIZE)
+ page_number = get_page(request.GET)
+ try:
+ page = paginator.page(page_number)
+ except (EmptyPage, InvalidPage):
+ page = paginator.page(paginator.num_pages)
context = {
- 'object_list': upcoming_list,
+ 'page': page,
}
if not template:
template = 'webcast/webcast_%s.html' % slug
View
3 settings.py
@@ -363,3 +363,6 @@ def JINJA_CONFIG():
BOOKING_THROTTLING_USERS = 30
# Time difference between slot releases
BOOKING_THROTTLING_TIMEDELTA = 60 * 60 * 2 # 2 Hours
+
+# Paginator
+PAGINATOR_SIZE = 25
View
25 templates_ignite/challenges/all.html
@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% from "challenges/helpers.html" import created_by with context %}
+{% from "layout/pagination.html" import footer_pagination with context %}
{% block page_title %}{% if category %}{{ _('All submissions in {cat}')|f(cat = category) }} | {% else %}{{ _('All submissions') }} | {% endif %}{% endblock %}
@@ -56,29 +57,7 @@ <h2 class="box_title">Submissions</h2>
</li>
{% endfor %}
</ol>
- {% if entries.paginator.num_pages > 1 %}
- <footer class="pagination">
- <nav>
- {% if entries.has_previous() %}
- <a href="?page={{ entries.previous_page_number() }}" class="btn">prev</a>
- {% endif %}
- <ol>
- {% for i in range(entries.paginator.num_pages) %}
- <li>
- {% if i + 1 == entries.number %}
- <span>{{ i + 1 }}</span>
- {% else %}
- <a href="?page={{ i + 1 }}">{{ i + 1 }}</a>
- {% endif %}
- </li>
- {% endfor %}
- </ol>
- {% if entries.has_next() %}
- <a href="?page={{ entries.next_page_number() }}" class="btn">next</a>
- {% endif %}
- </nav>
- </footer>
- {% endif %}
+ {{ footer_pagination(entries) }}
</div>
</div>
</section>
View
13 templates_ignite/webcast/object_list.html
@@ -0,0 +1,13 @@
+{% extends "base.html" %}
+{% from "layout/pagination.html" import footer_pagination with context %}
+{% block content %}
+
+{% block listing_title %}{% endblock listing_title %}
+
+{% for object in page.object_list %}
+{% include "webcast/include/submission_detail.html" %}
+{% endfor%}
+
+{{ footer_pagination(page) }}
+
+{% endblock content%}
View
9 templates_ignite/webcast/webcast_all.html
@@ -1,7 +1,2 @@
-{% extends "base.html" %}
-{% block content %}
-<h1>Webcast list</h1>
-{% for object in object_list %}
-{% include "webcast/include/submission_detail.html" %}
-{% endfor%}
-{% endblock content%}
+{% extends "webcast/object_list.html" %}
+{% block listing_title %}<h1>Webcast list</h1>{% endblock listing_title %}
View
9 templates_ignite/webcast/webcast_upcoming.html
@@ -1,7 +1,2 @@
-{% extends "base.html" %}
-{% block content %}
-<h1>Upcoming webcasts</h1>
-{% for object in object_list %}
-{% include "webcast/include/submission_detail.html" %}
-{% endfor%}
-{% endblock content%}
+{% extends "webcast/object_list.html" %}
+{% block listing_title %}<h1>Upcoming webcasts</h1>{% endblock listing_title %}

0 comments on commit 76ac420

Please sign in to comment.
Something went wrong with that request. Please try again.