76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
import logging
|
|
|
|
from zope.component import getUtility
|
|
from zope.component import getMultiAdapter
|
|
from zope.publisher.browser import BrowserView
|
|
|
|
from plone.resource.utils import queryResourceDirectory
|
|
|
|
from plone.registry.interfaces import IRegistry
|
|
|
|
from tabellio.config.interfaces import _
|
|
from tabellio.config.interfaces import ITabellioSettings
|
|
|
|
from AccessControl import Unauthorized
|
|
from Products.CMFCore.utils import getToolByName
|
|
from Products.Five.browser.decode import processInputs
|
|
from Products.statusmessages.interfaces import IStatusMessage
|
|
|
|
logger = logging.getLogger('tabellio.config')
|
|
|
|
class TabellioControlpanel(BrowserView):
|
|
|
|
def __call__(self):
|
|
if self.update():
|
|
return self.index()
|
|
return ''
|
|
|
|
def _setup(self):
|
|
self.settings = getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
def update(self):
|
|
processInputs(self.request)
|
|
self._setup()
|
|
self.errors = {}
|
|
submitted = False
|
|
form = self.request.form
|
|
|
|
if 'form.button.Cancel' in form:
|
|
self.redirect(_(u"Changes canceled."))
|
|
return False
|
|
|
|
if 'form.button.LocationsSave' in form:
|
|
self.authorize()
|
|
submitted = True
|
|
|
|
deputies_path = form.get('deputiesPath')
|
|
ministries_path = form.get('ministriesPath')
|
|
documents_path = form.get('documentsPath')
|
|
dossiers_path = form.get('dossiersPath')
|
|
polgroups_path = form.get('polgroupsPath')
|
|
|
|
if not self.errors:
|
|
self.settings.deputiesPath = deputies_path
|
|
self.settings.ministriesPath = ministries_path
|
|
self.settings.documentsPath = documents_path
|
|
self.settings.dossiersPath = dossiers_path
|
|
self.settings.polgroupsPath = polgroups_path
|
|
|
|
if submitted and not self.errors:
|
|
self._setup()
|
|
IStatusMessage(self.request).add(_(u"Changes saved"))
|
|
elif submitted:
|
|
IStatusMessage(self.request).add(_(u"There were errors"), 'error')
|
|
|
|
return True
|
|
|
|
def authorize(self):
|
|
authenticator = getMultiAdapter((self.context, self.request), name=u"authenticator")
|
|
if not authenticator.verify():
|
|
raise Unauthorized
|
|
|
|
def redirect(self, message):
|
|
IStatusMessage(self.request).add(message)
|
|
portalUrl = getToolByName(self.context, 'portal_url')()
|
|
self.request.response.redirect("%s/plone_control_panel" % portalUrl)
|