From 01412996bc3c4622d9efe79fbbb0022a9642b653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 14 Oct 2013 15:59:34 +0200 Subject: [PATCH] prepare for custom add form for versions (#3769) --- src/pfwbged/basecontent/browser/adddmsfile.py | 84 +++++++++++++++++++ .../basecontent/browser/configure.zcml | 8 ++ .../profiles/default/types/dmsmainfile.xml | 5 ++ 3 files changed, 97 insertions(+) create mode 100644 src/pfwbged/basecontent/browser/adddmsfile.py create mode 100644 src/pfwbged/basecontent/profiles/default/types/dmsmainfile.xml diff --git a/src/pfwbged/basecontent/browser/adddmsfile.py b/src/pfwbged/basecontent/browser/adddmsfile.py new file mode 100644 index 0000000..f585c93 --- /dev/null +++ b/src/pfwbged/basecontent/browser/adddmsfile.py @@ -0,0 +1,84 @@ +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) + diff --git a/src/pfwbged/basecontent/browser/configure.zcml b/src/pfwbged/basecontent/browser/configure.zcml index f5db60d..a29921e 100644 --- a/src/pfwbged/basecontent/browser/configure.zcml +++ b/src/pfwbged/basecontent/browser/configure.zcml @@ -63,4 +63,12 @@ image="pfwb.medicalcertificate_icon.png" /> + + + diff --git a/src/pfwbged/basecontent/profiles/default/types/dmsmainfile.xml b/src/pfwbged/basecontent/profiles/default/types/dmsmainfile.xml new file mode 100644 index 0000000..ad9c921 --- /dev/null +++ b/src/pfwbged/basecontent/profiles/default/types/dmsmainfile.xml @@ -0,0 +1,5 @@ + + + string:${folder_url}/adddmsmainfile +