Skip to content

Commit

Permalink
Fix soft dependency on formlib
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
ale-rt committed Apr 8, 2019
1 parent fdd68a3 commit 5db3315
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
22 changes: 18 additions & 4 deletions collective/auditlog/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from zope.component import adapter
from zope.component import getUtility
from zope.component.hooks import getSite
from zope.formlib import form
from zope.globalrequest import getRequest
from zope.interface import implementer
from zope.interface import Interface
Expand All @@ -48,6 +47,15 @@
class IPloneFormGenField(Interface):
pass

try:
# Plone4 only (formlib)
from zope.formlib import form
HAS_FORMLIB = True
except ImportError:
form = None
HAS_FORMLIB = False # Plone 5 will use z3c.form


logger = logging.getLogger('collective.auditlog')


Expand Down Expand Up @@ -300,18 +308,24 @@ def __call__(self):


class AuditAddForm(AddForm):
form_fields = form.FormFields(IAuditAction) # needed for Plone4 (formlib)

# Plone4 only
form_fields = form.FormFields(IAuditAction) if HAS_FORMLIB else []
schema = IAuditAction # needed for Plone5 (z3c.form)
label = u"Add Audit Action"
form_name = u"Configure element"

def create(self, data):
a = AuditAction()
form.applyChanges(a, self.form_fields, data)
HAS_FORMLIB and form.applyChanges(a, self.form_fields, data)
return a


class AuditEditForm(EditForm):
form_fields = form.FormFields(IAuditAction)

# Plone4 only
form_fields = form.FormFields(IAuditAction) if HAS_FORMLIB else []
schema = IAuditAction # needed for Plone5 (z3c.form)

label = u"Edit Audit Action"
form_name = u"Configure element"
3 changes: 2 additions & 1 deletion docs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
1.4.0a3 (unreleased)
--------------------

- Nothing changed yet.
- Fix soft dependency on formlib (#22)
[ale-rt]


1.4.0a2 (2018-10-11)
Expand Down

0 comments on commit 5db3315

Please sign in to comment.