From 4841a337d38589b54bfc0fa712dea5fcc1763539 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Wed, 9 Mar 2016 16:09:31 +0100 Subject: [PATCH 1/3] Overview control panel url from context Let the RegistryEditForm construct the base url to the @@overview-controlpanel from the context URL instead the portal URL. This gives more flexibility when calling controlpanels on contexts with local registries while in standard Plone installations the controlpanel is still bound to the portal url. --- CHANGES.rst | 4 ++- plone/app/registry/browser/controlpanel.py | 12 ++++++--- .../registry/browser/controlpanel_layout.pt | 2 +- plone/app/registry/tests/test_controlpanel.py | 27 +++++++++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 plone/app/registry/tests/test_controlpanel.py diff --git a/CHANGES.rst b/CHANGES.rst index 2d009b0..bda635c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,7 +10,9 @@ Incompatibilities: New: -- *add item here* +- Let the ``RegistryEditForm`` construct the base url to the ``@@overview-controlpanel`` from the context URL instead the portal URL. + This gives more flexibility when calling controlpanels on contexts with local registries while in standard Plone installations the controlpanel is still bound to the portal url. + [thet] Fixes: diff --git a/plone/app/registry/browser/controlpanel.py b/plone/app/registry/browser/controlpanel.py index dc9b4b1..45f7149 100644 --- a/plone/app/registry/browser/controlpanel.py +++ b/plone/app/registry/browser/controlpanel.py @@ -69,14 +69,20 @@ def handleCancel(self, action): IStatusMessage(self.request).addStatusMessage( _(u"Changes canceled."), "info") - self.request.response.redirect("%s/%s" % ( + self.request.response.redirect(u"{0}/{1}".format( self.context.absolute_url(), - self.control_panel_view)) + self.control_panel_view + )) class ControlPanelFormWrapper(layout.FormWrapper): """Use this form as the plone.z3cform layout wrapper to get the control panel layout. """ - index = ViewPageTemplateFile('controlpanel_layout.pt') + + @property + def control_panel_url(self): + return u"{0}/@@overview-controlpanel".format( + self.context.absolute_url() + ) diff --git a/plone/app/registry/browser/controlpanel_layout.pt b/plone/app/registry/browser/controlpanel_layout.pt index 9fa9886..1dadb1f 100644 --- a/plone/app/registry/browser/controlpanel_layout.pt +++ b/plone/app/registry/browser/controlpanel_layout.pt @@ -10,7 +10,7 @@
Site Setup diff --git a/plone/app/registry/tests/test_controlpanel.py b/plone/app/registry/tests/test_controlpanel.py new file mode 100644 index 0000000..6026c9c --- /dev/null +++ b/plone/app/registry/tests/test_controlpanel.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +from plone.app.registry.browser.controlpanel import ControlPanelFormWrapper +from plone.app.registry.testing import PLONE_APP_REGISTRY_INTEGRATION_TESTING + +import types +import unittest2 as unittest + + +class TestRegistryBaseControlpanel(unittest.TestCase): + + layer = PLONE_APP_REGISTRY_INTEGRATION_TESTING + + def test_registry_base_controlpanel__control_panel_url(self): + """Test, if control_panel_url property of the base controlpanel returns + the correct url. + """ + # Mock context + context = type('Dummy', (object,), {}) + context.absolute_url = types.MethodType( + lambda self: 'http://nohost/noportal/nocontext', + context + ) + view = ControlPanelFormWrapper(context, None) + self.assertEqual( + view.control_panel_url, + u'http://nohost/noportal/nocontext/@@overview-controlpanel' + ) From 8747e4b1650f94418249e6e27fa4c500a3d57a6c Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Wed, 9 Mar 2016 17:07:22 +0100 Subject: [PATCH 2/3] For the @@configuration_registry, construct the base url to the @@overview-controlpanel from the nearest site. --- CHANGES.rst | 3 ++- plone/app/registry/browser/records.pt | 4 ++-- plone/app/registry/browser/records.py | 7 +++++++ plone/app/registry/tests/test_controlpanel.py | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index bda635c..4be0530 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,7 +10,8 @@ Incompatibilities: New: -- Let the ``RegistryEditForm`` construct the base url to the ``@@overview-controlpanel`` from the context URL instead the portal URL. +- Let the ``ControlPanelFormWrapper`` construct the base url to the ``@@overview-controlpanel`` from the context URL instead the portal URL. + For the ``@@configuration_registry``, construct the base url to the ``@@overview-controlpanel`` from the nearest site. This gives more flexibility when calling controlpanels on contexts with local registries while in standard Plone installations the controlpanel is still bound to the portal url. [thet] diff --git a/plone/app/registry/browser/records.pt b/plone/app/registry/browser/records.pt index d683ca9..a4c24c3 100644 --- a/plone/app/registry/browser/records.pt +++ b/plone/app/registry/browser/records.pt @@ -19,9 +19,9 @@ tal:define="records view/records"> - Site Setup + Site Setup

Configuration Registry

