diff options
author | adityacp | 2020-01-02 15:35:07 +0530 |
---|---|---|
committer | adityacp | 2020-01-02 15:35:07 +0530 |
commit | 887cfb20d0ba158aa0e0838d6b40f334084d202e (patch) | |
tree | 3c74882521f3a3c358871e8eabd94b8e1f6ef304 /yaksh/views.py | |
parent | 29f93bce956af26e1b3ffe5ffc04e02c9f32de59 (diff) | |
download | online_test-887cfb20d0ba158aa0e0838d6b40f334084d202e.tar.gz online_test-887cfb20d0ba158aa0e0838d6b40f334084d202e.tar.bz2 online_test-887cfb20d0ba158aa0e0838d6b40f334084d202e.zip |
Change courses page with new UI
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index 78b30bf..7e9b706 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -15,6 +15,7 @@ from django.core.exceptions import ( MultipleObjectsReturned, ObjectDoesNotExist ) from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.contrib import messages from taggit.models import Tag import json import six @@ -1040,11 +1041,40 @@ def courses(request): if not is_moderator(user): raise Http404('You are not allowed to view this page') courses = Course.objects.filter( - creator=user, is_trial=False).order_by('-active', '-id') + creator=user, is_trial=False).order_by('-id') + paginator = Paginator(courses, 20) + 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) + context = {'objects': courses, 'created': True} + return my_render_to_response(request, 'yaksh/courses.html', context) + + +@login_required +@email_verified +def allotted_courses(request): + user = request.user + if not is_moderator(user): + raise Http404('You are not allowed to view this page') allotted_courses = Course.objects.filter( - teachers=user, is_trial=False).order_by('-active', '-id') - context = {'courses': courses, "allotted_courses": allotted_courses, - "type": "courses"} + teachers=user, is_trial=False).order_by('-id') + paginator = Paginator(allotted_courses, 20) + page = request.GET.get('page') + try: + allotted_courses = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + allotted_courses = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + allotted_courses = paginator.page(paginator.num_pages) + context = {'allotted': True, "objects": allotted_courses} return my_render_to_response(request, 'yaksh/courses.html', context) @@ -1166,9 +1196,12 @@ def toggle_course_status(request, course_id): if course.active: course.deactivate() + message = '{0} deactivated successfully'.format(course.name) else: course.activate() + message = '{0} activated successfully'.format(course.name) course.save() + messages.info(request, message) return my_redirect("/exam/manage/courses") |