web/__init__.py
changeset 7990 a673d1d9a738
parent 6614 4b9a785df0f7
child 8190 2a3c1b787688
equal deleted inserted replaced
7989:db76e8aaec29 7990:a673d1d9a738
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    60         try:
    60         try:
    61             return json_dumps(value)
    61             return json_dumps(value)
    62         except TypeError:
    62         except TypeError:
    63             return json_dumps(repr(value))
    63             return json_dumps(repr(value))
    64     return newfunc
    64     return newfunc
    65 
       
    66 @deprecated('[3.4] use req.ajax_replace_url() instead')
       
    67 def ajax_replace_url(nodeid, rql, vid=None, swap=False, **extraparams):
       
    68     """builds a replacePageChunk-like url
       
    69     >>> ajax_replace_url('foo', 'Person P')
       
    70     "javascript: replacePageChunk('foo', 'Person%20P');"
       
    71     >>> ajax_replace_url('foo', 'Person P', 'oneline')
       
    72     "javascript: replacePageChunk('foo', 'Person%20P', 'oneline');"
       
    73     >>> ajax_replace_url('foo', 'Person P', 'oneline', name='bar', age=12)
       
    74     "javascript: replacePageChunk('foo', 'Person%20P', 'oneline', {'age':12, 'name':'bar'});"
       
    75     >>> ajax_replace_url('foo', 'Person P', name='bar', age=12)
       
    76     "javascript: replacePageChunk('foo', 'Person%20P', 'null', {'age':12, 'name':'bar'});"
       
    77     """
       
    78     params = [repr(nodeid), repr(urlquote(rql))]
       
    79     if extraparams and not vid:
       
    80         params.append("'null'")
       
    81     elif vid:
       
    82         params.append(repr(vid))
       
    83     if extraparams:
       
    84         params.append(json_dumps(extraparams))
       
    85     if swap:
       
    86         params.append('true')
       
    87     return "javascript: replacePageChunk(%s);" % ', '.join(params)