Commit dea58870 authored by Jérome Perrin's avatar Jérome Perrin

When making a template, if a template with same title already exists, replace...

When making a template, if a template with same title already exists, replace it. This way we can easilly update an existing template.
Also check that the user has "Add portal content" permission in the preference.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34467 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bfb25bb3
No related merge requests found
......@@ -53,15 +53,28 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal_preferences = context.portal_preferences\n
<value> <string>portal = context.getPortalObject()\n
\n
preference = portal_preferences.getActivePreference()\n
if preference is None or preference.getPreferenceState()!=\'enabled\':\n
p = portal_preferences.newContent(portal_type=\'Preference\')\n
preference = portal.portal_preferences.getActivePreference()\n
if preference is None\\\n
or preference.getPreferenceState() != \'enabled\'\\\n
or not portal.portal_membership.checkPermission(\n
\'Add portal content\', preference):\n
p = portal.portal_preferences.newContent(portal_type=\'Preference\')\n
p.setTitle(\'Document Template Container\')\n
p.enable()\n
preference = p\n
\n
\n
# if the preference already contains a template with the same name, making\n
# another template will replace it\n
document_title = context.getTitle()\n
for existing_template in preference.contentValues(\n
portal_type=context.getPortalType()):\n
if existing_template.getTitle() == document_title:\n
preference.manage_delObjects(ids=[existing_template.getId()])\n
break\n
\n
parent = context.getParentValue()\n
document_id = context.getId()\n
cp = parent.manage_copyObjects(ids=[document_id])\n
......@@ -115,14 +128,16 @@ return context.Base_redirect(form_id,\n
<string>kw</string>
<string>_getattr_</string>
<string>context</string>
<string>portal_preferences</string>
<string>portal</string>
<string>preference</string>
<string>None</string>
<string>p</string>
<string>document_title</string>
<string>_getiter_</string>
<string>existing_template</string>
<string>parent</string>
<string>document_id</string>
<string>cp</string>
<string>_getiter_</string>
<string>paste_info</string>
<string>getattr</string>
<string>_getitem_</string>
......
1560
\ No newline at end of file
1561
\ 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