Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Various Changes #1

Merged
merged 7 commits into from over 1 year ago

2 participants

Timon Tschanz Jonas Baumann
Timon Tschanz
Collaborator

@jone Could you take a look at this? The Branch changes this things:

  • Show title & editbar
  • Don't show inherited portlets
  • Hide Plone languageselector
  • Fix and add additional Tests
Timon Tschanz
Collaborator

:+1:

ftw/subsite/handlers.py
... ... @@ -0,0 +1,27 @@
  1 +from plone.portlets.constants import CONTEXT_CATEGORY
  2 +from plone.portlets.interfaces import ILocalPortletAssignmentManager
  3 +from plone.portlets.interfaces import IPortletManager
  4 +from zope.component import getUtility, getMultiAdapter
  5 +from zope.component.interfaces import ComponentLookupError
  6 +
  7 +def remove_parent_portlets(object_, event):
1
Jonas Baumann Owner
jone added a note

block_parent_portlets instead of remove_parent_portlets would be more descriptive, I think..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ftw/subsite/tests/test_subsiteview.py
@@ -65,3 +51,27 @@ def test_manageview_render(self):
65 51 self.browser.open(self.subsite.absolute_url() + '/manage-subsiteview')
66 52 for item in range(1, 6):
67 53 self.assertIn('<div id="subsite-column-%s" class="column">' % str(item), self.browser.contents)
  54 +
  55 + def test_view_authorized(self):
  56 + self._auth()
  57 + self.browser.open(self.subsite.absolute_url())
  58 + self.assertIn(' <h1 id="parent-fieldname-title" class="documentFirstHeading', self.browser.contents)
  59 + self.assertIn('<div class="contentActions">', self.browser.contents)
  60 +
  61 + def test_view_anonymous(self):
  62 + self.browser.open(self.subsite.absolute_url())
  63 + self.assertNotIn(' <h1 id="parent-fieldname-title" class="documentFirstHeading', self.browser.contents)
1
Jonas Baumann Owner
jone added a note

Are those leading spaces (see also test_view_authorized) by intention? This would not match </div><h1> - but maybe it should?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Jonas Baumann jone merged commit 504709b into from
Jonas Baumann jone closed this
Jonas Baumann jone deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
6 ftw/subsite/browser/subsiteview.pt
@@ -14,11 +14,15 @@
14 14 <div id="edit-bar">
15 15
16 16
17   -
18 17 <h5 class="hiddenStructure">Ansichten</h5>
19 18
20 19 <div tal:replace="structure provider:plone.contentviews" />
21 20 </div>
  21 + <tal:title tal:condition="python: not view.is_anon()">
  22 + <div tal:replace="structure provider:plone.abovecontenttitle" />
  23 + <h1 metal:use-macro="context/kss_generic_macros/macros/generic_title_view" />
  24 + <div tal:replace="structure provider:plone.belowcontenttitle" />
  25 + </tal:title>
22 26 <h1 i18n:translate="" class="hiddenStructure">Choose your Section</h1>
23 27 <dl tal:condition="view/empty"
24 28 class="portalMessage info visualClear" id="dashboard-info-message">
7 ftw/subsite/browser/subsiteview.py
@@ -2,7 +2,7 @@
2 2 from zope.publisher.browser import BrowserView
3 3 from plone.portlets.interfaces import IPortletManager
4 4 from plone.memoize.instance import memoize
5   -
  5 +from Products.CMFCore.utils import getToolByName
6 6
7 7 class SubsiteView(BrowserView):
8 8
@@ -20,3 +20,8 @@ def empty(self):
20 20 for dashboard in dashboards:
21 21 num_portlets += len(dashboard)
22 22 return num_portlets == 0
  23 +
  24 + def is_anon(self):
  25 + member_tool = getToolByName(self, 'portal_membership')
  26 + isAnon = member_tool.isAnonymousUser()
  27 + return isAnon
5 ftw/subsite/configure.zcml
@@ -27,6 +27,11 @@
27 27 provides="Products.GenericSetup.interfaces.EXTENSION"
28 28 />
29 29
  30 + <subscriber
  31 + for=".interfaces.ISubsite
  32 + Products.Archetypes.interfaces.IObjectInitializedEvent"
  33 + handler=".handlers.block_parent_portlets" />
  34 +
30 35 <!-- -*- extra stuff goes here -*- -->
31 36
32 37 </configure>
27 ftw/subsite/handlers.py
... ... @@ -0,0 +1,27 @@
  1 +from plone.portlets.constants import CONTEXT_CATEGORY
  2 +from plone.portlets.interfaces import ILocalPortletAssignmentManager
  3 +from plone.portlets.interfaces import IPortletManager
  4 +from zope.component import getUtility, getMultiAdapter
  5 +from zope.component.interfaces import ComponentLookupError
  6 +
  7 +def block_parent_portlets(object_, event):
  8 + """Adds a custom navigation Portlet for Buch
  9 + """
  10 + if 'portal_factory' in object_.getPhysicalPath():
  11 + # do not run in portal_factory
  12 + pass
  13 + else:
  14 + for i in range(1, 7):
  15 + try:
  16 + manager = getUtility(IPortletManager, name='ftw.subsite.front%s' % str(i))
  17 +
  18 + except ComponentLookupError:
  19 + # This happens when the plone site is removed.
  20 + # In this case persistent utilites are already gone.
  21 + # Reindexing is not necessary in this situation, since
  22 + # everything will be gone.
  23 + return
  24 +
  25 + assignable = getMultiAdapter((object_, manager,),
  26 + ILocalPortletAssignmentManager)
  27 + assignable.setBlacklistStatus(CONTEXT_CATEGORY, True)
