--- a/src/pyams_utils/url.py Mon Sep 11 12:25:41 2017 +0200
+++ b/src/pyams_utils/url.py Mon Sep 11 12:28:09 2017 +0200
@@ -21,16 +21,18 @@
# import packages
from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
-from pyramid.url import resource_url
+from pyramid.encode import url_quote, urlencode
+from pyramid.url import resource_url, QUERY_SAFE
from zope.interface import Interface
-def absolute_url(context, request, view_name=None):
+def absolute_url(context, request, view_name=None, query=None):
"""Get resource absolute_url
:param object context: the persistent object for which absolute URL is required
:param request: the request on which URL is based
:param str view_name: an optional view name to add to URL
+ :param str/dict query: an optional URL arguments string or mapping
This absolute URL function is based on default Pyramid's :py:func:`resource_url` function, but
add checks to remove some double slashes, and add control on view name when it begins with a '#'
@@ -46,6 +48,13 @@
result += view_name
else:
result += '/' + view_name
+ if query:
+ qs = ''
+ if isinstance(query, str):
+ qs = '?' + url_quote(query, QUERY_SAFE)
+ elif query:
+ qs = '?' + urlencode(query, doseq=True)
+ result += qs
return result