Back to index

plone3  3.1.7
form.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 from zope.component import getMultiAdapter
00003 from zope.event import notify
00004 
00005 from plone.fieldsets.form import FieldsetsEditForm
00006 from zope.formlib import form
00007 
00008 from Products.CMFPlone import PloneMessageFactory as _
00009 from Products.Five.browser import BrowserView
00010 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00011 from Products.statusmessages.interfaces import IStatusMessage
00012 
00013 from plone.app.form import named_template_adapter
00014 from plone.app.form.validators import null_validator
00015 
00016 from plone.app.controlpanel.events import ConfigurationChangedEvent
00017 from plone.app.controlpanel.interfaces import IPloneControlPanelView
00018 from plone.app.controlpanel.interfaces import IPloneControlPanelForm
00019 
00020 from plone.protect import CheckAuthenticator
00021 
00022 
00023 class ControlPanelView(BrowserView):
00024     """A simple view to be used as a basis for control panel screens."""
00025 
00026     implements(IPloneControlPanelView)
00027 
00028 
00029 class ControlPanelForm(FieldsetsEditForm):
00030     """A simple form to be used as a basis for control panel screens."""
00031 
00032     implements(IPloneControlPanelForm)
00033 
00034     @form.action(_(u'label_save', default=u'Save'), name=u'save')
00035     def handle_edit_action(self, action, data):
00036         CheckAuthenticator(self.request)
00037         if form.applyChanges(self.context, self.form_fields, data,
00038                              self.adapters):
00039             self.status = _("Changes saved.")
00040             notify(ConfigurationChangedEvent(self, data))
00041             self._on_save(data)
00042         else:
00043             self.status = _("No changes made.")
00044 
00045     @form.action(_(u'label_cancel', default=u'Cancel'),
00046                  validator=null_validator,
00047                  name=u'cancel')
00048     def handle_cancel_action(self, action, data):
00049         IStatusMessage(self.request).addStatusMessage(_("Changes canceled."),
00050                                                       type="info")
00051         url = getMultiAdapter((self.context, self.request),
00052                               name='absolute_url')()
00053         self.request.response.redirect(url + '/plone_control_panel')
00054         return ''
00055         
00056     def _on_save(self, data=None):
00057         pass
00058 
00059 _template = ViewPageTemplateFile('control-panel.pt')
00060 controlpanel_named_template_adapter = named_template_adapter(_template)