Skip to content

Commit

Permalink
start move to z3c.form
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem authored and gforcada committed May 31, 2015
1 parent 71dfaee commit ab50833
Show file tree
Hide file tree
Showing 25 changed files with 286 additions and 251 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
4.0.5 (unreleased)
------------------

- Nothing changed yet.
- Move to z3c.form


4.0.4 (2015-05-30)
Expand Down
4 changes: 2 additions & 2 deletions plone/app/contentrules/actions/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
<browser:page
for="plone.app.contentrules.browser.interfaces.IRuleActionAdding"
name="plone.actions.Copy"
class=".copy.CopyAddForm"
class=".copy.CopyAddFormView"
permission="plone.app.contentrules.ManageContentRules"
/>

<browser:page
for="plone.app.contentrules.actions.copy.ICopyAction"
name="edit"
class=".copy.CopyEditForm"
class=".copy.CopyEditFormView"
permission="plone.app.contentrules.ManageContentRules"
/>

Expand Down
28 changes: 16 additions & 12 deletions plone/app/contentrules/actions/copy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData
from plone.app.form.widgets.uberselectionwidget import UberSelectionWidget
from plone.app.vocabularies.catalog import SearchableTextSourceBinder
from plone.app.vocabularies.catalog import CatalogSource
from zope.component import adapts
from zope.event import notify
from zope.formlib import form
from z3c.form import form
from zope.interface import implements, Interface
from zope.lifecycleevent import ObjectCopiedEvent
from zope import schema
Expand All @@ -19,6 +18,7 @@

from plone.app.contentrules import PloneMessageFactory as _
from plone.app.contentrules.browser.formhelper import AddForm, EditForm
from plone.app.contentrules.browser.formhelper import ContentRuleFormWrapper


class ICopyAction(Interface):
Expand All @@ -30,8 +30,7 @@ class ICopyAction(Interface):
target_folder = schema.Choice(title=_(u"Target folder"),
description=_(u"As a path relative to the portal root."),
required=True,
source=SearchableTextSourceBinder({'is_folderish': True},
default_query='path:'))
source=CatalogSource(is_folderish=True))


class CopyAction(SimpleItem):
Expand Down Expand Up @@ -109,7 +108,7 @@ def error(self, obj, error):
if request is not None:
title = utils.pretty_title_or_id(obj, obj)
message = _(u"Unable to copy ${name} as part of content rule 'copy' action: ${error}",
mapping={'name': title, 'error': error})
mapping={'name': title, 'error': error})
IStatusMessage(request).addStatusMessage(message, type="error")

def generate_id(self, target, old_id):
Expand All @@ -128,25 +127,30 @@ def generate_id(self, target, old_id):
class CopyAddForm(AddForm):
"""An add form for move-to-folder actions.
"""
form_fields = form.FormFields(ICopyAction)
form_fields['target_folder'].custom_widget = UberSelectionWidget
schema = ICopyAction
label = _(u"Add Copy Action")
description = _(u"A copy action can copy an object to a different folder.")
form_name = _(u"Configure element")

def create(self, data):
a = CopyAction()
form.applyChanges(a, self.form_fields, data)
form.applyChanges(self, a, data)
return a


class CopyAddFormView(ContentRuleFormWrapper):
form = CopyAddForm


class CopyEditForm(EditForm):
"""An edit form for copy rule actions.
Formlib does all the magic here.
"""
form_fields = form.FormFields(ICopyAction)
form_fields['target_folder'].custom_widget = UberSelectionWidget
schema = ICopyAction
label = _(u"Edit Copy Action")
description = _(u"A copy action can copy an object to a different folder.")
form_name = _(u"Configure element")


class CopyEditFormView(ContentRuleFormWrapper):
form = CopyEditForm
21 changes: 11 additions & 10 deletions plone/app/contentrules/actions/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from zope.component import adapts
from zope.component.interfaces import IObjectEvent
from zope.formlib import form
from z3c.form import form
from zope.interface import implements, Interface
from zope import schema

Expand Down Expand Up @@ -33,11 +33,12 @@ class ILoggerAction(Interface):
loggingLevel = schema.Int(title=_(u'Logging level'),
default=20) # INFO

message = schema.TextLine(title=_(u"Message"),
description=_('help_contentrules_logger_message',
default=u"&e = the triggering event, &c = the context, &u = the user"),
default=_('text_contentrules_logger_message',
default=u"Caught &e at &c by &u"))
message = schema.TextLine(
title=_(u"Message"),
description=_('help_contentrules_logger_message',
default=u"&e = the triggering event, &c = the context, &u = the user"),
default=_('text_contentrules_logger_message',
default=u"Caught &e at &c by &u"))


