class GlobalStatusMessageForm(form.EditForm): """This class defines the form""" schema = IStatusMessageConfigForm fields = field.Fields(IStatusMessageConfigForm) fields['message_textfield'].custom_widget = WYSIWYGWidget label = _(u"Global Statusmessage")
def handleSaveAndPublish(self, action): """ The additional button to send to a "ftw.publisher.receiver" instance. """ self.handleSave(self, action) self.send_to_receiver() # Consume Plone messages set by `handleSave` so we can set our own message. messages = IStatusMessage(self.request) if messages.show(): self.request.response.cookies.pop(STATUSMESSAGEKEY) IAnnotations(self.request)[STATUSMESSAGEKEY] = None # Set a new Plone message. api.portal.show_message( message=_(u'Changes saved and published.'), request=self.request, type='info' )
class StatusMessageEditForm(controlpanel.RegistryEditForm): schema = IStatusMessageConfigForm label = _(u'Global Status Message') description = _(u'Settings for Global Status Message.')
class PublishingStatusMessageEditForm(StatusMessageEditForm): """ A special edit form which handles the publishing of the global status message to a "ftw.publisher.receiver" instance. Please note that the buttons are rendered in the order as they are defined. """ @button.buttonAndHandler(plone_messagefactory(u"Save"), name='save') def handleSave(self, action): # Redeclare the save button because it is not inherited from the parent class. super(PublishingStatusMessageEditForm, self).handleSave(self, action) @button.buttonAndHandler(_(u'Save and publish'), name='save_and_publish') def handleSaveAndPublish(self, action): """ The additional button to send to a "ftw.publisher.receiver" instance. """ self.handleSave(self, action) self.send_to_receiver() # Consume Plone messages set by `handleSave` so we can set our own message. messages = IStatusMessage(self.request) if messages.show(): self.request.response.cookies.pop(STATUSMESSAGEKEY) IAnnotations(self.request)[STATUSMESSAGEKEY] = None # Set a new Plone message. api.portal.show_message( message=_(u'Changes saved and published.'), request=self.request, type='info' ) def updateActions(self): super(PublishingStatusMessageEditForm, self).updateActions() self.actions['save_and_publish'].addClass("context") @button.buttonAndHandler(plone_messagefactory(u'Cancel'), name='cancel') def handleCancel(self, action): # Redeclare the cancel button because it is not inherited from the parent class. super(PublishingStatusMessageEditForm, self).handleCancel(self, action) def send_to_receiver(self): data = json.dumps( decode_for_json(self.get_settings_data()) ) realms = IConfig(api.portal.get()).getRealms() for realm in realms: sendJsonToRealm( data, realm, 'global_statusmessage_config_receiver' ) def get_settings_data(self): registry = getUtility(IRegistry) settings = registry.forInterface(IStatusMessageConfigForm, check=False) data = { field_name: getattr(settings, field_name) for field_name in getFieldNames(IStatusMessageConfigForm) } return data
class IStatusMessageConfigForm(model.Schema): """ This interface defines the configlet. """ enabled_bool = schema.Bool(title=_(u"statusmessage_label_Active", default=u"Active"), required=False) enabled_anonymous_bool = schema.Bool( title=_(u"statusmessage_label_anonymous", default=u"Show to anonymous users?"), default=True, # for backward compatibility required=False) enabled_automatic_bool = schema.Bool(title=_( u"statusmessage_label_automatic", default=u"Allow automatic activation?"), default=False, required=False) show_on_login_bool = schema.Bool(title=_( u"statusmessage_label_show_on_login", default=u"Show on login form?"), default=False, required=False) type_choice = schema.Choice( title=_(u"statusmessage_label_type", default=u"Type"), values=[_(u"information"), _(u"warning"), _(u"error")], required=False) title_textfield = schema.TextLine(title=_(u"statusmessage_label_title", default=u"Title"), required=False) message_textfield = schema.Text(title=_(u"statusmessage_label_message", default=u"Message"), required=False) exclude_sites = schema.List( title=_(u'statusmessage_label_exclude_sites', default=u'Exclude sites'), description=_(u'statusmessage_help_exclude_sites', default=u'The message will not be shown on any content' u' within containers which are selected here.' u' If however a container is selected but a selectable' u' sub container is not selected, contents within the' u' the sub container will display the message.'), required=False, value_type=schema.Choice( vocabulary='ftw.globalstatusmessage:sites_vocabulary'))