Back to index

plone3  3.1.7
metadata_edit_form.py
Go to the documentation of this file.
00001 ##parameters=change='', change_and_edit='', change_and_view=''
00002 ##
00003 from Products.CMFCore.utils import getUtilityByInterfaceName
00004 from Products.CMFDefault.utils import decode
00005 from Products.CMFDefault.utils import Message as _
00006 
00007 mdtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IMetadataTool')
00008 
00009 
00010 form = context.REQUEST.form
00011 if change and \
00012         context.metadata_edit_control(**form) and \
00013         context.setRedirect(context, 'object/metadata'):
00014     return
00015 elif change_and_edit and \
00016         context.metadata_edit_control(**form) and \
00017         context.setRedirect(context, 'object/edit'):
00018     return
00019 elif change_and_view and \
00020         context.metadata_edit_control(**form) and \
00021         context.setRedirect(context, 'object/view'):
00022     return
00023 
00024 
00025 options = {}
00026 
00027 allow_discussion = getattr(context, 'allow_discussion', None)
00028 if allow_discussion is not None:
00029     allow_discussion = bool(allow_discussion)
00030 options['allow_discussion'] = allow_discussion
00031 
00032 options['identifier'] = context.Identifier()
00033 options['title'] = form.get('title', context.Title())
00034 options['description'] = form.get('description', context.Description())
00035 
00036 subject = form.get('subject', context.Subject())
00037 allowed_subjects = mdtool.listAllowedSubjects(context)
00038 extra_subjects = [ s for s in subject if not s in allowed_subjects ]
00039 options['allowed_subjects'] = tuple(allowed_subjects)
00040 options['extra_subjects'] = tuple(extra_subjects)
00041 options['subject'] = tuple(subject)
00042 options['format'] = form.get('format', context.Format())
00043 options['contributors'] = form.get('contributors', context.Contributors())
00044 options['language'] = form.get('language', context.Language())
00045 options['rights'] = form.get('rights', context.Rights())
00046 
00047 buttons = []
00048 target = context.getActionInfo('object/metadata')['url']
00049 buttons.append( {'name': 'change', 'value': _(u'Change')} )
00050 buttons.append( {'name': 'change_and_edit', 'value': _(u'Change and Edit')} )
00051 buttons.append( {'name': 'change_and_view', 'value': _(u'Change and View')} )
00052 
00053 options['form'] = { 'action': target,
00054                     'listButtonInfos': tuple(buttons) }
00055 
00056 return context.metadata_edit_template(**decode(options, script))