diff --git a/plone/app/registry/browser/records.py b/plone/app/registry/browser/records.py index feb8017..f817de9 100644 --- a/plone/app/registry/browser/records.py +++ b/plone/app/registry/browser/records.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from Products.CMFPlone.PloneBatch import Batch from Products.Five import BrowserView +from zope.component.hooks import getSite def _true(s, v): @@ -23,6 +24,12 @@ def _starts_with(s, v): class RecordsControlPanel(BrowserView): + @property + def control_panel_url(self): + return u"{0}/@@overview-controlpanel".format( + getSite().absolute_url() + ) + def __call__(self): form = self.request.form search = form.get('q') diff --git a/plone/app/registry/tests/test_controlpanel.py b/plone/app/registry/tests/test_controlpanel.py index 6026c9c..f84823e 100644 --- a/plone/app/registry/tests/test_controlpanel.py +++ b/plone/app/registry/tests/test_controlpanel.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from plone.app.registry.browser.controlpanel import ControlPanelFormWrapper +from plone.app.registry.browser.records import RecordsControlPanel from plone.app.registry.testing import PLONE_APP_REGISTRY_INTEGRATION_TESTING import types @@ -25,3 +26,18 @@ def test_registry_base_controlpanel__control_panel_url(self): view.control_panel_url, u'http://nohost/noportal/nocontext/@@overview-controlpanel' ) + + +class TestRecordsControlPanel(unittest.TestCase): + + layer = PLONE_APP_REGISTRY_INTEGRATION_TESTING + + def test_records_control_panel__control_panel_url(self): + """Test, if control_panel_url property of the registry controlpanel + returns the correct url. + """ + view = RecordsControlPanel(None, None) + self.assertEqual( + view.control_panel_url, + u'http://nohost/plone/@@overview-controlpanel' + ) From de6c4c65bc4649be8d7191cfe6ed0338c87968ba Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Fri, 11 Mar 2016 12:51:49 +0100 Subject: [PATCH 3/3] Consistency: For ``ControlPanelFormWrapper`` and ``@@configuration_registry``, construct the base url to the ``@@overview-controlpanel`` from the nearest site. --- CHANGES.rst | 5 ++--- plone/app/registry/browser/controlpanel.py | 8 ++++---- plone/app/registry/browser/records.py | 4 +--- plone/app/registry/tests/test_controlpanel.py | 10 ++-------- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4be0530..5e432f8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,9 +10,8 @@ Incompatibilities: New: -- Let the ``ControlPanelFormWrapper`` construct the base url to the ``@@overview-controlpanel`` from the context URL instead the portal URL. - For the ``@@configuration_registry``, construct the base url to the ``@@overview-controlpanel`` from the nearest site. - This gives more flexibility when calling controlpanels on contexts with local registries while in standard Plone installations the controlpanel is still bound to the portal url. +- For ``ControlPanelFormWrapper`` and ``@@configuration_registry``, construct the base url to the ``@@overview-controlpanel`` from the nearest site. + This gives more flexibility when calling controlpanels on sub sites with local registries while in standard Plone installations the controlpanel is still bound to the portal url. [thet] Fixes: diff --git a/plone/app/registry/browser/controlpanel.py b/plone/app/registry/browser/controlpanel.py index 45f7149..fe2eeda 100644 --- a/plone/app/registry/browser/controlpanel.py +++ b/plone/app/registry/browser/controlpanel.py @@ -10,7 +10,9 @@ from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.statusmessages.interfaces import IStatusMessage +from zope.component.hooks import getSite from zope.i18nmessageid import MessageFactory + _ = MessageFactory('plone') @@ -70,7 +72,7 @@ def handleCancel(self, action): _(u"Changes canceled."), "info") self.request.response.redirect(u"{0}/{1}".format( - self.context.absolute_url(), + getSite().absolute_url(), self.control_panel_view )) @@ -83,6 +85,4 @@ class ControlPanelFormWrapper(layout.FormWrapper): @property def control_panel_url(self): - return u"{0}/@@overview-controlpanel".format( - self.context.absolute_url() - ) + return u"{0}/@@overview-controlpanel".format(getSite().absolute_url()) diff --git a/plone/app/registry/browser/records.py b/plone/app/registry/browser/records.py index f817de9..30aa17d 100644 --- a/plone/app/registry/browser/records.py +++ b/plone/app/registry/browser/records.py @@ -26,9 +26,7 @@ class RecordsControlPanel(BrowserView): @property def control_panel_url(self): - return u"{0}/@@overview-controlpanel".format( - getSite().absolute_url() - ) + return u"{0}/@@overview-controlpanel".format(getSite().absolute_url()) def __call__(self): form = self.request.form diff --git a/plone/app/registry/tests/test_controlpanel.py b/plone/app/registry/tests/test_controlpanel.py index f84823e..f475575 100644 --- a/plone/app/registry/tests/test_controlpanel.py +++ b/plone/app/registry/tests/test_controlpanel.py @@ -15,16 +15,10 @@ def test_registry_base_controlpanel__control_panel_url(self): """Test, if control_panel_url property of the base controlpanel returns the correct url. """ - # Mock context - context = type('Dummy', (object,), {}) - context.absolute_url = types.MethodType( - lambda self: 'http://nohost/noportal/nocontext', - context - ) - view = ControlPanelFormWrapper(context, None) + view = ControlPanelFormWrapper(None, None) self.assertEqual( view.control_panel_url, - u'http://nohost/noportal/nocontext/@@overview-controlpanel' + u'http://nohost/plone/@@overview-controlpanel' )