diff --git a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_redirectToUserPreference.xml b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_redirectToUserPreference.xml new file mode 100644 index 0000000000000000000000000000000000000000..277a21b08906ee83c8ce03c4e701a761475a10e3 --- /dev/null +++ b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_redirectToUserPreference.xml @@ -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> diff --git a/bt5/erp5_web/bt/revision b/bt5/erp5_web/bt/revision index 0f746c73b16ee0ca210cff3fb7e1c98e6e1d2aa8..2d677318be9a7f186911d1213fec0ee5c2361989 100644 --- a/bt5/erp5_web/bt/revision +++ b/bt5/erp5_web/bt/revision @@ -1 +1 @@ -1038 \ No newline at end of file +1039 \ No newline at end of file