summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authoradityacp2019-12-20 12:23:03 +0530
committeradityacp2019-12-20 12:23:03 +0530
commit2e4c36969b18b9ebf09314d7a04094a7debe4387 (patch)
treeeb96983127f7535442eca89659692f771031531b /yaksh/views.py
parent93eb0c0d3346dc7de466263a66ead29660f2518f (diff)
downloadonline_test-2e4c36969b18b9ebf09314d7a04094a7debe4387.tar.gz
online_test-2e4c36969b18b9ebf09314d7a04094a7debe4387.tar.bz2
online_test-2e4c36969b18b9ebf09314d7a04094a7debe4387.zip
Change forms.py and views.py
- Add pagination for the courses in the moderator dashboard - Add bootstrap class for input type in forms.py
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 0bf91eb..78b30bf 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -14,6 +14,7 @@ from django.utils import timezone
from django.core.exceptions import (
MultipleObjectsReturned, ObjectDoesNotExist
)
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from taggit.models import Tag
import json
import six
@@ -395,8 +396,19 @@ def prof_manage(request, msg=None):
return my_redirect('/exam/login')
if not is_moderator(user):
return my_redirect('/exam/')
- courses = Course.objects.filter(Q(creator=user) | Q(teachers=user),
- is_trial=False).distinct()
+ courses = Course.objects.get_queryset().filter(
+ Q(creator=user) | Q(teachers=user),
+ is_trial=False).distinct().order_by("-id")
+ paginator = Paginator(courses, 10)
+ page = request.GET.get('page')
+ try:
+ courses = paginator.page(page)
+ except PageNotAnInteger:
+ # If page is not an integer, deliver first page.
+ courses = paginator.page(1)
+ except EmptyPage:
+ # If page is out of range (e.g. 9999), deliver last page of results.
+ courses = paginator.page(paginator.num_pages)
trial_paper = AnswerPaper.objects.filter(
user=user, question_paper__quiz__is_trial=True,
course__is_trial=True
@@ -416,7 +428,7 @@ def prof_manage(request, msg=None):
else:
answerpaper.delete()
- context = {'user': user, 'courses': courses,
+ context = {'user': user, 'objects': courses,
'trial_paper': trial_paper, 'msg': msg
}
return my_render_to_response(