Skip to content

Commit

Permalink
Merge pull request #36 from plone/tg_individual_flag
Browse files Browse the repository at this point in the history
Add field for enabling/disabling versioning per content item
  • Loading branch information
jensens authored Mar 18, 2018
2 parents 85de56c + 47c1d7f commit f93811e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
7 changes: 5 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ Breaking changes:

New features:

- *add item here*
- Add a field for disabling versions per content item
https://github.com/plone/Products.CMFPlone/issues/2341
[tomgross]

Bug fixes:

- *add item here*
- Remove obsolete grok usage
[tomgross]


1.3.2 (2018-02-02)
Expand Down
26 changes: 24 additions & 2 deletions plone/app/versioningbehavior/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from z3c.form.interfaces import IEditForm
from zope import schema
from zope.annotation.interfaces import IAnnotations
from zope.component import adapts
from zope.component import adapter
from zope.interface import alsoProvides
from zope.interface import implementer
from zope.interface import Interface
Expand All @@ -20,6 +20,11 @@ class IVersionable(model.Schema):
control-panel for your content type.
"""

model.fieldset(
'settings',
label=_(u'Settings'),
fields=['versioning_enabled']
)
changeNote = schema.TextLine(
title=_(u'label_change_note', default=u'Change Note'),
description=_(u'help_change_note',
Expand All @@ -28,6 +33,13 @@ class IVersionable(model.Schema):
u'to create the new version.'),
required=False)

versioning_enabled = schema.Bool(
title=_(u'label_versioning_enabled', default=u'Versioning enabled'),
description=_(u'help_versioning_enabled',
default=u'Enable/disable versioning for this document.'),
default=True,
required=False)

form.omitted('changeNote')
form.no_omit(IEditForm, 'changeNote')
form.no_omit(IAddForm, 'changeNote')
Expand All @@ -42,12 +54,14 @@ class IVersioningSupport(Interface):


@implementer(IVersionable)
@adapter(IDexterityContent)
class Versionable(object):
""" The Versionable adapter prohibits dexterity from saving the changeNote
on the context. It stores it in a request-annotation for later use in
event-handlers
The versioning_enabled flag is stored at the context itself.
"""
adapts(IDexterityContent)

def __init__(self, context):
self.context = context
Expand All @@ -61,3 +75,11 @@ def changeNote(self, value):
# store the value for later use (see events.py)
annotation = IAnnotations(self.context.REQUEST)
annotation['plone.app.versioningbehavior-changeNote'] = value

@property
def versioning_enabled(self):
return self.context.versioning_enabled

@versioning_enabled.setter
def versioning_enabled(self, value):
setattr(self.context, 'versioning_enabled', value)
10 changes: 1 addition & 9 deletions plone/app/versioningbehavior/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone">

<include package="zope.security" />
<include package="plone.behavior" file="meta.zcml" />

<include package="plone.rfc822" />
Expand All @@ -18,15 +19,6 @@

<include package="plone.app.dexterity" />

<!-- Dexterity 1.x uses grok / martian based directive.
Newer dexterity versions do not use grok anymore.
For supporting the old versions we grok the package if
grok is installed. /-->
<configure zcml:condition="installed five.grok">
<include package="five.grok" />
<grok:grok package="." />
</configure>

<plone:behavior
name="plone.versioning"
title="Versioning"
Expand Down

0 comments on commit f93811e

Please sign in to comment.