Commit 339cb7c6 authored by Rafael Monnerat's avatar Rafael Monnerat

Cache WebSite/WebSection_getProductList

Use erp5_ui_short cache on Products List
parent ce80edde
......@@ -50,28 +50,39 @@
</item>
<item>
<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
<value> <string># the goal of this script is to get all the related product of this section\n
from Products.ERP5Type.Cache import CachingMethod\n
current_web_section = context.REQUEST.get(\'current_web_section\', context)\n
product_list = []\n
\n
if not kw.has_key(\'portal_type\'):\n
kw[\'portal_type\'] = \'Product\'\n
\t \n
if not kw.has_key(\'limit\'):\t \n
kw[\'limit\'] = limit\n
\t\t \n
if not kw.has_key(\'limit\'):\t\t \n
kw[\'limit\'] = limit\t\t \n
\t\t \n
if not kw.has_key(\'all_versions\'):\t\t \n
kw[\'all_versions\'] = 1\t\t \n
if not kw.has_key(\'all_versions\'):\t \n
kw[\'all_versions\'] = 1\n
\t\t \n
if not kw.has_key(\'all_languages\'):\t\t \n
kw[\'all_languages\'] = 1\t\t \n
kw[\'all_languages\'] = 1\n
\t\t \n
for key in [\'limit\',\'all_versions\',\'all_languages\']:\t\t \n
kw[key] = int(kw[key])\t\t \n
kw[key] = int(kw[key])\n
\n
\n
def getProductList(context_relative_url, limit, all_versions, all_languages):\n
# Gabriel: The condition was added to not break the paypal return\n
# after finish the payment. The verify_sign is checked because all\n
# data from paypal have this key\n
if kw.has_key(\'quantity\') and kw.has_key("verify_sign"):\n
del kw[\'quantity\']\n
\t\t \n
product_list = current_web_section.getDocumentValueList(**kw)\n
return product_list\n
return current_web_section.getDocumentValueList(**kw)\n
\n
\n
return CachingMethod(getProductList,\n
id="WebSection_getProductList_ecommerce",\n
cache_factory=\'erp5_ui_short\')(current_web_section.getRelativeUrl(),kw[\'limit\'],kw[\'all_versions\'], kw[\'all_languages\'])\n
</string> </value>
</item>
<item>
......
......@@ -52,34 +52,31 @@
<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 choice\n
\n
web_site = context.getWebSiteValue() or context.REQUEST.get(\'current_web_site\')\n
\n
if not kw.has_key(\'portal_type\'):\t \t \n
if not kw.has_key(\'portal_type\'):\n
kw[\'portal_type\'] = \'Product\'\n
\n
def getProductList(limit, portal_type):\n
from random import choice\n
\n
web_site = context.getWebSiteValue() or context.REQUEST.get(\'current_web_site\')\n
\n
# Getting all the products from all the visible Web Section.\n
product_dict = {}\n
for web_section in web_site.WebSite_getMainSectionList():\n
for product in web_section.getDocumentValueList(all_versions=1, all_languages=1, **kw):\n
product_dict[product.uid] = product\n
\n
# Getting all the products from all the visible Web Section.\n
product_dict = {}\n
for web_section in web_site.WebSite_getMainSectionList():\n
for product in web_section.getDocumentValueList(all_versions=1, all_languages=1, **kw):\n
product_dict[product.uid] = product\n
if len(product_dict) > limit:\n
return random.sample(product_dict.values(), limit)\n
\n
if len(product_dict) > limit:\n
random_uid_list = []\n
key_list = product_dict.keys()\n
while len(random_uid_list) < limit:\n
random_uid = choice(key_list)\n
key_list.remove(random_uid)\n
random_uid_list.append(random_uid)\n
product_list = [product_dict.get(uid) for uid in random_uid_list]\n
else:\n
product_list = product_dict.values()\n
return product_dict.values()\n
\n
return product_list\n
return CachingMethod(getProductList,\n
id="WebSite_getProductList_ecommerce",\n
cache_factory=\'erp5_ui_short\')(limit, kw[\'portal_type\'])\n
]]></string> </value>
......
284
\ No newline at end of file
285
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