Redirect the login to home page if the login is made from logout page.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Tue, 18 Jan 2011 14:33:54 +0530
changeset 455 7b006fb467c2
parent 454 8d88ec95a828
child 456 da6f5be33087
Redirect the login to home page if the login is made from logout page.
pytask/profile/views.py
--- a/pytask/profile/views.py	Tue Jan 18 01:47:55 2011 +0530
+++ b/pytask/profile/views.py	Tue Jan 18 14:33:54 2011 +0530
@@ -1,3 +1,5 @@
+from urllib2 import urlparse
+
 from django import http
 from django import shortcuts
 from django.contrib.auth.decorators import login_required
@@ -195,15 +197,25 @@
 
 @login_required
 def login_proceed(request):
-  """View that handles the successful login.
-  """
+    """View that handles the successful login.
+    """
+
+    template_name = '_user_login.html'
 
-  template_name = '_user_login.html'
-  response = {
-    'authentication': 'success',
-    'markup': loader.render_to_string(template_name,
-                                      RequestContext(request, {}))
-  }
+    # Check if the request came from logout page, if so set
+    # authentication to redirect to home page
+    if reverse('auth_logout') == urlparse.urlsplit(
+      request.META['HTTP_REFERER'])[2]:
+      response = {
+        'authentication': 'success',
+        'redirect': reverse('home_page'),
+        }
+    else:
+        response = {
+          'authentication': 'success',
+          'markup': loader.render_to_string(template_name,
+                                            RequestContext(request, {}))
+        }
 
-  json_response = json.dumps(response)
-  return http.HttpResponse(json_response)
+    json_response = json.dumps(response)
+    return http.HttpResponse(json_response)