23 ftw/subsite/profiles/default/viewlets.xml
... ... @@ -1,9 +1,20 @@
1 1 <?xml version="1.0"?>
2 2 <object>
3   - <order manager="plone.portalheader" skinname="*">
4   - <viewlet name="plone.app.i18n.locales.languageselector" />
5   - <viewlet name="plone.logo" inser-before="ftw.subsite.banner" />
6   - <viewlet name="ftw.subsite.banner" insert-after="plone.logo" />
7   - <viewlet name="plone.global_sections" insert-after="ftw.subsite.banner" />
8   - </order>
  3 +
  4 + <order manager="plone.portalheader" skinname="*">
  5 + <viewlet name="ftw.subsite.languageselector" />
  6 + <viewlet name="plone.logo" inser-before="ftw.subsite.banner" />
  7 + <viewlet name="ftw.subsite.banner" insert-after="plone.logo" />
  8 + <viewlet name="plone.global_sections" insert-after="ftw.subsite.banner" />
  9 + </order>
  10 +
  11 + <hidden manager="plone.portalheader" skinname="*">
  12 + <viewlet name="plone.app.i18n.locales.languageselector" />
  13 + </hidden>
  14 +
  15 + <!-- Plone 4.1 does not hide on skinname="*" -->
  16 + <hidden manager="plone.portalheader" skinname="Plone Default">
  17 + <viewlet name="plone.app.i18n.locales.languageselector" />
  18 + </hidden>
  19 +
9 20 </object>
46 ftw/subsite/tests/test_subsiteview.py
... ... @@ -1,15 +1,13 @@
1 1 from ftw.subsite.testing import FTW_SUBSITE_FUNCTIONAL_TESTING
2   -from plone.app.testing import TEST_USER_ID
3 2 from plone.app.testing import TEST_USER_NAME
4 3 from plone.app.testing import TEST_USER_PASSWORD
5 4 from plone.testing.z2 import Browser
6   -from zope.component import queryMultiAdapter
7 5 import unittest2 as unittest
8 6 import transaction
9   -from plone.app.testing import logout
10   -from plone.app.testing import setRoles
11   -from plone.app.testing import login
12   -
  7 +from zope.component import getUtility, getMultiAdapter
  8 +from plone.portlets.interfaces import IPortletManager
  9 +from plone.portlets.interfaces import IPortletAssignmentMapping
  10 +from ftw.subsite.portlets import teaserportlet
13 11
14 12 class TestSubsite(unittest.TestCase):
15 13
@@ -42,18 +40,6 @@ def tearDown(self):
42 40 self.portal.manage_delObjects(['mysubsite'])
43 41 transaction.commit()
44 42
45   - def test_view_has_permission(self):
46   - view = queryMultiAdapter((self.subsite, self.portal.REQUEST), name="subsite_view")
47   - logout()
48   - self.assertFalse(view.hasPermissions())
49   - setRoles(self.portal, TEST_USER_ID, ['Member'])
50   - login(self.portal, TEST_USER_NAME)
51   - self.assertFalse(view.hasPermissions())
52   - logout()
53   - setRoles(self.portal, TEST_USER_ID, ['Manager'])
54   - login(self.portal, TEST_USER_NAME)
55   - self.assertTrue(view.hasPermissions())
56   -
57 43 def test_view_render(self):
58 44 self.browser.open(self.subsite.absolute_url())
59 45 for item in range(1, 6):
@@ -65,3 +51,27 @@ def test_manageview_render(self):
65 51 self.browser.open(self.subsite.absolute_url() + '/manage-subsiteview')
66 52 for item in range(1, 6):
67 53 self.assertIn('<div id="subsite-column-%s" class="column">' % str(item), self.browser.contents)
  54 +
  55 + def test_view_authorized(self):
  56 + self._auth()
  57 + self.browser.open(self.subsite.absolute_url())
  58 + self.assertIn(' <h1 id="parent-fieldname-title" class="documentFirstHeading', self.browser.contents)
  59 + self.assertIn('<div class="contentActions">', self.browser.contents)
  60 +
  61 + def test_view_anonymous(self):
  62 + self.browser.open(self.subsite.absolute_url())
  63 + self.assertNotIn('<h1 id="parent-fieldname-title" class="documentFirstHeading', self.browser.contents)
  64 +
  65 + def test_drop_parent_portlets(self):
  66 + manager = getUtility(IPortletManager, name='ftw.subsite.front1')
  67 + mapping = getMultiAdapter((self.subsite, manager),
  68 + IPortletAssignmentMapping).__of__(self.subsite)
  69 +
  70 + mapping['myportlet'] = teaserportlet.Assignment(teasertitle='MyPortlet',
  71 + teaserdesc='Lorem Ipsum')
  72 +
  73 + housi = self.subsite.get(self.subsite.invokeFactory('Subsite', 'hans', title="Housi"))
  74 + housi.processForm()
  75 + transaction.commit()
  76 + self.browser.open(housi.absolute_url())
  77 + self.assertNotIn('MyPortlet', self.browser.contents)

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.