Skip to content
Browse files

remove use of portal properties

  • Loading branch information...
1 parent 1aec5aa commit 50d092dbb12d7a2534de75d42a7feea16fdb4761 @vangheem vangheem committed Nov 5, 2011
Showing with 17 additions and 28 deletions.
  1. +7 −7 collective/routes/__init__.py
  2. +1 −14 collective/routes/controlpanel.py
  3. +9 −7 collective/routes/tests/test_routes.py
View
14 collective/routes/__init__.py
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
-from Acquisition import aq_parent
-from DateTime import DateTime
+from collective.routes.controlpanel import IRoutesSettings
+from zope.component import getUtility
+from plone.registry.interfaces import IRegistry
+
from zope.component import adapts
-from zope.component import getMultiAdapter
from zope.i18nmessageid import MessageFactory
from zope.interface import alsoProvides
from zope.publisher.interfaces import IRequest
@@ -13,7 +14,6 @@
from Products.ZCatalog.Lazy import LazyMap
from Products.CMFCore.interfaces._content import ISiteRoot
-from Products.CMFCore.utils import getToolByName
from collective.routes.content import FragmentContext
from collective.routes.content import WrappedBrainsContext
@@ -120,9 +120,9 @@ def publishTraverse(self, request, name):
return DefaultPublishTraverse.publishTraverse(self, request, name)
except KeyError:
if ILayer.providedBy(request):
- pprops = getToolByName(self.context, 'portal_properties')
- props = pprops.routes_properties
- activated_routes = props.getProperty('activated_routes', ())
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(IRoutesSettings)
+ activated_routes = settings.routes
#path = request.environ['PATH_INFO'].split('/')
path = request.physicalPathFromURL(request['URL'])
View
15 collective/routes/controlpanel.py
@@ -1,22 +1,17 @@
# -*- encoding: utf-8 -*-
-from Acquisition import aq_inner
from five import grok
from zope import schema
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleVocabulary
from zope.interface import implements
from zope.interface import Interface
-from zope.site.hooks import getSite
-from Products.CMFCore.utils import getToolByName
from plone.app.registry.browser import controlpanel
-from plone.registry.interfaces import IRecordModifiedEvent
from z3c.form.browser.checkbox import CheckBoxFieldWidget
from collective.routes import getRoute
from collective.routes import getRouteNames
-from collective.routes import getObject
from collective.routes import _
@@ -58,6 +53,7 @@ class RoutesSettingsEditForm(controlpanel.RegistryEditForm):
label = _(u'Routes Settings')
description = _(u'Here you can modify the settings for '
'Routes.')
+
def updateFields(self):
super(RoutesSettingsEditForm, self).updateFields()
self.fields['routes'].widgetFactory = CheckBoxFieldWidget
@@ -68,12 +64,3 @@ def updateWidgets(self):
class RoutesConfiglet(controlpanel.ControlPanelFormWrapper):
form = RoutesSettingsEditForm
-
-
-@grok.subscribe(IRoutesSettings, IRecordModifiedEvent)
-def detectRoutesChange(settings, event):
- if event.record.fieldName == 'routes':
- context = aq_inner(settings)
- pprops = getToolByName(context, 'portal_properties')
- route_props = pprops.routes_properties
- route_props.activated_routes = tuple(event.newValue)
View
16 collective/routes/tests/test_routes.py
@@ -1,4 +1,6 @@
-from Products.CMFCore.utils import getToolByName
+from collective.routes.controlpanel import IRoutesSettings
+from zope.component import getUtility
+from plone.registry.interfaces import IRegistry
from zExceptions import NotFound
from collective.routes.testing import browserLogin
from collective.routes.testing import createObject
@@ -38,9 +40,9 @@ def setUp(self):
browserLogin(self.portal, self.browser)
def activateRoutes(self):
- pprops = getToolByName(self.portal, 'portal_properties')
- props = pprops.routes_properties
- props.activated_routes = ('foobar', 'foobar1', 'foobar2')
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(IRoutesSettings)
+ settings.routes = set(('foobar', 'foobar1', 'foobar2'))
def test_route_works(self):
self.browser.open(self.portal.absolute_url() + '/2010/10/10')
@@ -51,9 +53,9 @@ def test_bad_route_still_returns_a_404(self):
self.browser.open(self.portal.absolute_url() + '/foobar')
def test_not_run_if_not_activated(self):
- pprops = getToolByName(self.portal, 'portal_properties')
- props = pprops.routes_properties
- props.activated_routes = ()
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(IRoutesSettings)
+ settings.routes = set([])
transaction.commit()
with self.assertRaises(NotFound):

0 comments on commit 50d092d

Please sign in to comment.
Something went wrong with that request. Please try again.