class LoggerAction(SimpleItem):
Expand Down Expand Up @@ -75,7 +76,7 @@ def processedMessage(self):
processedMessage = self.element.message
if "&e" in processedMessage:
processedMessage = processedMessage.replace("&e", "%s.%s" % (
self.event.__class__.__module__, self.event.__class__.__name__))
self.event.__class__.__module__, self.event.__class__.__name__))

if "&c" in processedMessage and IObjectEvent.providedBy(self.event):
processedMessage = processedMessage.replace("&c", repr(self.event.object))
Expand All @@ -96,14 +97,14 @@ def __call__(self):
class LoggerAddForm(AddForm):
"""An add form for logger rule actions.
"""
form_fields = form.FormFields(ILoggerAction)
schema = ILoggerAction
label = _(u"Add Logger Action")
description = _(u"A logger action can output a message to the system log.")
form_name = _(u"Configure element")

def create(self, data):
a = LoggerAction()
form.applyChanges(a, self.form_fields, data)
form.applyChanges(self, a, data)
return a


Expand All @@ -112,7 +113,7 @@ class LoggerEditForm(EditForm):
Formlib does all the magic here.
"""
form_fields = form.FormFields(ILoggerAction)
schema = ILoggerAction
label = _(u"Edit Logger Action")
description = _(u"A logger action can output a message to the system log.")
form_name = _(u"Configure element")
27 changes: 13 additions & 14 deletions plone/app/contentrules/actions/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from zope.component import adapts
from zope.component import getUtility
from zope.component.interfaces import ComponentLookupError
from zope.formlib import form
from z3c.form import form
from zope.interface import Interface, implements
from zope import schema
from zope.globalrequest import getRequest
Expand Down Expand Up @@ -38,12 +38,13 @@ class IMailAction(Interface):
"email. If no email is provided here, "
"it will use the portal from address."),
required=False)
recipients = schema.TextLine(title=_(u"Email recipients"),
description=_("The email where you want to "
"send this message. To send it to "
"different email addresses, "
"just separate them with ,"),
required=True)
recipients = schema.TextLine(
title=_(u"Email recipients"),
description=_("The email where you want to "
"send this message. To send it to "
"different email addresses, "
"just separate them with ,"),
required=True)
exclude_actor = schema.Bool(title=_(u"Exclude actor from recipients"),
description=_("Do not send the email to the user "
"that did the action."))
Expand Down Expand Up @@ -86,12 +87,10 @@ def __init__(self, context, element, event):
self.mail_settings = registry.forInterface(IMailSchema,
prefix='plone')


def __call__(self):
mailhost = getToolByName(aq_inner(self.context), "MailHost")
if not mailhost:
raise ComponentLookupError, "You must have a Mailhost utility to \
execute this action"
raise ComponentLookupError("You must have a Mailhost utility to execute this action")

urltool = getToolByName(aq_inner(self.context), "portal_url")
portal = urltool.getPortalObject()
Expand Down Expand Up @@ -125,7 +124,7 @@ def __call__(self):

recip_string = interpolator(self.element.recipients)
if recip_string: # check recipient is not None or empty string
recipients = set([str(mail.strip()) for mail in recip_string.split(',') \
recipients = set([str(mail.strip()) for mail in recip_string.split(',')
if mail.strip()])
else:
recipients = set()
Expand Down Expand Up @@ -165,7 +164,7 @@ class MailAddForm(AddForm):
"""
An add form for the mail action
"""
form_fields = form.FormFields(IMailAction)
schema = IMailAction
label = _(u"Add Mail Action")
description = _(u"A mail action can mail different recipient.")
form_name = _(u"Configure element")
Expand All @@ -175,15 +174,15 @@ class MailAddForm(AddForm):

def create(self, data):
a = MailAction()
form.applyChanges(a, self.form_fields, data)
form.applyChanges(self, a, data)
return a


class MailEditForm(EditForm):
"""
An edit form for the mail action
"""
form_fields = form.FormFields(IMailAction)
schema = IMailAction
label = _(u"Edit Mail Action")
description = _(u"A mail action can mail different recipient.")
form_name = _(u"Configure element")
Expand Down
18 changes: 7 additions & 11 deletions plone/app/contentrules/actions/move.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData
from plone.app.form.widgets.uberselectionwidget import UberSelectionWidget
from plone.app.vocabularies.catalog import SearchableTextSourceBinder
from plone.app.vocabularies.catalog import CatalogSource
from zope.component import adapts
from zope.container.contained import notifyContainerModified
from zope.event import notify
from zope.formlib import form
from z3c.form import form
from zope.interface import implements, Interface
from zope.lifecycleevent import ObjectMovedEvent
from zope import schema
Expand All @@ -31,8 +30,7 @@ class IMoveAction(Interface):
target_folder = schema.Choice(title=_(u"Target folder"),
description=_(u"As a path relative to the portal root."),
required=True,
source=SearchableTextSourceBinder({'is_folderish': True},
default_query='path:'))
source=CatalogSource(is_folderish=True))


class MoveAction(SimpleItem):
Expand Down Expand Up @@ -132,7 +130,7 @@ def error(self, obj, error):
if request is not None:
title = utils.pretty_title_or_id(obj, obj)
message = _(u"Unable to move ${name} as part of content rule 'move' action: ${error}",
mapping={'name': title, 'error': error})
mapping={'name': title, 'error': error})
IStatusMessage(request).addStatusMessage(message, type="error")

def generate_id(self, target, old_id):
Expand All @@ -151,15 +149,14 @@ def generate_id(self, target, old_id):
class MoveAddForm(AddForm):
"""An add form for move-to-folder actions.
"""
form_fields = form.FormFields(IMoveAction)
form_fields['target_folder'].custom_widget = UberSelectionWidget
schema = IMoveAction
label = _(u"Add Move Action")
description = _(u"A move action can move an object to a different folder.")
form_name = _(u"Configure element")

def create(self, data):
a = MoveAction()
form.applyChanges(a, self.form_fields, data)
form.applyChanges(self, a, data)
return a


Expand All @@ -168,8 +165,7 @@ class MoveEditForm(EditForm):
Formlib does all the magic here.
"""
form_fields = form.FormFields(IMoveAction)
form_fields['target_folder'].custom_widget = UberSelectionWidget
schema = IMoveAction
label = _(u"Edit Move Action")
description = _(u"A move action can move an object to a different folder.")
form_name = _(u"Configure element")
8 changes: 4 additions & 4 deletions plone/app/contentrules/actions/notify.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData
from zope.component import adapts
from zope.formlib import form
from z3c.form import form
from zope.interface import implements, Interface
from zope import schema

