Commit 3dd4138c authored by Ivan Tyagov's avatar Ivan Tyagov

Use consistent API everywhere.

Use some macros (whenever possible).
Clean up code.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40923 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0ec2597c
......@@ -277,8 +277,41 @@
Please use link (<b>Add gadgets</b>) to prepare it yourself.\n
</h4>\n
</div>\n
</tal:block>\n
\n
\n
<tal:block metal:define-macro="create_default_pad">\n
<!-- Create (asynch) default pad. -->\n
<div tal:condition="python: not waitForActivitiesOnServer and \n
isUserAllowedToCreateKnowledgePads and\n
createDefaultPadForUser">\n
<div class="wait_block">\n
<h2 i18n:translate="" i18n:domain="ui"> \n
Please wait until your tab is being prepared.\n
</h2>\n
<p i18n:translate="" i18n:domain="ui"> You\'ll be automatically redirected.</p>\n
<script type="text/javascript"\n
tal:content="string: createDefaultPadOnServer(5000, \'ERP5Site_createDefaultKnowledgePadListForUser\',\n
\'${default_pad_group}\', \'view\', \'${mode}\');"/>\n
</div>\n
</div>\n
</tal:block>\n
\n
</tal:block>
\n
<tal:block metal:define-macro="create_default_pad_started">\n
\n
<!-- Show message that default pad is being prepared. -->\n
<div tal:condition="python: waitForActivitiesOnServer and isUserAllowedToCreateKnowledgePads">\n
<div class="wait_block">\n
<h2 i18n:translate="" i18n:domain="ui"> \n
Please wait until your home is being updated.</h2>\n
<p i18n:translate="" i18n:domain="ui"> You\'ll be automatically redirected.</p>\n
<script type="text/javascript" \n
tal:content="string: checkForActivitiesOnServer(5000, \'view\', \'${mode}\', \'\');"/>\n
</div>\n
</div>\n
</tal:block>\n
]]></unicode> </value>
</item>
......
......@@ -52,7 +52,10 @@
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
MARKER = (\'\', None,)\n
visible_state_list = [\'visible\', \'public\']\n
isAnon = context.portal_membership.isAnonymousUser()\n
\n
if isAnon and len(knowledge_pads)>=1:\n
# for anonymous we return the first one found \n
return knowledge_pads[0], knowledge_pads\n
......@@ -61,7 +64,7 @@ if isAnon and len(knowledge_pads)>=1:\n
active_pad, knowledge_pads = \\\n
context.ERP5Site_getActiveKnowledgePadForUserFromRequest(knowledge_pads,\n
\'active_pad_url\')\n
if active_pad is not None and active_pad.getValidationState() in (\'visible\', \'public\',):\n
if active_pad is not None and active_pad.getValidationState() in visible_state_list:\n
return active_pad, knowledge_pads\n
\n
# use info from REQUEST\n
......@@ -73,47 +76,29 @@ if active_knowledge_pad is not None:\n
\n
# first filter if we have a custom Pad for the context\n
for knowledge_pad in knowledge_pads:\n
if knowledge_pad.getPublicationSectionValue() == context and \\\n
knowledge_pad.getValidationState() in (\'visible\', \'public\',):\n
if (knowledge_pad.getPublicationSectionValue().getPortalType() == \'Web Site\' and \\\n
default_pad_group is None):\n
# return default active front page pad\n
pad_state = knowledge_pad.getValidationState()\n
publication_section = knowledge_pad.getPublicationSectionValue()\n
if publication_section == context and pad_state in visible_state_list:\n
if publication_section.getPortalType() == \'Web Site\' and default_pad_group in MARKER:\n
# ERP5 Web Site front gadget\n
return knowledge_pad, knowledge_pads\n
elif (knowledge_pad.getPublicationSectionValue() == context and \\\n
knowledge_pad.getGroup() == default_pad_group):\n
elif publication_section == context and knowledge_pad.getGroup() == default_pad_group:\n
# some Web Section can have a customized EXPLICILY "sticked" Pad\n
return knowledge_pad, knowledge_pads\n
elif publication_section == None and default_pad_group in MARKER and pad_state in visible_state_list:\n
# ERP5 Site front gadget \n
\n
return knowledge_pad, knowledge_pads \n
\n
\n
# no customized version found for this context so\n
# try finding pad by group\n
for knowledge_pad in knowledge_pads:\n
if knowledge_pad.getGroup() == default_pad_group and \\\n
knowledge_pad.getValidationState() in (\'visible\', \'public\',):\n
knowledge_pad.getValidationState() in visible_state_list:\n
return knowledge_pad, knowledge_pads\n
\n
return None, knowledge_pads\n
\n
"""\n
# REQUEST can be used to get active pad\n
active_knowledge_pad, knowledge_pads = \\\n
context.ERP5Site_getActiveKnowledgePadForUserFromRequest(knowledge_pads,\n
\'override_catalog\')\n
if active_knowledge_pad is not None:\n
return active_knowledge_pad, knowledge_pads\n
\n
# get visible one\n
for knowledge_pad in knowledge_pads:\n
if knowledge_pad.getValidationState() in (\'visible\', \'public\',):\n
active_knowledge_pad = knowledge_pad\n
break\n
\n
# REQUEST can be used to get active pad\n
if active_knowledge_pad is None:\n
active_knowledge_pad, knowledge_pads = \\\n
context.ERP5Site_getActiveKnowledgePadForUserFromRequest(knowledge_pads,\n
\'active_pad_url\')\n
return active_knowledge_pad, knowledge_pads\n
"""\n
]]></string> </value>
......@@ -126,7 +111,7 @@ return active_knowledge_pad, knowledge_pads\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>knowledge_pads = [], default_pad_group=None</string> </value>
<value> <string>knowledge_pads = [], mode = None, default_pad_group=None</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
......@@ -146,14 +131,18 @@ return active_knowledge_pad, knowledge_pads\n
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>2</int> </value>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>knowledge_pads</string>
<string>mode</string>
<string>default_pad_group</string>
<string>None</string>
<string>MARKER</string>
<string>visible_state_list</string>
<string>_getattr_</string>
<string>context</string>
<string>isAnon</string>
......@@ -161,9 +150,10 @@ return active_knowledge_pad, knowledge_pads\n
<string>_getitem_</string>
<string>_getiter_</string>
<string>active_pad</string>
<string>None</string>
<string>active_knowledge_pad</string>
<string>knowledge_pad</string>
<string>pad_state</string>
<string>publication_section</string>
</tuple>
</value>
</item>
......@@ -178,6 +168,7 @@ return active_knowledge_pad, knowledge_pads\n
<tuple>
<list/>
<none/>
<none/>
</tuple>
</value>
</item>
......
......@@ -2,10 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
......@@ -57,9 +54,11 @@
\n
if active_knowledge_pad is None and js_call:\n
# only for asynchronous checks\n
knowledge_pads = context.ERP5Site_getKnowledgePadListForUser(mode=mode)\n
active_knowledge_pad, knowledge_pads = \\\n
context.ERP5Site_getActiveKnowledgePadForUser(knowledge_pads)\n
kw = dict(mode=mode, \n
default_pad_group=default_pad_group)\n
knowledge_pads = context.ERP5Site_getKnowledgePadListForUser(**kw)\n
active_knowledge_pad, knowledge_pads = context.ERP5Site_getActiveKnowledgePadForUser(\n
knowledge_pads, **kw)\n
\n
if active_knowledge_pad is None:\n
# no pad but it may be reindexed in an activity now, check by tag\n
......@@ -74,6 +73,7 @@ if active_knowledge_pad is None:\n
\n
# we have an active pad, check if it has pending activities\n
is_pending_create_activities = active_knowledge_pad.hasActivity()\n
\n
if js_call:\n
return str(is_pending_create_activities)\n
return is_pending_create_activities\n
......@@ -87,7 +87,7 @@ return is_pending_create_activities\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>active_knowledge_pad=None, mode=None, default_pad_group=\'\', js_call=0</string> </value>
<value> <string>active_knowledge_pad=None, mode=None, default_pad_group=None, js_call=0</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
......@@ -121,6 +121,9 @@ return is_pending_create_activities\n
<string>context</string>
<string>portal</string>
<string>None</string>
<string>dict</string>
<string>kw</string>
<string>_apply_</string>
<string>knowledge_pads</string>
<string>_getiter_</string>
<string>tag</string>
......@@ -140,7 +143,7 @@ return is_pending_create_activities\n
<tuple>
<none/>
<none/>
<string></string>
<none/>
<int>0</int>
</tuple>
</value>
......
......@@ -39,23 +39,18 @@
<tal:block \n
tal:define="mode python: options.get(\'mode\', \'erp5_front\');\n
default_pad_group python: options.get(\'default_pad_group\', \'\');\n
knowledge_pads python: here.ERP5Site_getKnowledgePadListForUser(mode=mode);\n
struct python: here.ERP5Site_getActiveKnowledgePadForUser(knowledge_pads);\n
kw python: dict(mode=mode, default_pad_group=default_pad_group);\n
knowledge_pads python: here.ERP5Site_getKnowledgePadListForUser(**kw);\n
struct python: here.ERP5Site_getActiveKnowledgePadForUser(knowledge_pads, **kw);\n
global active_knowledge_pad python: struct[0];\n
knowledge_pads python: struct[1];\n
columns python: options.get(\'columns\', 3);\n
hasUserActivity python: here.ERP5Site_hasUserActivity(active_knowledge_pad,\n
mode=mode,\n
default_pad_group=default_pad_group);\n
hasUserActivity python: here.ERP5Site_hasUserActivity(active_knowledge_pad, **kw);\n
isAnon python: here.portal_membership.isAnonymousUser();\n
createDefaultPadForUser python: len(knowledge_pads)==0 and\n
not hasUserActivity;\n
waitForActivitiesOnServer python: active_knowledge_pad is None and\n
hasUserActivity;\n
isUserAllowedToCreateKnowledgePads\n
context/Base_isUserAllowedToUseKnowledgePad;\n
isKnowledgePadTemplateUsed python:\n
request.get(\'is_knowledge_pad_template_used\', 0);\n
createDefaultPadForUser python: len(knowledge_pads)==0 and not hasUserActivity;\n
waitForActivitiesOnServer python: active_knowledge_pad is None and hasUserActivity;\n
isUserAllowedToCreateKnowledgePads context/Base_isUserAllowedToUseKnowledgePad;\n
isKnowledgePadTemplateUsed python: request.get(\'is_knowledge_pad_template_used\', 0);\n
isAnonymousKnowledgePadUsed python: request.get(\'use_anonymous_knowledge_pad\', False);\n
cancel_url here/absolute_url;">\n
\n
......@@ -68,11 +63,11 @@
<!-- Pad navigation -->\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/navigation"/>\n
\n
<tal:block tal:condition="not: isAnon"> \n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/knowledge_pad_security_check"/> \n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/disable_server_integration"/>\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/disable_server_integration"/> \n
</tal:block>\n
<tal:block tal:condition="not: isAnon"> \n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/knowledge_pad_security_check"/> \n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/disable_server_integration"/>\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/disable_server_integration"/> \n
</tal:block>\n
\n
<!-- Render active Knowledge pad -->\n
<span tal:condition="active_knowledge_pad"\n
......@@ -87,31 +82,10 @@
</tal:block>\n
\n
<!-- Show message that default pad is being prepared. -->\n
<div tal:condition="python: waitForActivitiesOnServer and \n
isUserAllowedToCreateKnowledgePads">\n
<div class="wait_block">\n
<h2 i18n:translate="" i18n:domain="ui"> \n
Please wait until your home is being updated.</h2>\n
<p i18n:translate="" i18n:domain="ui"> You\'ll be automatically redirected.</p>\n
<script type="text/javascript" \n
tal:content="string: checkForActivitiesOnServer(5000, \'view\', \'${mode}\', \'\');"/>\n
</div>\n
</div>\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/create_default_pad_started"/>\n
\n
<!-- Create (asynch) default pad. -->\n
<div tal:condition="python: not waitForActivitiesOnServer and \n
isUserAllowedToCreateKnowledgePads and\n
createDefaultPadForUser">\n
<div class="wait_block">\n
<h2 i18n:translate="" i18n:domain="ui"> \n
Please wait until your tab is being prepared.\n
</h2>\n
<p i18n:translate="" i18n:domain="ui"> You\'ll be automatically redirected.</p>\n
<script type="text/javascript"\n
tal:content="string: createDefaultPadOnServer(5000, \'ERP5Site_createDefaultKnowledgePadListForUser\',\n
\'\', \'view\', \'${mode}\');"/>\n
</div>\n
</div>\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/create_default_pad"/>\n
\n
</div>\n
\n
......
......@@ -12,7 +12,7 @@
</item>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts91040808.94</string> </value>
<value> <string>ts91117034.62</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
......@@ -151,7 +151,7 @@ function createDefaultPadOnServer(timeout, create_url,\n
\'mode\': mode});\n
d.addCallbacks(handleServerSuccess, handleServerError);\n
function handleServerSuccess(res){\n
checkForActivitiesOnServer(timeout, return_url);};\n
checkForActivitiesOnServer(timeout, return_url, mode, default_pad_group);};\n
};\n
\n
// This function can be used to submit gadget preferences form whenever\n
......@@ -433,7 +433,7 @@ MochiKit.DOM.addLoadEvent(initialize);\n
</item>
<item>
<key> <string>size</string> </key>
<value> <int>15973</int> </value>
<value> <int>15998</int> </value>
</item>
<item>
<key> <string>title</string> </key>
......
......@@ -39,22 +39,17 @@
<tal:block \n
tal:define="mode python: options.get(\'mode\', \'web_section\');\n
default_pad_group python: options.get(\'default_pad_group\', None);\n
kw python: dict(mode=mode, default_pad_group=default_pad_group);\n
isAnonymousKnowledgePadUsed python: options.get(\'use_anonymous_knowledge_pad\', False);\n
pad_column python: options.get(\'pad_column\', 0);\n
create_default_pad python: options.get(\'create_default_pad\', False);\n
make_security_check python: options.get(\'make_security_check\', False);\n
dummy python: request.set(\'is_anonymous_knowledge_pad_used\', isAnonymousKnowledgePadUsed);\n
knowledge_pads python: here.ERP5Site_getKnowledgePadListForUser(\n
mode=mode,\n
default_pad_group=default_pad_group);\n
struct python: here.ERP5Site_getActiveKnowledgePadForUser(knowledge_pads, \n
default_pad_group);\n
knowledge_pads python: here.ERP5Site_getKnowledgePadListForUser(**kw);\n
struct python: here.ERP5Site_getActiveKnowledgePadForUser(knowledge_pads, **kw);\n
active_knowledge_pad python: struct[0];\n
knowledge_pads python: struct[1];\n
hasUserActivity python: here.ERP5Site_hasUserActivity(\n
active_knowledge_pad,\n
mode=mode,\n
default_pad_group=default_pad_group);\n
hasUserActivity python: here.ERP5Site_hasUserActivity(active_knowledge_pad, **kw);\n
isAnon python: context.portal_membership.isAnonymousUser();\n
createDefaultPadForUser python: len(knowledge_pads)==0 and\n
not hasUserActivity and create_default_pad;\n
......@@ -76,7 +71,7 @@
not waitForActivitiesOnServer and\n
active_knowledge_pad is not None">\n
\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/disable_server_integration"> Disable slot</span>\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/disable_server_integration"/>\n
\n
<div class="portal-column" \n
tal:attributes="class python: test(isAnon or isAnonymousKnowledgePadUsed, \n
......@@ -94,28 +89,8 @@
\n
</tal:block>\n
\n
<div tal:condition="python: not (isAnon or isAnonymousKnowledgePadUsed) and\n
createDefaultPadForUser and \n
isUserAllowedToCreateKnowledgePads">\n
\n
<div class="wait_block">\n
<h6 i18n:translate="" i18n:domain="ui"> \n
Please wait until your area is being prepared.\n
</h6>\n
<p i18n:translate="" i18n:domain="ui"> \n
You\'ll be automatically redirected in few seconds.\n
</p>\n
\n
<script type="text/javascript"\n
tal:content="structure python: \n
\'\'\'createDefaultPadOnServer(5000,\n
\'%s/ERP5Site_createDefaultKnowledgePadListForUser\', \n
\'%s\', \'%s/view\', \'%s\');\'\'\' \n
%(current_web_section_url, default_pad_group, current_web_section_url, mode)">\n
</script>\n
</div>\n
\n
</div>\n
<!-- Create (asynch) default pad. -->\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/create_default_pad"/>\n
\n
<tal:block tal:condition="make_security_check">\n
<span metal:use-macro="container/Base_viewKnowledgePadMacroLibrary/macros/knowledge_pad_security_check"/>\n
......
630
\ No newline at end of file
632
\ 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