diff options
author | ankitjavalkar | 2017-04-19 11:58:25 +0530 |
---|---|---|
committer | ankitjavalkar | 2017-04-19 11:58:25 +0530 |
commit | 44754aabea4e4f59d1e8feb0894a020f146d00ef (patch) | |
tree | 5278ead0d53d876290a20d11e7f2362cc0239578 /yaksh/views.py | |
parent | ad73f7b938b7620ab4be202dc33c699cf5cb4ac5 (diff) | |
download | online_test-44754aabea4e4f59d1e8feb0894a020f146d00ef.tar.gz online_test-44754aabea4e4f59d1e8feb0894a020f146d00ef.tar.bz2 online_test-44754aabea4e4f59d1e8feb0894a020f146d00ef.zip |
Allow redirection to desired page after logging in
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 24 |
1 files changed, 11 insertions, 13 deletions
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) |