]> git.parisson.com Git - django-social-auth.git/commitdiff
Small docs and code improves. Refs #384
authorMatías Aguirre <matiasaguirre@gmail.com>
Mon, 9 Jul 2012 05:48:03 +0000 (02:48 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Mon, 9 Jul 2012 05:48:03 +0000 (02:48 -0300)
README.rst
doc/configuration.rst
social_auth/context_processors.py

index 1dc328215a5c9a535f9450086de152b852d6026f..5759950bab51fe656a1d84657332bd2fa80c60d7 100644 (file)
@@ -234,6 +234,7 @@ Configuration
         'social_auth.context_processors.social_auth_by_name_backends',
         'social_auth.context_processors.social_auth_backends',
         'social_auth.context_processors.social_auth_by_type_backends',
+        'social_auth.context_processors.social_auth_login_redirect'
     )
 
   * ``social_auth_by_name_backends``:
@@ -253,6 +254,16 @@ Configuration
     Simiar to ``social_auth_backends`` but each value is grouped by backend
     type ``openid``, ``oauth2`` and ``oauth``.
 
+  * ``social_auth_login_redirect``:
+    For man in the middle redirects (ie authenticating via a login
+    required decorator), a convenince query string can be added to your context
+    for templates. On your login options page::
+
+        <a href={{% url socialauth_begin 'twitter' %}?{{ redirect_querystring }}">...</a>
+
+    allows for a continuous login. Useful if multiple login options are
+    presented.
+
   Check ``social_auth.context_processors`` for details.
 
   **Note**:
index 71347e247fb4637f5d886909852295c9949ecb5e..2aec520a86c38421cb465dd658f54cb018c9a9d2 100644 (file)
@@ -116,6 +116,7 @@ Configuration
         'social_auth.context_processors.social_auth_by_name_backends',
         'social_auth.context_processors.social_auth_backends',
         'social_auth.context_processors.social_auth_by_type_backends',
+        'social_auth.context_processors.social_auth_login_redirect',
     )
 
   * ``social_auth_by_name_backends``:
@@ -134,18 +135,22 @@ Configuration
     Simiar to ``social_auth_backends`` but each value is grouped by backend type
     ``openid``, ``oauth2`` and ``oauth``.
 
+  * ``social_auth_login_redirect``:
+    For man in the middle redirects (ie authenticating via a login
+    required decorator), a convenince query string can be added to your context
+    for templates. On your login options page::
+
+        <a href={{% url socialauth_begin 'twitter' %}?{{ redirect_querystring }}">...</a>
+
+    allows for a continuous login. Useful if multiple login options are
+    presented.
+
   Check ``social_auth.context_processors`` for details.
 
   **Note**:
   ``social_auth_backends`` and ``social_auth_by_type_backends`` don't play nice
   together.
 
-  **Also:** For man in the middle redirects (ie authenticating via a login required decorator), a convenince query string can be added to your context for templates.  On your login options page: ``<a href={{% url socialauth_begin 'twitter' %}?{{ redirect_querystring }}">`` allows for a continuous login.  Useful if multiple login options are presented.  
-
-       To enable, add the following Context Processor::
-               
-               'social_auth.context_processors.social_auth_login_redirect',
-
 - Sync database to create needed models::
 
     ./manage.py syncdb
index 6a444239b51754dc9fd0e48e862344f9cfc77e88..f22ae96e5ea53f289fc15d672fb05d8e0cfa876c 100644 (file)
@@ -2,12 +2,13 @@ from social_auth.models import UserSocialAuth
 from social_auth.backends import get_backends
 from social_auth.utils import group_backend_by_type
 
-from django.contrib.auth import REDIRECT_FIELD_NAME as auth_redirect
+from django.contrib.auth import REDIRECT_FIELD_NAME
 from django.conf import settings
 
 # Note: social_auth_backends, social_auth_by_type_backends and
 #       social_auth_by_name_backends don't play nice together.
 
+
 def social_auth_backends(request):
     """Load Social Auth current user data to context.
     Will add a output from backends_data to context under social_auth key.
@@ -73,17 +74,18 @@ def backends_data(user):
         values['associated'] = associated
         values['not_associated'] = not_associated
     return values
+
+
 def social_auth_login_redirect(request):
-    """Load current redirect to context
-    Provides access to the redirect variable as named in the settings file
-    Assumes that the redirect field name is set in the settings file
-               """
-    redirect_name = getattr(settings, 'REDIRECT_FIELD_NAME', auth_redirect)
-    redirect_value = request.REQUEST.get(redirect_name, '')
-    context = {
-        'REDIRECT_FIELD_NAME' : redirect_name, 
-        'REDIRECT_FIELD_VALUE' : redirect_value,
-        'redirect_querystring' : redirect_name + '=' + redirect_value
+    """Load current redirect to context."""
+    redirect_value = request.REQUEST.get(REDIRECT_FIELD_NAME)
+    if redirect_value:
+        redirect_querystring = REDIRECT_FIELD_NAME + '=' + redirect_value
+    else:
+        redirect_querystring = ''
+
+    return {
+        'REDIRECT_FIELD_NAME': REDIRECT_FIELD_NAME,
+        'REDIRECT_FIELD_VALUE': redirect_value,
+        'redirect_querystring': redirect_querystring
     }
-    return context