[Erp5-report] r44616 ivan - in /erp5/trunk/bt5/erp5_web: SkinTemplateItem/portal_skins/erp5...

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Mar 25 13:05:08 CET 2011


Author: ivan
Date: Fri Mar 25 13:05:08 2011
New Revision: 44616

URL: http://svn.erp5.org?rev=44616&view=rev
Log:
Add a generic script to redirect current logged in user to his/hers preference (create one if not already created). Moved from erp5_km.

Added:
    erp5/trunk/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_redirectToUserPreference.xml
Modified:
    erp5/trunk/bt5/erp5_web/bt/revision

Added: erp5/trunk/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_redirectToUserPreference.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_redirectToUserPreference.xml?rev=44616&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_redirectToUserPreference.xml (added)
+++ erp5/trunk/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_redirectToUserPreference.xml [utf8] Fri Mar 25 13:05:08 2011
@@ -0,0 +1,111 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+    </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
+  This script redirects the current user to its \n
+  active preference. If a user has no preference\n
+  yet, then it creates a new preference and redirects\n
+  to it. In case a failure, a message is displayed.\n
+"""\n
+from zExceptions import Unauthorized\n
+\n
+# Initialize some useful variables\n
+request = context.REQUEST\n
+portal = context.getPortalObject()\n
+website = context.getWebSiteValue()\n
+user = portal.portal_membership.getAuthenticatedMember()\n
+user_preference = None\n
+portal_preferences = portal.portal_preferences\n
+\n
+# Find user owned preferences\n
+kw = {\'portal_type\': \'Preference\',\n
+      \'owner\': user}\n
+user_preference_list = portal_preferences.searchFolder(**kw)\n
+\n
+if not len(user_preference_list):\n
+  # create and enable a user owned preference\n
+  # if no preference exists\n
+  try:\n
+    user_preference = portal_preferences.newContent(\n
+                                         portal_type=\'Preference\', \n
+                                         title=\'Preference for %s\' %user)\n
+    user_preference.enable()\n
+  except Unautorized:\n
+    # user is not allowed to have its own preference\n
+    user_preference = None\n
+else:\n
+  user_active_preference_list = portal_preferences.searchFolder(\n
+                                preference_state=\'active\', **kw)\n
+  if len(user_active_preference_list):\n
+    # try to find an active preference\n
+    user_preference = user_active_preference_list[0]\n
+  else:\n
+    # if not use the first non active\n
+    user_preference = user_preference_list[0]\n
+\n
+# make sure next view is returned again into the context of the web site itself\n
+if user_preference is None:\n
+  translateString = context.Base_translateString\n
+  msg = translateString("Could not create user preferences.")\n
+  return context.Base_redirect(form_id="view", keep_items={\'portal_status_message\':msg})\n
+else:\n
+  return user_preference.Base_redirect(form_id="view", keep_items={\'editable_mode\':1})\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>WebSite_redirectToUserPreference</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>

Modified: erp5/trunk/bt5/erp5_web/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_web/bt/revision?rev=44616&r1=44615&r2=44616&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_web/bt/revision [utf8] (original)
+++ erp5/trunk/bt5/erp5_web/bt/revision [utf8] Fri Mar 25 13:05:08 2011
@@ -1 +1 @@
-1038
\ No newline at end of file
+1039
\ No newline at end of file



More information about the Erp5-report mailing list