Back to index

plone3  3.1.7
metadata_edit_control.py
Go to the documentation of this file.
00001 ##parameters=allow_discussion, title=None, subject=None, description=None, contributors=None, effective_date=None, expiration_date=None, format=None, language=None, rights=None, **kw
00002 ##
00003 from Products.CMFCore.utils import getUtilityByInterfaceName
00004 from Products.CMFDefault.exceptions import ResourceLockedError
00005 from Products.CMFDefault.utils import Message as _
00006 
00007 dtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IDiscussionTool')
00008 
00009 def tuplify( value ):
00010 
00011     if not same_type( value, () ):
00012         value = tuple( value )
00013 
00014     temp = filter( None, value )
00015     return tuple( temp )
00016 
00017 if title is None:
00018     title = context.Title()
00019 
00020 if subject is None:
00021     subject = context.Subject()
00022 else:
00023     subject = tuplify( subject )
00024 
00025 if description is None:
00026     description = context.Description()
00027 
00028 if contributors is None:
00029     contributors = context.Contributors()
00030 else:
00031     contributors = tuplify( contributors )
00032 
00033 if effective_date is None:
00034     effective_date = context.EffectiveDate()
00035 
00036 if expiration_date is None:
00037     expiration_date = context.expires()
00038 
00039 if format is None:
00040     format = context.Format()
00041 
00042 if language is None:
00043     language = context.Language()
00044 
00045 if rights is None:
00046     rights = context.Rights()
00047 
00048 if allow_discussion == 'default':
00049     allow_discussion = None
00050 elif allow_discussion == 'off':
00051     allow_discussion = False
00052 elif allow_discussion == 'on':
00053     allow_discussion = True
00054 dtool.overrideDiscussionFor(context, allow_discussion)
00055 
00056 try:
00057     context.editMetadata( title=title
00058                         , description=description
00059                         , subject=subject
00060                         , contributors=contributors
00061                         , effective_date=effective_date
00062                         , expiration_date=expiration_date
00063                         , format=format
00064                         , language=language
00065                         , rights=rights
00066                         )
00067     return context.setStatus(True, _(u'Metadata changed.'))
00068 except ResourceLockedError, errmsg:
00069     return context.setStatus(False, errmsg)