Skip to content

Commit

Permalink
Merge pull request #17 from plone/thet-control-panel-url
Browse files Browse the repository at this point in the history
Overview control panel url from context
  • Loading branch information
jensens committed Mar 14, 2016
2 parents 07a1765 + de6c4c6 commit 8ead847
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Incompatibilities:

New:

- *add item here*
- 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:

Expand Down
14 changes: 10 additions & 4 deletions plone/app/registry/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand Down Expand Up @@ -69,14 +71,18 @@ def handleCancel(self, action):
IStatusMessage(self.request).addStatusMessage(
_(u"Changes canceled."),
"info")
self.request.response.redirect("%s/%s" % (
self.context.absolute_url(),
self.control_panel_view))
self.request.response.redirect(u"{0}/{1}".format(
getSite().absolute_url(),
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(getSite().absolute_url())
2 changes: 1 addition & 1 deletion plone/app/registry/browser/controlpanel_layout.pt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div metal:fill-slot="prefs_configlet_main">

<a id="setup-link" class="link-parent"
tal:attributes="href string:$portal_url/@@overview-controlpanel"
tal:attributes="href view/control_panel_url"
i18n:translate="">
Site Setup
</a>
Expand Down
4 changes: 2 additions & 2 deletions plone/app/registry/browser/records.pt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
tal:define="records view/records">

<a id="setup-link" class="link-parent"
tal:attributes="href string:$portal_url/@@overview-controlpanel"
tal:attributes="href view/control_panel_url"
i18n:translate="">
Site Setup
Site Setup
</a>

<h1 class="documentFirstHeading" i18n:translate="heading_registry">Configuration Registry</h1>
Expand Down
5 changes: 5 additions & 0 deletions plone/app/registry/browser/records.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -23,6 +24,10 @@ 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')
Expand Down
37 changes: 37 additions & 0 deletions plone/app/registry/tests/test_controlpanel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- 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
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.
"""
view = ControlPanelFormWrapper(None, None)
self.assertEqual(
view.control_panel_url,
u'http://nohost/plone/@@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'
)

0 comments on commit 8ead847

Please sign in to comment.