hideki nara avatar hideki nara committed e6e4a63

depending on cases, have to force to embed session or not for SSO

Comments (0)

Files changed (2)

bpmobile/templatetags/mobile.py

 # )
 
 from django.template.defaulttags import url as default_url
-from django.core.urlresolvers import get_script_prefix
+import re
 
 class URLNodeMobile(template.Node):
-    def __init__(self,urlnode ):
+    def __init__(self,urlnode,session ):
         self.urlnode = urlnode
+        self.session = session
     def render(self,context):
         ret = self.urlnode.render(context)
-        if context.has_key('agent') and context['agent'].is_docomo():
-            if context.has_key('request'):
-                request = context['request']  
-#                ret= "/(%s)%s" % ( request.session.session_key , ret)
+
+        if context.has_key('request'):
+            request = context['request']  
+            if self.session == 'embed' or ( 
+               self.session != 'none'       
+               and context.has_key('agent') and context['agent'].is_docomo()):  # auto
                 ret = ret+ ";(%s)"% request.session.session_key 
+
         return ret 
 
 @register.tag
 def url(parser,token):
-    return  URLNodeMobile( default_url(parser,token) )
+    ''' _session="auto|embed|none" '''
+    rstr=r'(_session=)(\S+)'
+    m= re.search(rstr,token.contents )
+    if m:
+        session = m.group(2).replace('"','')
+        token.contents = re.sub(rstr,'',token.contents ) 
+    else: 
+        session = 'auto'   #defult=auto
+    
+    return  URLNodeMobile( default_url(parser,token),session )

bpmobile/utils.py

 #: Overides django.core.urlresolvers.reverse  to embed the session key in urls
 from django.core.urlresolvers import reverse as default_reverse
 
-def reverse(viewname, request=None,urlconf=None, args=None, kwargs=None, prefix=None, current_app=None):
+def reverse(viewname, request=None,urlconf=None, args=None, kwargs=None, prefix=None, current_app=None,
+            session="auto"):
     url = default_reverse(viewname, urlconf,args,kwargs,prefix,current_app )
-    if request == None or not hasattr(request,'agent') or not request.agent.is_docomo():
-        return url
+    if session == 'embed'  or ( 
+       session != 'none' and 
+       request != None and hasattr(request,'agent') and request.agent.is_docomo()):
+        return url + ";(%s)"%  request.session.session_key 
 
-    return url + ";(%s)"%  request.session.session_key 
+    return url
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.