Expand Down Expand Up @@ -68,14 +68,14 @@ def __call__(self):
class NotifyAddForm(AddForm):
"""An add form for notify rule actions.
"""
form_fields = form.FormFields(INotifyAction)
schema = INotifyAction
label = _(u"Add Notify Action")
description = _(u"A notify action can show a message to the user.")
form_name = _(u"Configure element")

def create(self, data):
a = NotifyAction()
form.applyChanges(a, self.form_fields, data)
form.applyChanges(self, a, data)
return a


Expand All @@ -84,7 +84,7 @@ class NotifyEditForm(EditForm):
Formlib does all the magic here.
"""
form_fields = form.FormFields(INotifyAction)
schema = INotifyAction
label = _(u"Edit Notify Action")
description = _(u"A notify action can show a message to the user.")
form_name = _(u"Configure element")
13 changes: 7 additions & 6 deletions plone/app/contentrules/actions/workflow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData
from zope.interface import implements, Interface
from zope.component import adapts
from zope.formlib import form
from z3c.form import form
from zope import schema

from OFS.SimpleItem import SimpleItem
Expand Down Expand Up @@ -71,29 +71,30 @@ def error(self, obj, error):
request = getattr(self.context, 'REQUEST', None)
if request is not None:
title = utils.pretty_title_or_id(obj, obj)
message = _(u"Unable to change state of ${name} as part of content rule 'workflow' action: ${error}",
mapping={'name': title, 'error': error})
message = _(
u"Unable to change state of ${name} as part of content rule 'workflow' action: ${error}", # noqa
mapping={'name': title, 'error': error})
IStatusMessage(request).addStatusMessage(message, type="error")


class WorkflowAddForm(AddForm):
"""An add form for workflow actions.
"""
form_fields = form.FormFields(IWorkflowAction)
schema = IWorkflowAction
label = _(u"Add Workflow Action")
description = _(u"A workflow action triggers a workflow transition on an object.")
form_name = _(u"Configure element")

def create(self, data):
a = WorkflowAction()
form.applyChanges(a, self.form_fields, data)
form.applyChanges(self, a, data)
return a


class WorkflowEditForm(EditForm):
"""An edit form for workflow rule actions.
"""
form_fields = form.FormFields(IWorkflowAction)
schema = IWorkflowAction
label = _(u"Edit Workflow Action")
description = _(u"A workflow action triggers a workflow transition on an object.")
form_name = _(u"Configure element")
Loading

0 comments on commit ab50833

Please sign in to comment.