Commit 7a3ac3a0 authored by Lucas Carvalho's avatar Lucas Carvalho

- does not matter which is the context, all the products must be shown randomly.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28743 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0378f6a3
...@@ -54,13 +54,15 @@ ...@@ -54,13 +54,15 @@
- make it hierarchic\n - make it hierarchic\n
-->\n -->\n
</tal:block>\n </tal:block>\n
<div tal:define="site_url python:here.getWebSiteValue().absolute_url();\n <div tal:define="web_site python: here.getWebSiteValue();\n
site_url python: web_site.absolute_url();\n
current_web_section python:request.get(\'current_web_section\', here);\n current_web_section python:request.get(\'current_web_section\', here);\n
shopping_cart here/SaleOrder_getShoppingCart;\n shopping_cart here/SaleOrder_getShoppingCart;\n
currency_symbol python: shopping_cart.SaleOrder_getShoppingCartDefaultCurrencySymbol();"\n currency_symbol python: shopping_cart.SaleOrder_getShoppingCartDefaultCurrencySymbol();\n
product_list python: web_site.WebSite_getProductList(limit=5);"\n
i18n:translate="" i18n:domain="ui" i18n:attributes="title"\n i18n:translate="" i18n:domain="ui" i18n:attributes="title"\n
title="Sections accessible from here." class="selected-product">\n title="Sections accessible from here." class="selected-product">\n
<tal:block tal:repeat="product python: here.WebSection_getProductList(limit=5)">\n <tal:block tal:repeat="product python: product_list">\n
<div tal:define="product_href python: \'%s/product_module/%s/%s\' % (site_url, product.getId(), \'Resource_viewAsShop\');\n <div tal:define="product_href python: \'%s/product_module/%s/%s\' % (site_url, product.getId(), \'Resource_viewAsShop\');\n
price python: here.WebSection_unrestrictedGetPrice(product)">\n price python: here.WebSection_unrestrictedGetPrice(product)">\n
<a href="#" tal:attributes="href product_href">\n <a href="#" tal:attributes="href product_href">\n
......
<?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>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>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
#TODO : USE CACHE\n
# The goal of this script is to get all the products from all the visible Web Sections\n
# and it must select randomly which product must be displayed for a given context.\n
from random import randrange\n
\n
web_site = context.getWebSiteValue() or context.REQUEST.get(\'current_web_site\')\n
product_list = []\n
kw[\'portal_type\'] = \'Product\'\n
kw[\'limit\'] = limit\n
\n
# Getting all the products from all the visible Web Section.\n
web_section_list = web_site.WebSite_getMainSectionList()\n
for web_section in web_section_list:\n
product_result_list = web_section.WebSection_getDocumentValueListBase(all_versions=1, all_languages=1, **kw)\n
for product in product_result_list:\n
if product.getObject() not in product_list:\n
product_list.append(product.getObject())\n
\n
if len(product_list) <= limit:\n
product_list = [x for x in product_list if x.getPortalType() == \'Product\']\n
else:\n
random_index_list = []\n
while len(random_index_list) < limit:\n
random_number = randrange(0, len(product_list))\n
if random_number not in random_index_list:\n
random_index_list.append(random_number)\n
product_list = [product_list[x] for x in random_index_list if product_list[x].getPortalType() == \'Product\']\n
return product_list\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>limit=5, **kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Authenticated</string>
<string>Author</string>
<string>Manager</string>
<string>Member</string>
<string>Owner</string>
<string>Reviewer</string>
</tuple>
</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>1</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>limit</string>
<string>kw</string>
<string>random</string>
<string>randrange</string>
<string>_getattr_</string>
<string>context</string>
<string>web_site</string>
<string>product_list</string>
<string>_write_</string>
<string>web_section_list</string>
<string>_getiter_</string>
<string>web_section</string>
<string>_apply_</string>
<string>product_result_list</string>
<string>product</string>
<string>len</string>
<string>append</string>
<string>$append0</string>
<string>x</string>
<string>random_index_list</string>
<string>random_number</string>
<string>_getitem_</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<int>5</int>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSite_getProductList</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
180 182
\ 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