app/soc/views/helper/requests.py
changeset 512 aae25d2b4464
parent 365 74dec172944e
child 1307 091a21cf3627
equal deleted inserted replaced
511:52557918ec8f 512:aae25d2b4464
    99       expected_path is not supplied (the most common usage)
    99       expected_path is not supplied (the most common usage)
   100     expected_prefix: optional HTTP path to use instead of the one in
   100     expected_prefix: optional HTTP path to use instead of the one in
   101       request.path; default is None (use request.path)
   101       request.path; default is None (use request.path)
   102     suffix: suffix to remove from the HTTP request path before comparing
   102     suffix: suffix to remove from the HTTP request path before comparing
   103       it to the HTTP referrer path in the HTTP request object headers
   103       it to the HTTP referrer path in the HTTP request object headers
   104       (this is often an link name, for example, that may be changing from
   104       (this is often an link ID, for example, that may be changing from
   105       a POST referrer to a GET redirect target) 
   105       a POST referrer to a GET redirect target) 
   106   
   106   
   107   Returns:
   107   Returns:
   108     True if HTTP referrer path begins with the HTTP request path (either
   108     True if HTTP referrer path begins with the HTTP request path (either
   109       request.path or expected_prefix instead if it was supplied), after
   109       request.path or expected_prefix instead if it was supplied), after
   122   if not expected_prefix:
   122   if not expected_prefix:
   123     # use HTTP request path, since expected_prefix was not supplied
   123     # use HTTP request path, since expected_prefix was not supplied
   124     expected_prefix = request.path
   124     expected_prefix = request.path
   125 
   125 
   126   if suffix:
   126   if suffix:
   127     # remove suffix (such as a link name) before comparison
   127     # remove suffix (such as a link ID) before comparison
   128     chars_to_remove = len(suffix)
   128     chars_to_remove = len(suffix)
   129     
   129     
   130     if not suffix.startswith('/'):
   130     if not suffix.startswith('/'):
   131       chars_to_remove = chars_to_remove + 1
   131       chars_to_remove = chars_to_remove + 1
   132 
   132 
   142 
   142 
   143 def replaceSuffix(path, old_suffix, new_suffix=None, params=None):
   143 def replaceSuffix(path, old_suffix, new_suffix=None, params=None):
   144   """Replace the last part of a URL path with something else.
   144   """Replace the last part of a URL path with something else.
   145 
   145 
   146   Also appends an optional list of query parameters.  Used for
   146   Also appends an optional list of query parameters.  Used for
   147   replacing, for example, one link name at the end of a relative
   147   replacing, for example, one link ID at the end of a relative
   148   URL path with another.
   148   URL path with another.
   149 
   149 
   150   Args:
   150   Args:
   151     path: HTTP request relative URL path (with no query arguments)
   151     path: HTTP request relative URL path (with no query arguments)
   152     old_suffix: expected suffix at the end of request.path component;
   152     old_suffix: expected suffix at the end of request.path component;