web/views/urlrewrite.py
changeset 3890 d7a270f50f54
parent 3629 559cad62c786
parent 3865 f9778a00e47f
child 4045 f4a52abb6f4f
equal deleted inserted replaced
3810:5b75fd66c80e 3890:d7a270f50f54
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
     8 import re
     8 import re
     9 
     9 
       
    10 from cubicweb import typed_eid
    10 from cubicweb.appobject import AppObject
    11 from cubicweb.appobject import AppObject
    11 
    12 
    12 
    13 
    13 def rgx(pattern, flags=0):
    14 def rgx(pattern, flags=0):
    14     """this is just a convenient shortcout to add the $ sign"""
    15     """this is just a convenient shortcout to add the $ sign"""
   146         return None, None
   147         return None, None
   147     return do_build_rset
   148     return do_build_rset
   148 
   149 
   149 def rgx_action(rql=None, args=None, cachekey=None, argsgroups=(), setuser=False,
   150 def rgx_action(rql=None, args=None, cachekey=None, argsgroups=(), setuser=False,
   150                form=None, formgroups=(), transforms={}, controller=None):
   151                form=None, formgroups=(), transforms={}, controller=None):
   151     def do_build_rset(inputurl, uri, req, schema):
   152     def do_build_rset(inputurl, uri, req, schema,
       
   153                       cachekey=cachekey # necessary to avoid UnboundLocalError
       
   154                       ):
   152         if rql:
   155         if rql:
   153             kwargs = args and args.copy() or {}
   156             kwargs = args and args.copy() or {}
   154             if argsgroups:
   157             if argsgroups:
       
   158                 if cachekey is not None and isinstance(cachekey, basestring):
       
   159                     cachekey = (cachekey,)
   155                 match = inputurl.match(uri)
   160                 match = inputurl.match(uri)
   156                 for key in argsgroups:
   161                 for key in argsgroups:
   157                     value = match.group(key)
   162                     value = match.group(key)
   158                     try:
   163                     try:
   159                         kwargs[key] = transforms[key](value)
   164                         kwargs[key] = transforms[key](value)
   160                     except KeyError:
   165                     except KeyError:
   161                         kwargs[key] = value
   166                         kwargs[key] = value
       
   167                     if cachekey is not None and key in cachekey:
       
   168                         kwargs[key] = typed_eid(value)
   162             if setuser:
   169             if setuser:
   163                 kwargs['u'] = req.user.eid
   170                 kwargs['u'] = req.user.eid
   164             rset = req.execute(rql, kwargs, cachekey)
   171             rset = req.execute(rql, kwargs, cachekey)
   165         else:
   172         else:
   166             rset = None
   173             rset = None