Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
erp5
Commits
938cc648
Commit
938cc648
authored
Nov 12, 2012
by
Rafael Monnerat
Committed by
Xiaowu Zhang
Feb 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache WebSite/WebSection_getProductList
Use erp5_ui_short cache on Products List
parent
c6f1a758
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
34 deletions
+42
-34
bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSection_getProductList.xml
...rp5_commerce_widget_library/WebSection_getProductList.xml
+23
-12
bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSite_getProductList.xml
...s/erp5_commerce_widget_library/WebSite_getProductList.xml
+18
-21
bt5/erp5_commerce/bt/revision
bt5/erp5_commerce/bt/revision
+1
-1
No files found.
bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSection_getProductList.xml
View file @
938cc648
...
...
@@ -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>
...
...
bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSite_getProductList.xml
View file @
938cc648
...
...
@@ -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>
...
...
bt5/erp5_commerce/bt/revision
View file @
938cc648
289
\ No newline at end of file
290
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment