summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-04-27 17:29:54 +0530
committerGitHub2017-04-27 17:29:54 +0530
commit9991300f25ad9d83e0724342c38c7e0f20cee895 (patch)
tree88cce6d7101ba423f1d06fcd3b06f9e17bab72ee /yaksh
parenta67f8597da19527669b596fab08083a18c7e1fcc (diff)
parent44754aabea4e4f59d1e8feb0894a020f146d00ef (diff)
downloadonline_test-9991300f25ad9d83e0724342c38c7e0f20cee895.tar.gz
online_test-9991300f25ad9d83e0724342c38c7e0f20cee895.tar.bz2
online_test-9991300f25ad9d83e0724342c38c7e0f20cee895.zip
Merge pull request #276 from ankitjavalkar/fix-login-redirect2
Allow redirection to desired page after logging in
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/views.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 44f06b1..94cb0c6 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -73,14 +73,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/")
@@ -331,27 +331,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)