1. Ben Bangert
  2. WebHelpers
  3. Issues
Issue #62 new

update_params() should accept a dict of query params

Mike Orr
created an issue

Often it's useful to generate a URL based on a path, a dict of existing query params, and new query params. update_params() does not facilitate this: it expects a URL with a query string and keyword params. This requires the caller to take multiple steps if he has a path, a dict, and new params. Change the function to:

{{{

!python

update_params(url, params=None, debug=False, **kwparams) }}}

(Note that the meaning of the 'params' argument changes!)

'params' may be a (WebOb) MultiDict, and the values in 'kwparams may also be mutliple (i.e., lists). To preserve these, if 'params' is specified, make a copy of it, setdefault any parameters specified in the URL (to set them only if they don't exist in 'params'), and then set any params specified in kwparams. If a value exists in kwparams, it should completely replace the value in params, and multiple new values should all be added. If any kwparam has a None value, delete the key in params if it exists.

Alternatively, if params is specified and the URL also has params, ignore the URL's params. It's not likely that both would be specified, and the dict should be more definitive.

If params is not specified, it would be fine to keep the existing implementation rather than rewrite it.

Comments (0)

  1. Log in to comment