Commit e9792acc authored by Jean-Paul Smets's avatar Jean-Paul Smets

2006-01-03 JPS - Early refactoring of ERP5 Web

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11890 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4d48744c
...@@ -90,6 +90,10 @@ ...@@ -90,6 +90,10 @@
for the first relevant section and build a URL\n for the first relevant section and build a URL\n
based on the section absolute_url and on the\n based on the section absolute_url and on the\n
document reference.\n document reference.\n
\n
The section parameter can be used to provide\n
explicitely a section. This can be useful to\n
build URL generators for listbox entries.\n
\n \n
More sophisticated behaviours are possible.\n More sophisticated behaviours are possible.\n
\n \n
...@@ -101,11 +105,18 @@ ...@@ -101,11 +105,18 @@
- change the behaviour of WebSite_getDocumentUrl\n - change the behaviour of WebSite_getDocumentUrl\n
for documents which are not published.\n for documents which are not published.\n
\n \n
NOTE: it is still unknown whether this script\n NOTE: absolute_url is the appropriate API to get\n
needs to be integrated or not to the absolute_url API\n the absolute_url of the current document. It has\n
been tweaked enough in ERP5 Web to support virtual\n
hosting and permanent URLs.\n
\n
Base_getPermanentURL is useful to create a permanent\n
URL out of a document which has been accessed either\n
directly or through a Web Section / Web Site. It is\n
the reverse method of WebSite_getDocumentValue.\n
"""\n """\n
# Return absolute URL if our parent is not a Web Section or Web Site\n # Return absolute URL if our parent is not a Web Section or Web Site\n
if context.aq_parent.getPortalType() not in (\'Web Section\', \'Web Site\'):\n if section is None and context.aq_parent.getPortalType() not in (\'Web Section\', \'Web Site\'):\n
return context.absolute_url()\n return context.absolute_url()\n
\n \n
# Return absolute URL if this is not an appropriate portal_type\n # Return absolute URL if this is not an appropriate portal_type\n
...@@ -120,10 +131,10 @@ if context.getValidationState() not in validation_state:\n ...@@ -120,10 +131,10 @@ if context.getValidationState() not in validation_state:\n
return context.absolute_url()\n return context.absolute_url()\n
\n \n
# Find the Web Section or Web Site we belong to\n # Find the Web Section or Web Site we belong to\n
current_section = context.getWebSectionValue()\n if section is None: section = context.getWebSectionValue()\n
\n \n
# Return the URL\n # Return the URL\n
return "%s/%s" % (current_section.absolute_url(), context.getReference())\n return "%s/%s" % (section.absolute_url(), context.getReference())\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -146,7 +157,7 @@ return "%s/%s" % (current_section.absolute_url(), context.getReference())\n ...@@ -146,7 +157,7 @@ return "%s/%s" % (current_section.absolute_url(), context.getReference())\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>section=None</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -166,17 +177,18 @@ return "%s/%s" % (current_section.absolute_url(), context.getReference())\n ...@@ -166,17 +177,18 @@ return "%s/%s" % (current_section.absolute_url(), context.getReference())\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>0</int> </value> <value> <int>1</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>section</string>
<string>None</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>valid_portal_type_list</string> <string>valid_portal_type_list</string>
<string>validation_state</string> <string>validation_state</string>
<string>current_section</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -188,7 +200,9 @@ return "%s/%s" % (current_section.absolute_url(), context.getReference())\n ...@@ -188,7 +200,9 @@ return "%s/%s" % (current_section.absolute_url(), context.getReference())\n
<item> <item>
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<tuple>
<none/> <none/>
</tuple>
</value> </value>
</item> </item>
<item> <item>
......
...@@ -389,20 +389,7 @@ ...@@ -389,20 +389,7 @@
<item> <item>
<key> <string>default_params</string> </key> <key> <string>default_params</string> </key>
<value> <value>
<list> <list/>
<tuple>
<string>id</string>
<string encoding="base64">Jyc=</string>
</tuple>
<tuple>
<string>title</string>
<string encoding="base64">Jyc=</string>
</tuple>
<tuple>
<string>description</string>
<string encoding="base64">Jyc=</string>
</tuple>
</list>
</value> </value>
</item> </item>
<item> <item>
...@@ -489,6 +476,10 @@ ...@@ -489,6 +476,10 @@
<list/> <list/>
</value> </value>
</item> </item>
<item>
<key> <string>page_template</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>portal_types</string> </key> <key> <string>portal_types</string> </key>
<value> <value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.ERP5Form.Form</string>
<string>ERP5Form</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</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/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left column</string>
<string>right column</string>
<string>footer</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>footer</string> </key>
<value>
<list>
<string>login_box</string>
</list>
</value>
</item>
<item>
<key> <string>left column</string> </key>
<value>
<list>
<string>website_logo</string>
<string>breadcrumb</string>
<string>sub_web_object_list</string>
<string>sub_document_list</string>
<string>admin_toolbox</string>
</list>
</value>
</item>
<item>
<key> <string>right column</string> </key>
<value>
<list>
<string>your_searchable_text</string>
<string>about_box</string>
<string>latest_news</string>
</list>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>erp5_web_default_layout</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>erp5_web_default_layout</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>erp5_web_default_template</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>6</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Default Web Layout</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -103,6 +103,7 @@ ...@@ -103,6 +103,7 @@
<key> <string>left column (Navigation)</string> </key> <key> <string>left column (Navigation)</string> </key>
<value> <value>
<list> <list>
<string>language_selector</string>
<string>breadcrumb</string> <string>breadcrumb</string>
</list> </list>
</value> </value>
......
...@@ -75,11 +75,15 @@ ...@@ -75,11 +75,15 @@
or by creating a new document.\n or by creating a new document.\n
\n \n
This script is called by the admin toolbox.\n This script is called by the admin toolbox.\n
"""\n
\n \n
Cloning or creation is prevented if document already exists\n
with same reference, version, language. Pretty messages\n
are provided to the user.\n
"""\n
translateString = context.Base_translateString\n
form_data = context.REQUEST.form\n form_data = context.REQUEST.form\n
\n \n
# Define a list of field name to ignore in the cloning process\n # Define a list of field name to take into account in the cloning process\n
ACCEPTABLE_FORM_ID_LIST = [ \\\n ACCEPTABLE_FORM_ID_LIST = [ \\\n
\'reference\'\n \'reference\'\n
, \'language\'\n , \'language\'\n
...@@ -89,14 +93,6 @@ ACCEPTABLE_FORM_ID_LIST = [ \\\n ...@@ -89,14 +93,6 @@ ACCEPTABLE_FORM_ID_LIST = [ \\\n
, \'short_title\'\n , \'short_title\'\n
]\n ]\n
\n \n
# Clone properties to the new object\n
kw = {}\n
property_id_list = context.propertyIds()\n
for (key, val) in form_data.items():\n
if key in ACCEPTABLE_FORM_ID_LIST and key in property_id_list:\n
kw[key] = val\n
new_object.edit(**kw)\n
\n
# First make sure that no document already exists with the\n # First make sure that no document already exists with the\n
# same portal_type, reference, language and version.\n # same portal_type, reference, language and version.\n
if clone:\n if clone:\n
...@@ -104,35 +100,35 @@ if clone:\n ...@@ -104,35 +100,35 @@ if clone:\n
else:\n else:\n
portal_type = form_data[\'new_portal_type\']\n portal_type = form_data[\'new_portal_type\']\n
\n \n
portal_catalog(portal_type=portal_type, reference=reference, ) \n # prepare query params\n
kw = {\'portal_type\' : portal_type}\n
if form_data.get(\'reference\'): kw[\'reference\'] = form_data[\'reference\']\n
if form_data.get(\'version\'): kw[\'version\'] = form_data[\'version\']\n
if form_data.get(\'language\'): kw[\'language\'] = form_data[\'language\']\n
\n \n
# Count documents of same reference and prepare kw\n
count = int(context.portal_catalog.countResults(**kw)[0][0])\n
kw[\'reference\'] = kw.get(\'reference\', \'undefined\')\n
kw[\'language\'] = kw.get(\'language\', \'any\')\n
kw[\'version\'] = kw.get(\'version\', \'undefined\')\n
# if count results not 0, warn user\n
if count:\n
return context.Base_redirect(form_id, editable_mode=editable_mode,\n
keep_items={\'portal_status_message\': translateString("Sorry, a ${portal_type} with reference \'${reference}\' and version \'${version} [${language}]\' already exists. Please select another reference or version.", mapping = kw)})\n
\n \n
# Standard cloning method\n # Standard cloning method\n
if clone:\n if clone:\n
\n
\n
\n
# TODO ?: If the document language hasn\'t changed and the version wasn\'t increased,\n
# change the copied document reference to "copy-of-%s". This idea came from\n
# the fact some published document are "invisible" because cloned documents\n
# share by default the same reference (within a set of documents of same\n
# references in a given section, only one document is display).\n
\n
# We copy contents in place if possible\n # We copy contents in place if possible\n
directory = getattr(context, \'original_container\', None) or context.getParentValue()\n directory = getattr(context, \'original_container\', None) or context.getParentValue()\n
\n \n
# Copy and paste the object\n # Copy and paste the object\n
original_id = getattr(context, \'original_id\', None) or context.getId() # This is required for objects acquired in Web Section\n original_id = getattr(context, \'original_id\', None) or context.getId()\n
# This is required for objects acquired in Web Section\n
clipboard = directory.manage_copyObjects(ids=[original_id])\n clipboard = directory.manage_copyObjects(ids=[original_id])\n
#context.log("Kev test clipboard >>>>>", repr(clipboard))\n #context.log("Kev test clipboard >>>>>", repr(clipboard))\n
paste_result = directory.manage_pasteObjects(cb_copy_data=clipboard)\n paste_result = directory.manage_pasteObjects(cb_copy_data=clipboard)\n
new_object = directory[paste_result[0][\'new_id\']]\n new_object = directory[paste_result[0][\'new_id\']]\n
\n message_kind = \'clone\'\n
#context.log("Kev test paste_result >>>>>", repr(paste_result))\n
#context.log("Kev test directory.WebSite_getUrl() >>>>>", repr(directory.WebSite_getUrl()))\n
#context.log("Kev test new_object.getId() >>>>>", repr(new_object.getId()))\n
\n
redirect_url = \'%s/view?editable_mode=1\' % new_object.absolute_url()\n
\n \n
# Create a new object here (this is a copy and paste of the previous WebSite_clone script)\n # Create a new object here (this is a copy and paste of the previous WebSite_clone script)\n
else:\n else:\n
...@@ -140,19 +136,20 @@ else:\n ...@@ -140,19 +136,20 @@ else:\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
module = portal.getDefaultModule(portal_type=portal_type)\n module = portal.getDefaultModule(portal_type=portal_type)\n
new_object = module.newContent(portal_type = portal_type)\n new_object = module.newContent(portal_type = portal_type)\n
redirect_url = \'%s/view?editable_mode=1\' % new_object.absolute_url()\n form_id = \'view\'\n
\n message_kind = \'new\'\n
\n \n
# Clone properties to the new object\n # Clone properties to the new object\n
kw = {}\n edit_kw = {}\n
property_id_list = new_object.propertyIds()\n property_id_list = new_object.propertyIds()\n
for (key, val) in form_data.items():\n for (key, val) in form_data.items():\n
if key in ACCEPTABLE_FORM_ID_LIST and key in property_id_list:\n if key in ACCEPTABLE_FORM_ID_LIST and key in property_id_list:\n
kw[key] = val\n edit_kw[key] = val\n
new_object.edit(**kw)\n new_object.edit(**edit_kw)\n
\n \n
\n if not editable_mode: form_id = \'view\'\n
return context.REQUEST.RESPONSE.redirect(redirect_url)\n return new_object.Base_redirect(form_id, editable_mode=1,\n
keep_items={\'portal_status_message\': translateString("Created %s ${portal_type} with reference \'${reference}\' and version \'${version} [${language}]\'." % message_kind, mapping = kw)})\n
]]></string> </value> ]]></string> </value>
...@@ -171,7 +168,7 @@ return context.REQUEST.RESPONSE.redirect(redirect_url)\n ...@@ -171,7 +168,7 @@ return context.REQUEST.RESPONSE.redirect(redirect_url)\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>clone=1</string> </value> <value> <string>clone=1, form_id, editable_mode=0</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -191,38 +188,42 @@ return context.REQUEST.RESPONSE.redirect(redirect_url)\n ...@@ -191,38 +188,42 @@ return context.REQUEST.RESPONSE.redirect(redirect_url)\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>1</int> </value> <value> <int>3</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>clone</string> <string>clone</string>
<string>form_id</string>
<string>editable_mode</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>translateString</string>
<string>form_data</string> <string>form_data</string>
<string>ACCEPTABLE_FORM_ID_LIST</string> <string>ACCEPTABLE_FORM_ID_LIST</string>
<string>portal_type</string>
<string>_getitem_</string>
<string>kw</string> <string>kw</string>
<string>property_id_list</string>
<string>_getiter_</string>
<string>key</string>
<string>val</string>
<string>_write_</string> <string>_write_</string>
<string>int</string>
<string>_apply_</string> <string>_apply_</string>
<string>new_object</string> <string>count</string>
<string>portal_type</string>
<string>_getitem_</string>
<string>portal_catalog</string>
<string>reference</string>
<string>getattr</string> <string>getattr</string>
<string>None</string> <string>None</string>
<string>directory</string> <string>directory</string>
<string>original_id</string> <string>original_id</string>
<string>clipboard</string> <string>clipboard</string>
<string>paste_result</string> <string>paste_result</string>
<string>redirect_url</string> <string>new_object</string>
<string>message_kind</string>
<string>portal</string> <string>portal</string>
<string>module</string> <string>module</string>
<string>edit_kw</string>
<string>property_id_list</string>
<string>_getiter_</string>
<string>key</string>
<string>val</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -236,6 +237,8 @@ return context.REQUEST.RESPONSE.redirect(redirect_url)\n ...@@ -236,6 +237,8 @@ return context.REQUEST.RESPONSE.redirect(redirect_url)\n
<value> <value>
<tuple> <tuple>
<int>1</int> <int>1</int>
<none/>
<int>0</int>
</tuple> </tuple>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>OFS.Folder</string>
<string>Folder</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>login_box</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>OFS.Folder</string>
<string>Folder</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_stuff_list</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Outdated code: need upgrade</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>OFS.Folder</string>
<string>Folder</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_task_list</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Outdated code: need upgrade</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>OFS.Folder</string>
<string>Folder</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>pending_work_list</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Outdated code: need upgrade</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>OFS.Folder</string>
<string>Folder</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>recent_changes</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Outdated code: need upgrade</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>OFS.Folder</string>
<string>Folder</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>search_box</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Outdated code: need upgrade</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>OFS.Folder</string>
<string>Folder</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>site_map</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Outdated code: need upgrade</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
497 510
\ No newline at end of file \ No newline at end of file
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