Commit f098d723 authored by Georgios Dagkakis's avatar Georgios Dagkakis

erp5_core: add script Base_constructUrlFor. As an API to be able to construct urls

for a base document, given the form_id, document_reference and GET parameters

(provisional version, for testing)
parent 956a4b5e
'''
- context: should the document that we need as base for the url.
In case it is not given, the context will be used
- form_id: the form that is invoked
- document_reference: the reference of a document that is rendered,
- parameter_dict: dictionary containing all get parameters
'''
if context.getPortalType() in ('Web Section', 'Web Site'):
url = context.absolute_url()[:-1]
else:
url = context.absolute_url()
assert not (form_id and document_reference), 'Not allowed to have both form and document in the same url'
if form_id:
url = '%s/%s' % (url, form_id)
if document_reference:
url = '%s/%s' % (url, document_reference)
if parameter_dict:
url = '%s?%s' % (
url,
'&'.join(['%s=%s' % (key, value) for (key, value) in parameter_dict.iteritems()])
)
return url
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>form_id=None, document_reference=None, parameter_dict=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_constructUrlFor</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment