From 0c337f1677603d4f0690c7526840f5bd62ec68db Mon Sep 17 00:00:00 2001 From: Yoshinori Okuji <yo@nexedi.com> Date: Thu, 12 Jun 2008 03:02:17 +0000 Subject: [PATCH] 2008-06-12 yo * Refactor WebSection_getDocumentValueList, so that it can be mostly shared with km. Now this script relies on a custom Z SQL Method to generate a good query. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21519 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../WebSection_getDocumentValueList.xml | 110 +------- .../WebSection_getDocumentValueListBase.xml | 232 ++++++++++++++++ .../WebSection_zGetDocumentValueList.xml | 251 ++++++++++++++++++ bt5/erp5_web/bt/change_log | 3 + bt5/erp5_web/bt/revision | 2 +- 5 files changed, 496 insertions(+), 102 deletions(-) create mode 100644 bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_getDocumentValueListBase.xml create mode 100644 bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_zGetDocumentValueList.xml diff --git a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_getDocumentValueList.xml b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_getDocumentValueList.xml index 87503b2f18..3bb26370df 100644 --- a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_getDocumentValueList.xml +++ b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_getDocumentValueList.xml @@ -65,86 +65,9 @@ </item> <item> <key> <string>_body</string> </key> - <value> <string>"""\n - This script is part of ERP5 Web\n -\n - ERP5 Web is a business template of ERP5 which provides a way\n - to create web sites which can display selected\n - ERP5 contents through multiple custom web layouts.\n -\n - This script returns a list of document values (ie. objects or brains)\n - which are considered as part of this section. It can be\n - a list of web pages (usual case), a list of products\n - (online catalog), a list of tenders (e-government), etc.\n -\n - The default implementation provided here consists in\n - listing documents which meet the predicate defined\n - by the section (ex. which are part of a given publication_section)\n - and which are in "published" state and of a "Web Page" portal_type.\n -\n - It should be noted that document selection should be implemented\n - as much as possible using the Domain API.\n -\n - This script can be changed to meet other requirements. For example\n - one may want to display a list of products in a section. In this case,\n - this script must return a list of documents of type "Product"\n - with a "validated" state and in the appropriate product family.\n -\n - This script is intended to be overriden by creating a new script\n - within the Web Section or Web Site instance. It can be also\n - customised per portal type within portal_skins. Customisation\n - thourgh local scripts is recommended to host multiple sites\n - on the same ERP5Site instance.\n -\n - The API uses **kw so that it is possible to extend the behaviour of\n - the default script with advanced features (ex. group by reference,\n - by version, only select a specific publication state, etc.).\n -\n - Here are some suggestions which can either be implemented using\n - SQL (group_by, order_by) or using additional python scripting\n - if this is compatible with data size.\n -\n - SUGGESTIONS:\n -\n - - Prevent showing duplicate references\n - \n - - Add documents associated to this section through \'aggregate\'.\n -\n - - Display only the latest version and the appropriate language.\n -"""\n -from zExceptions import Unauthorized\n -\n -try:\n - portal = container.getPortalObject()\n - portal_catalog = portal.portal_catalog\n -\n - # First find the Web Section or Web Site we belong to\n - current_section = context.getWebSectionValue()\n -\n - # Build the list of parameters\n - if not kw.has_key(\'portal_type\'):\n - kw[\'portal_type\'] = portal.getPortalDocumentTypeList()\n -\n - if language is None:\n - language = portal.Localizer.get_selected_language()\n -\n - if validation_state is None:\n - validation_state = (\'released\', \'released_alive\', \'published\', \'published_alive\',\n - \'shared\', \'shared_alive\', \'public\', \'validated\')\n - if sort_on is None:\n - sort_on = [(\'int_index\', \'descending\')]\n -\n - if group_by is None:\n - group_by = (\'reference\',)\n -\n - # Return the list of matching documents for the given states\n - return current_section.searchResults(language=language,\n - validation_state=validation_state,\n - sort_on=sort_on,\n - group_by=group_by,\n - **kw)\n -except Unauthorized:\n - return []\n + <value> <string># In normal web sites, pages only in a selected language should be displayed.\n +kw[\'all_languages\'] = False\n +return context.WebSection_getDocumentValueListBase(**kw)\n </string> </value> </item> <item> @@ -167,7 +90,7 @@ except Unauthorized:\n </item> <item> <key> <string>_params</string> </key> - <value> <string>language=None, validation_state=None, sort_on=None, group_by=None, **kw</string> </value> + <value> <string>**kw</string> </value> </item> <item> <key> <string>errors</string> </key> @@ -187,28 +110,18 @@ except Unauthorized:\n <dictionary> <item> <key> <string>co_argcount</string> </key> - <value> <int>4</int> </value> + <value> <int>0</int> </value> </item> <item> <key> <string>co_varnames</string> </key> <value> <tuple> - <string>language</string> - <string>validation_state</string> - <string>sort_on</string> - <string>group_by</string> <string>kw</string> - <string>zExceptions</string> - <string>Unauthorized</string> - <string>_getattr_</string> - <string>container</string> - <string>portal</string> - <string>portal_catalog</string> - <string>context</string> - <string>current_section</string> + <string>False</string> <string>_write_</string> - <string>None</string> <string>_apply_</string> + <string>_getattr_</string> +<string>context</string> </tuple> </value> </item> @@ -220,12 +133,7 @@ except Unauthorized:\n <item> <key> <string>func_defaults</string> </key> <value> - <tuple> - <none/> - <none/> - <none/> - <none/> - </tuple> + <none/> </value> </item> <item> diff --git a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_getDocumentValueListBase.xml b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_getDocumentValueListBase.xml new file mode 100644 index 0000000000..ca7f0d283a --- /dev/null +++ b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_getDocumentValueListBase.xml @@ -0,0 +1,232 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <global name="PythonScript" module="Products.PythonScripts.PythonScript"/> + <tuple/> + </tuple> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>Python_magic</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>Script_magic</string> </key> + <value> <int>3</int> </value> + </item> + <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> + <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>_body</string> </key> + <value> <string>"""\n + This script is part of ERP5 Web\n +\n + ERP5 Web is a business template of ERP5 which provides a way\n + to create web sites which can display selected\n + ERP5 contents through multiple custom web layouts.\n +\n + This script returns a list of document values (ie. objects or brains)\n + which are considered as part of this section. It can be\n + a list of web pages (usual case), a list of products\n + (online catalog), a list of tenders (e-government), etc.\n +\n + The default implementation provided here consists in\n + listing documents which meet the predicate defined\n + by the section (ex. which are part of a given publication_section)\n + and which are in "published" state and of a "Web Page" portal_type.\n +\n + It should be noted that document selection should be implemented\n + as much as possible using the Domain API.\n +\n + This script can be changed to meet other requirements. For example\n + one may want to display a list of products in a section. In this case,\n + this script must return a list of documents of type "Product"\n + with a "validated" state and in the appropriate product family.\n +\n + This script is intended to be overriden by creating a new script\n + within the Web Section or Web Site instance. It can be also\n + customised per portal type within portal_skins. Customisation\n + thourgh local scripts is recommended to host multiple sites\n + on the same ERP5Site instance.\n +\n + The API uses **kw so that it is possible to extend the behaviour of\n + the default script with advanced features (ex. group by reference,\n + by version, only select a specific publication state, etc.).\n +\n + Here are some suggestions which can either be implemented using\n + SQL (group_by, order_by) or using additional python scripting\n + if this is compatible with data size.\n +\n + SUGGESTIONS:\n +\n + - Prevent showing duplicate references\n + \n + - Add documents associated to this section through \'aggregate\'.\n +\n + - Display only the latest version and the appropriate language.\n +"""\n +from zExceptions import Unauthorized\n +\n +try:\n + portal = container.getPortalObject()\n +\n + # First find the Web Section or Web Site we belong to\n + current_section = context.getWebSectionValue()\n +\n + # Build the list of parameters\n + if language is None:\n + language = portal.Localizer.get_selected_language()\n +\n + if validation_state is None:\n + validation_state = (\'released\', \'released_alive\', \'published\', \'published_alive\',\n + \'shared\', \'shared_alive\', \'public\', \'validated\')\n +\n + query = current_section.buildSQLQuery(validation_state=validation_state, **kw)\n + return current_section.WebSection_zGetDocumentValueList(language=language,\n + all_languages=all_languages,\n + from_table_list=query[\'from_table_list\'],\n + where_expression=query[\'where_expression\'])\n +except Unauthorized:\n + return []\n +</string> </value> + </item> + <item> + <key> <string>_code</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_filepath</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_owner</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string>language=None, validation_state=None, all_languages=False, **kw</string> </value> + </item> + <item> + <key> <string>errors</string> </key> + <value> + <tuple/> + </value> + </item> + <item> + <key> <string>func_code</string> </key> + <value> + <object> + <klass> + <global name="FuncCode" module="Shared.DC.Scripts.Signature"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>co_argcount</string> </key> + <value> <int>3</int> </value> + </item> + <item> + <key> <string>co_varnames</string> </key> + <value> + <tuple> + <string>language</string> + <string>validation_state</string> + <string>all_languages</string> + <string>kw</string> + <string>zExceptions</string> + <string>Unauthorized</string> + <string>_getattr_</string> + <string>container</string> + <string>portal</string> + <string>context</string> + <string>current_section</string> + <string>None</string> + <string>_apply_</string> + <string>query</string> + <string>_getitem_</string> + </tuple> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>func_defaults</string> </key> + <value> + <tuple> + <none/> + <none/> + <int>0</int> + </tuple> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>WebSection_getDocumentValueListBase</string> </value> + </item> + <item> + <key> <string>warnings</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_zGetDocumentValueList.xml b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_zGetDocumentValueList.xml new file mode 100644 index 0000000000..11338d0e88 --- /dev/null +++ b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web/WebSection_zGetDocumentValueList.xml @@ -0,0 +1,251 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <global name="SQL" module="Products.ZSQLMethods.SQL"/> + <tuple/> + </tuple> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>__ac_local_roles__</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_arg</string> </key> + <value> + <object> + <klass> + <global name="Args" module="Shared.DC.ZRDB.Aqueduct"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_data</string> </key> + <value> + <dictionary> + <item> + <key> <string>all_languages</string> </key> + <value> + <dictionary/> + </value> + </item> + <item> + <key> <string>from_table_list</string> </key> + <value> + <dictionary> + <item> + <key> <string>type</string> </key> + <value> <string>list</string> </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>language</string> </key> + <value> + <dictionary/> + </value> + </item> + <item> + <key> <string>where_expression</string> </key> + <value> + <dictionary/> + </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>_keys</string> </key> + <value> + <list> +<string>language</string> +<string>all_languages</string> +<string>from_table_list</string> +<string>where_expression</string> + </list> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>_owner</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>allow_simple_one_argument_traversal</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>arguments_src</string> </key> + <value> <string>language\r\n +all_languages\r\n +from_table_list:list\r\n +where_expression</string> </value> + </item> + <item> + <key> <string>cache_time_</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>class_file_</string> </key> + <value> <string>ZSQLCatalog.zsqlbrain</string> </value> + </item> + <item> + <key> <string>class_name_</string> </key> + <value> <string>ZSQLBrain</string> </value> + </item> + <item> + <key> <string>connection_hook</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>connection_id</string> </key> + <value> <string>erp5_sql_connection</string> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>WebSection_zGetDocumentValueList</string> </value> + </item> + <item> + <key> <string>max_cache_</string> </key> + <value> <int>100</int> </value> + </item> + <item> + <key> <string>max_rows_</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>src</string> </key> + <value> <string encoding="cdata"><![CDATA[ + +SELECT\n + t.path AS path, t.uid AS uid, t.version AS version\n +FROM\n + (\n + SELECT\n + catalog.uid, catalog.path, catalog.int_index,\n + catalog.reference, my_versioning.language, my_versioning.version\n + FROM\n + <dtml-in from_table_list><dtml-var sequence-item> AS <dtml-var sequence-key>,</dtml-in>\n + versioning AS my_versioning\n + WHERE\n + my_versioning.uid = catalog.uid\n + AND <dtml-var where_expression>\n +<dtml-if all_languages>\n + GROUP BY\n + catalog.reference\n + HAVING\n + MAX(CASE my_versioning.language WHEN <dtml-sqlvar language type="string"> THEN 3 WHEN \'en\' THEN 2 ELSE 1 END)\n + = CASE my_versioning.language WHEN <dtml-sqlvar language type="string"> THEN 3 WHEN \'en\' THEN 2 ELSE 1 END\n +<dtml-else>\n + AND my_versioning.language = <dtml-sqlvar language type="string">\n +</dtml-if>\n + ) AS t\n +GROUP BY\n + t.reference\n +HAVING\n + MAX(t.version) = t.version\n +ORDER BY\n + t.int_index, t.reference\n +LIMIT 1000\n + + +]]></string> </value> + </item> + <item> + <key> <string>template</string> </key> + <value> + <object> + <klass> + <global name="__newobj__" module="copy_reg"/> + </klass> + <tuple> + <global name="SQL" module="Shared.DC.ZRDB.DA"/> + </tuple> + <state> + <dictionary> + <item> + <key> <string>__name__</string> </key> + <value> <string encoding="cdata"><![CDATA[ + +<string> + +]]></string> </value> + </item> + <item> + <key> <string>_vars</string> </key> + <value> + <dictionary/> + </value> + </item> + <item> + <key> <string>globals</string> </key> + <value> + <dictionary/> + </value> + </item> + <item> + <key> <string>raw</string> </key> + <value> <string encoding="cdata"><![CDATA[ + +SELECT\n + t.path AS path, t.uid AS uid, t.version AS version\n +FROM\n + (\n + SELECT\n + catalog.uid, catalog.path, catalog.int_index,\n + catalog.reference, my_versioning.language, my_versioning.version\n + FROM\n + <dtml-in from_table_list><dtml-var sequence-item> AS <dtml-var sequence-key>,</dtml-in>\n + versioning AS my_versioning\n + WHERE\n + my_versioning.uid = catalog.uid\n + AND <dtml-var where_expression>\n +<dtml-if all_languages>\n + GROUP BY\n + catalog.reference\n + HAVING\n + MAX(CASE my_versioning.language WHEN <dtml-sqlvar language type="string"> THEN 3 WHEN \'en\' THEN 2 ELSE 1 END)\n + = CASE my_versioning.language WHEN <dtml-sqlvar language type="string"> THEN 3 WHEN \'en\' THEN 2 ELSE 1 END\n +<dtml-else>\n + AND my_versioning.language = <dtml-sqlvar language type="string">\n +</dtml-if>\n + ) AS t\n +GROUP BY\n + t.reference\n +HAVING\n + MAX(t.version) = t.version\n +ORDER BY\n + t.int_index, t.reference\n +LIMIT 1000\n + + +]]></string> </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_web/bt/change_log b/bt5/erp5_web/bt/change_log index 10fad2f86e..f90563c855 100644 --- a/bt5/erp5_web/bt/change_log +++ b/bt5/erp5_web/bt/change_log @@ -1,3 +1,6 @@ +2008-06-12 yo +* Refactor WebSection_getDocumentValueList, so that it can be mostly shared with km. Now this script relies on a custom Z SQL Method to generate a good query. + 2008-06-11 yo * Make WebSection_getPermanentURL consistent. diff --git a/bt5/erp5_web/bt/revision b/bt5/erp5_web/bt/revision index 837f72e62a..e2756006da 100644 --- a/bt5/erp5_web/bt/revision +++ b/bt5/erp5_web/bt/revision @@ -1 +1 @@ -643 \ No newline at end of file +644 \ No newline at end of file -- 2.30.9