Commit 91388004cb353aa637f6478adc8eb8b845721046
1 parent
90cb0003
Exists in
master
and in
5 other branches
Adding pagination on guest template/view [Issue #190]
Showing
3 changed files
with
19 additions
and
8 deletions
Show diff stats
core/templates/guest.html
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | 3 | ||
4 | {% load i18n custom_filters %} | 4 | {% load i18n custom_filters %} |
5 | {% load static i18n %} | 5 | {% load static i18n %} |
6 | +{% load pagination %} | ||
6 | 7 | ||
7 | <html> | 8 | <html> |
8 | <head> | 9 | <head> |
@@ -159,6 +160,7 @@ | @@ -159,6 +160,7 @@ | ||
159 | </div> | 160 | </div> |
160 | {% endfor %} | 161 | {% endfor %} |
161 | 162 | ||
163 | + {% pagination request paginator page_obj %} | ||
162 | {% endblock %} | 164 | {% endblock %} |
163 | </div> | 165 | </div> |
164 | </div> | 166 | </div> |
core/urls.py
@@ -11,7 +11,7 @@ urlpatterns = [ | @@ -11,7 +11,7 @@ urlpatterns = [ | ||
11 | url(r'^logout/$', auth_views.logout, {'next_page': 'core:home'}, name='logout'), | 11 | url(r'^logout/$', auth_views.logout, {'next_page': 'core:home'}, name='logout'), |
12 | url(r'^notification/([0-9]+)/$', views.processNotification, name='notification_read'), | 12 | url(r'^notification/([0-9]+)/$', views.processNotification, name='notification_read'), |
13 | url(r'^getNotifications/$', views.getNotifications, name='getNotifications'), | 13 | url(r'^getNotifications/$', views.getNotifications, name='getNotifications'), |
14 | - url(r'^guest/$', views.guest, name='guest'), | 14 | + url(r'^guest/$', views.GuestView.as_view(), name='guest'), |
15 | 15 | ||
16 | #Reset Password | 16 | #Reset Password |
17 | 17 |
core/views.py
@@ -6,7 +6,7 @@ from .decorators import log_decorator | @@ -6,7 +6,7 @@ from .decorators import log_decorator | ||
6 | from django.contrib import messages | 6 | from django.contrib import messages |
7 | from django.shortcuts import render, redirect | 7 | from django.shortcuts import render, redirect |
8 | from django.template.loader import render_to_string | 8 | from django.template.loader import render_to_string |
9 | -from django.views.generic import CreateView, UpdateView | 9 | +from django.views.generic import CreateView, UpdateView, ListView |
10 | from django.http import HttpResponse, JsonResponse | 10 | from django.http import HttpResponse, JsonResponse |
11 | from django.core.mail import send_mail,BadHeaderError | 11 | from django.core.mail import send_mail,BadHeaderError |
12 | from django.conf import settings | 12 | from django.conf import settings |
@@ -120,9 +120,18 @@ def getNotifications(request): | @@ -120,9 +120,18 @@ def getNotifications(request): | ||
120 | data['amountGotten'] = amountGotten | 120 | data['amountGotten'] = amountGotten |
121 | return JsonResponse(data) | 121 | return JsonResponse(data) |
122 | 122 | ||
123 | -def guest (request): | ||
124 | - context = { | ||
125 | - 'courses': Course.objects.filter(public=True), | ||
126 | - 'categories': CourseCategory.objects.all(), | ||
127 | - } | ||
128 | - return render(request, 'guest.html', context) | ||
129 | \ No newline at end of file | 123 | \ No newline at end of file |
124 | + | ||
125 | +class GuestView (ListView): | ||
126 | + | ||
127 | + template_name = 'guest.html' | ||
128 | + context_object_name = 'courses' | ||
129 | + paginate_by = 10 | ||
130 | + | ||
131 | + def get_queryset(self): | ||
132 | + return Course.objects.filter(public=True) | ||
133 | + | ||
134 | + | ||
135 | + def get_context_data (self, **kwargs): | ||
136 | + context = super(GuestView, self).get_context_data(**kwargs) | ||
137 | + context['categories'] = CourseCategory.objects.all() | ||
138 | + return context |