Back to index

plone3  3.1.7
revertversion.py
Go to the documentation of this file.
00001 ## Script (Python) "revertversion"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=version_id
00008 ##title=Revert version
00009 ##
00010 
00011 from Products.CMFPlone import PloneMessageFactory as _
00012 from Products.CMFEditions.interfaces.IModifier import FileTooLargeToVersionError
00013 
00014 RESPONSE = context.REQUEST.RESPONSE
00015 putils = container.plone_utils
00016 pr = container.portal_repository
00017 pr.revert(context, version_id)
00018 view_url = '%s/%s' % (context.absolute_url(),
00019                       context.getTypeInfo().getActionInfo('object/view')['url']
00020                      )
00021 
00022 title = context.title_or_id()
00023 if not isinstance(title, unicode):
00024     title = unicode(title, 'utf-8', 'ignore')
00025 
00026 msg = _(u'${title} has been reverted to version ${version}.',
00027         mapping={'title' : context.title_or_id(), 'version' : version_id})
00028 
00029 if pr.supportsPolicy(context, 'version_on_revert'):
00030     try:
00031         pr.save(obj=context, comment=_(u"Reverted to version ${version}",
00032                                        mapping={'version': version_id}))
00033     except FileTooLargeToVersionError:
00034         putils.addPortalMessage(
00035   _("The most current version of the file could not be saved before reverting "
00036     "because the file is too large."),
00037        type="warn"
00038        )
00039 
00040 context.plone_utils.addPortalMessage(msg)
00041 return RESPONSE.redirect(view_url)