From 44754aabea4e4f59d1e8feb0894a020f146d00ef Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 19 Apr 2017 11:58:25 +0530 Subject: Allow redirection to desired page after logging in --- yaksh/views.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index db7498c..52cdc5f 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -68,14 +68,14 @@ def add_to_group(users): user.groups.add(group) -def index(request): +def index(request, next_url=None): """The start page. """ user = request.user if user.is_authenticated(): if user.groups.filter(name='moderator').count() > 0: - return my_redirect('/exam/manage/') - return my_redirect("/exam/quizzes/") + return my_redirect('/exam/manage/' if not next_url else next_url) + return my_redirect("/exam/quizzes/" if not next_url else next_url) return my_redirect("/exam/login/") @@ -324,27 +324,25 @@ def user_login(request): user = request.user ci = RequestContext(request) if user.is_authenticated(): - if user.groups.filter(name='moderator').count() > 0: - return my_redirect('/exam/manage/') - return my_redirect("/exam/quizzes/") + return index(request) + + next_url = request.GET.get('next') if request.method == "POST": form = UserLoginForm(request.POST) if form.is_valid(): user = form.cleaned_data login(request, user) - if user.groups.filter(name='moderator').count() > 0: - return my_redirect('/exam/manage/') - return my_redirect('/exam/login/') + return index(request, next_url) else: context = {"form": form} - return my_render_to_response('yaksh/login.html', context, - context_instance=ci) + else: form = UserLoginForm() context = {"form": form} - return my_render_to_response('yaksh/login.html', context, - context_instance=ci) + + return my_render_to_response('yaksh/login.html', context, + context_instance=ci) -- cgit From 290b71a311ad245b996f38bc7da4080a07493958 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 5 Apr 2017 18:50:00 +0530 Subject: Add course_code field allows access only to users with relevant course code string --- yaksh/views.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 94cb0c6..d298e5e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -122,14 +122,25 @@ def user_logout(request): def quizlist_user(request, enrolled=None): """Show All Quizzes that is available to logged-in user.""" user = request.user - if enrolled is not None: + ci = RequestContext(request) + + if request.method == "POST": + course_code = request.POST.get('course_code') + hidden_courses = Course.objects.get_hidden_courses(code=course_code) + courses = hidden_courses if hidden_courses else None + title = 'Search' + + elif enrolled is not None: courses = user.students.all() title = 'Enrolled Courses' else: - courses = Course.objects.filter(active=True, is_trial=False) + courses = Course.objects.filter(active=True, is_trial=False, hidden=False) title = 'All Courses' + context = {'user': user, 'courses': courses, 'title': title} - return my_render_to_response("yaksh/quizzes_user.html", context) + + return my_render_to_response("yaksh/quizzes_user.html", context, + context_instance=ci) @login_required @@ -639,8 +650,8 @@ def enroll_request(request, course_id): user = request.user ci = RequestContext(request) course = get_object_or_404(Course, pk=course_id) - if not course.is_active_enrollment: - msg = 'Enrollment for this course has been closed, please contact your '\ + if not course.is_active_enrollment and course.hidden: + msg = 'Unable to add enrollments for this course, please contact your '\ 'instructor/administrator.' return complete(request, msg, attempt_num=None, questionpaper_id=None) @@ -1238,7 +1249,7 @@ def search_teacher(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page!') - context = {} + context = {'success': False} course = get_object_or_404(Course, pk=course_id) context['course'] = course -- cgit