Commit d2dca3df authored by Lucas Carvalho's avatar Lucas Carvalho

- refactored the WebSection_getProductList script

- is better use portal catalog than getObject in WebSite_getProductList

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28802 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a6dd63ac
......@@ -55,23 +55,11 @@
<key> <string>_body</string> </key>
<value> <string>#TODO : USE CACHE\n
#the goal of this script is to get all the related product of this section\n
\n
current_web_section = context.REQUEST.get(\'current_web_section\', context)\n
product_list = []\n
\n
kw[\'portal_type\'] = \'Product\'\n
kw[\'limit\'] = limit\n
if current_web_section.getMembershipCriterionCategoryList() in (None, []) and current_web_section.getCriterionList() in (None, []):\n
kw[\'product_line_uid\'] = context.REQUEST.get(\'current_web_site\').getLayoutProperty(\'ecommerce_base_product_line\', \'\')\n
\n
product_list = current_web_section.WebSection_getDocumentValueListBase(all_versions=1,\n
all_languages=1,\n
**kw)\n
product_list = [x.getObject() for x in product_list if x.getPortalType() == \'Product\']\n
\n
# this step will be remove after have find a good way to improve WebSection_getDocumentValueListBase\n
# or find another base script for get only product direclty\n
\n
product_list = current_web_section.getDocumentValueList(all_versions=1, all_languages=1, **kw)\n
return product_list\n
</string> </value>
</item>
......@@ -133,12 +121,7 @@ return product_list\n
<string>current_web_section</string>
<string>product_list</string>
<string>_write_</string>
<string>None</string>
<string>_apply_</string>
<string>append</string>
<string>$append0</string>
<string>_getiter_</string>
<string>x</string>
</tuple>
</value>
</item>
......
......@@ -67,7 +67,7 @@ kw[\'limit\'] = limit\n
\n
# Getting all the products from all the visible Web Section.\n
for web_section in web_site.WebSite_getMainSectionList():\n
product_list.extend([x.getObject() for x in web_section.getDocumentValueList(all_versions=1, all_languages=1, **kw) if x.getObject() not in product_list])\n
product_list.extend([x.uid for x in web_section.getDocumentValueList(all_versions=1, all_languages=1, **kw) if x.uid not in product_list])\n
\n
if len(product_list) > limit:\n
random_index_list = []\n
......@@ -75,7 +75,9 @@ if len(product_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
product_list = [product_list[x] for x in random_index_list]\n
\n
product_list = context.portal_catalog(portal_type=\'Product\', uid=product_list)\n
return product_list\n
......
188
\ No newline at end of file
190
\ 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