Back to index

plone3  3.1.7
prefs_group_edit.py
Go to the documentation of this file.
00001 ## Script (Python) "prefs_group_edit"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=addname=None, groupname=None
00008 ##title=Edit user
00009 ##
00010 
00011 from Products.CMFPlone import PloneMessageFactory as _
00012 
00013 REQUEST=context.REQUEST
00014 msg = _(u'No changes made.')
00015 
00016 if addname:
00017     success = context.portal_groups.addGroup(addname,(),(),REQUEST=context.REQUEST)
00018     if not success:
00019         msg = _(u'Could not add group ${name}, perhaps a user or group with '
00020                 u'this name already exists.', mapping={u'name' : addname})
00021         context.plone_utils.addPortalMessage(msg, 'error')
00022         return context.prefs_group_details()
00023     group=context.portal_groups.getGroupById(addname)
00024     msg = _(u'Group ${name} has been added.',
00025             mapping={u'name' : addname})
00026 else:
00027     group=context.portal_groups.getGroupById(groupname)
00028     msg = _(u'Changes saved.')
00029 
00030 processed={}
00031 for id, property in context.portal_groupdata.propertyItems():
00032     processed[id]=REQUEST.get(id, None)
00033 
00034 if group:
00035     # for what reason ever, the very first group created does not exist
00036     group.setGroupProperties(processed)
00037 
00038 context.plone_utils.addPortalMessage(msg)
00039 
00040 return REQUEST.RESPONSE.redirect(context.prefs_groups_overview.absolute_url())