This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
pfwbged.basecontent/src/pfwbged/basecontent/browser/adddmsfile.py

85 lines
2.5 KiB
Python

from five import grok
from zope.interface import implements
from zope.component import getUtility, createObject
from Acquisition import aq_inner, aq_base
from Acquisition.interfaces import IAcquirer
from zope.annotation.interfaces import IAnnotations
from zope import schema
from plone.supermodel import model
from z3c.form import field, form, button
from plone.dexterity.interfaces import IDexterityFTI
from plone.dexterity.browser.add import DefaultAddView, DefaultAddForm
from plone.namedfile.field import NamedBlobFile
from plone.directives.form import default_value
from collective.dms.basecontent.dmsfile import IDmsFile, DmsFile
from collective.dms.basecontent.dmsdocument import IDmsDocument
from collective.dms.basecontent import _
class IAddVersion(model.Schema):
model.primary('file')
file = NamedBlobFile(
title=_(u"File"),
required=True,
)
label = schema.TextLine(
title=_(u'Label'),
required=False,
)
signed = schema.Bool(
title=_("Signed version"),
default=False)
class AddVersion(DefaultAddForm, form.AddForm):
grok.name('adddmsmainfile')
grok.context(IDmsDocument)
label = _(u'New version')
description = u''
schema = IAddVersion
portal_type = 'dmsmainfile'
def create(self, data):
fti = getUtility(IDexterityFTI, name=self.portal_type)
container = aq_inner(self.context)
content = createObject(fti.factory)
# Note: The factory may have done this already, but we want to be sure
# that the created type has the right portal type. It is possible
# to re-define a type through the web that uses the factory from an
# existing type, but wants a unique portal_type!
if hasattr(content, '_setPortalTypeName'):
content._setPortalTypeName(fti.getId())
# Acquisition wrap temporarily to satisfy things like vocabularies
# depending on tools
if IAcquirer.providedBy(content):
content = content.__of__(container)
content.signed = data.get('signed')
content.label = data.get('label')
content.file = data.get('file')
annotations = IAnnotations(container)
if 'higher_version' not in annotations:
content.title = u'1'
else:
content.title = unicode(annotations['higher_version'].value + 1)
for group in self.groups:
form.applyChanges(group, content, data)
return aq_base(content)