Commit 912624a1 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added a gadget for random pages (improvement needed still)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35007 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 665d1a08
<?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>"""\n
Returns a random page in a given Web Section. This Gadget\n
renderer can be used asynchronously only for now. \n
\n
web_section_url -- a relative URL to the web section\n
(relative to portal or to site)\n
"""\n
import random\n
request = context.REQUEST\n
portal = context.getPortalObject()\n
\n
# Find the box if this gadget is asynchronous\n
# XXX-JPS: this could show that the script is \n
# not called on the appropriate context\n
# ie. the box. Discussion is needed here\n
# in order to make widgets and gadgets\n
# consistent (ie. develop once)\n
# --\n
# The biggest issue in current design\n
# is that all calls are made at the level\n
# of the site or at the level of the portal\n
# by passing a parameter to the object to\n
# edit. This is clearly againt object orientation\n
if box_relative_url:\n
box = portal.restrictedTraverse(box_relative_url)\n
\n
# Get the preferences (some casting of preferences would \n
# probably be a good thing here so that there is no need\n
# to cas them later)\n
preferences = box.KnowledgeBox_getDefaultPreferencesDict()\n
\n
if web_section_url is None:\n
web_section_url = preferences.get(\'web_section_url\', \'\') # XXX-JPS - Why do we have to do casting ? (used to be str()\n
\n
# Try to find the web site else use the portal\n
current_web_site = request.get(\'current_web_site\', None)\n
if current_web_site is None and parent_web_section_url is not None:\n
# XXX-JPS This shows inconsistent API between async and non async mode\n
# Some unification is needed\n
current_web_site = portal.restrictedTraverse(parent_web_section_url).getWebSiteValue()\n
if current_web_site is None:\n
current_web_site = portal\n
\n
# Try to find the real section\n
web_section = current_web_site.restrictedTraverse(web_section_url)\n
\n
# Select a random page in the web section\n
if web_section is not None:\n
web_page_list = web_section.getDocumentValueList()\n
web_page_len = len(web_page_list)\n
if web_page_len:\n
web_page_index = random.randint(0, web_page_len - 1)\n
return web_page_list[web_page_index].asStrippedHTML()\n
\n
return \'\' # Nothing to display\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>box=None, box_relative_url=None, is_gadget_mode=0, parent_web_section_url=None, editable_mode=None, web_section_url=None</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>6</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>box</string>
<string>box_relative_url</string>
<string>is_gadget_mode</string>
<string>parent_web_section_url</string>
<string>editable_mode</string>
<string>web_section_url</string>
<string>random</string>
<string>_getattr_</string>
<string>context</string>
<string>request</string>
<string>portal</string>
<string>preferences</string>
<string>None</string>
<string>current_web_site</string>
<string>web_section</string>
<string>web_page_list</string>
<string>len</string>
<string>web_page_len</string>
<string>web_page_index</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>
<none/>
<none/>
<none/>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_viewRandomPageGadget</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<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/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Base_edit</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Auto generated form</string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list>
<string>my_title</string>
</list>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list>
<string>my_web_section_url</string>
</list>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_viewRandomPageGadgetPreferenceDialog</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>Gadget_editERP5Person</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>gadget_preference_form_view</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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