Commits

hideki nara  committed f55175f

Lastest styleof tamplate tag for 'url'

  • Participants
  • Parent commits 1d7bc86

Comments (0)

Files changed (1)

File bpmobile/templatetags/mobile.py

     else:
         raise template.TemplateSyntaxError("'mobile_fontsize' tag require one arguments")
 
-# Overrinding  django.tempate.defaulttags.url to embed the session key in urls.
-#
-# TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
-#    'django.core.context_processors.request', 
-# )
+from bpmobile.utils import  reverse,session_embedded_url
 
-from django.template.defaulttags import url as default_url
-import re
-from bpmobile.utils import  session_embedded_url
-
-class URLNodeMobile(template.Node):
-    def __init__(self,urlnode,session ):
-        self.urlnode = urlnode
-        self.session = session
-    def render(self,context):
-        ret = self.urlnode.render(context)
-        if context.has_key('request'):
-            request = context['request']  
-            ret =  session_embedded_url( request,ret,self.session )
-
-        return ret 
-
-@register.tag
-def 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 )
+@register.simple_tag(takes_context=True)
+def url(context,name,*args,**kwargs):
+    '''  require 'django.core.context_processors.request' in 
+         settings.TEMPLATE_CONTEXT_PROCESSORS
+    '''
+    request = context.get('request',None) 
+    url_to_go= reverse(name,args =args,kwargs=kwargs,request=request)
+    return url_to_go