Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

display menu now correct. just need to unregister views when they change

  • Loading branch information...
commit 98540ccf6a01e04aa1d0f8eb4158feb12eed70e7 1 parent 0b8d6b8
Dylan Jay authored
View
9 README.rst
@@ -239,3 +239,12 @@ possible future directions
- support hierarchical listing
- support ajax batching
- support infinite lists (auto load next when scrolled down)
+
+Dynamic adding to displaymenu
+=============================
+
+https://github.com/plone/Products.CMFDynamicViewFTI/blob/master/Products/CMFDynamicViewFTI/browserdefault.py
+https://github.com/plone/plone.app.customerize/blob/master/plone/app/customerize/browser.py
+ sm = getSiteManager(self.context)
+ sm.registerAdapter(viewzpt, required = reg.required,
+ provided = reg.provided, name = reg.name)
View
5 buildout.cfg
@@ -7,6 +7,8 @@ extends =
# conf/test-3.3.x.cfg
conf/test-4.2.x.cfg
+versions=versions
+
[plone]
eggs +=
collective.listingviews
@@ -18,3 +20,6 @@ recipe = zc.recipe.testrunner
eggs =
${plone:eggs}
plone.app.collection
+
+[versions]
+zc.buildout = 1.6.3
View
2  conf/test-4.2.x.cfg
@@ -7,7 +7,7 @@ extensions =
buildout.bootstrap
buildout.dumppickedversions
mr.developer
-extends = http://dist.plone.org/release/4.2rc2/versions.cfg
+extends = http://dist.plone.org/release/4.2-latest/versions.cfg
find-links =
http://dist.plone.org/thirdparty/elementtree-1.2.7-20070827-preview.zip
http://downloads.sourceforge.net/project/docutils/docutils/0.9/docutils-0.9.tar.gz
View
5 src/collective/listingviews/browser/views/configure.zcml
@@ -50,4 +50,9 @@
action="listing_views"
description="A custom listing view for folder and collection." />
+ <subscriber
+ for="Products.CMFPlone.interfaces.IPloneSiteRoot
+ zope.app.publication.interfaces.IBeforeTraverseEvent"
+ handler=".controlpanel.registerMenuItems"
+ />
</configure>
View
96 src/collective/listingviews/browser/views/controlpanel.py
@@ -5,13 +5,30 @@
from zope.interface import implements
from plone.registry.interfaces import IRegistry
from zope.component import queryUtility
-from zope.component import adapts, getUtility
+from zope.component import adapts, getUtility, getAdapters
+from zope.component import getSiteManager
+from zope.component import getGlobalSiteManager
+from zope.browser.interfaces import IBrowserView
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from Products.CMFCore.interfaces import IFolderish, IContentish
from collective.listingviews.utils import ComplexRecordsProxy
+from five.customerize.zpt import TTWViewTemplate
+from collective.listingviews.browser.views.listing_view import ListingView
+from Products.CMFCore.utils import getToolByName
+from zope.browsermenu.interfaces import IBrowserMenu
+from zope.browsermenu.metaconfigure import addMenuItem, MenuItemFactory, menuItemDirective
+from zope.browsermenu.menu import BrowserMenu, BrowserMenuItem, BrowserSubMenuItem
+from zope.browsermenu.interfaces import IBrowserMenuItem
+from Products.ATContentTypes.permission import ModifyViewTemplate
class ListingControlPanel(object):
implements(IListingControlPanel)
+
+
+
class ListingControlPanelForm(controlpanel.RegistryEditForm):
schema = IListingControlPanel
@@ -24,6 +41,83 @@ def getContent(self):
key_names={'views':'id'})
return proxy
+ def applyChanges(self, data):
+ # for each view we will create a new view in customerize and add that as a menu
+ # item in the display menu
+ sm = getSiteManager(self.context)
+
+ portal_types = getToolByName(self.context, "portal_types")
+
+ for view in data['views']:
+ view_name = 'collective.listingviews.%s'%view.id
+ sm.registerAdapter(ListingView,
+ required = (IFolderish, IBrowserRequest),
+ provided = IBrowserView,
+ name = view_name)
+
+ # add view to the relevent types
+ for type_ in ['Folder','Topic']:
+ fti = portal_types.getTypeInfo(type_)
+ if view_name not in fti.view_methods:
+ fti.manage_changeProperties(view_methods=fti.view_methods+(view_name,))
+
+ # registering a menu item will be done in beforeSiteTraverse event
+
+
+ #TODO unregister any old views
+
+ super(ListingControlPanelForm, self).applyChanges(data)
+
+
+ # register all the menu names again from registery
+ _registerMenuItems()
+
+
+# We need to register our menuitems the first time it's accessed
+def registerMenuItems(site, event, _handled=set()):
+ if site.getPhysicalPath() not in _handled:
+ _registerMenuItems()
+ _handled.add(site.getPhysicalPath())
+
+
+def _registerMenuItems():
+
+ reg = getUtility(IRegistry)
+ proxy = ComplexRecordsProxy(reg, IListingControlPanel, prefix='collective.listingviews',
+ key_names={'views':'id'})
+ gsm = getGlobalSiteManager()
+ menu = getUtility(IBrowserMenu, 'plone_displayviews')
+ for view in proxy.views:
+ # register a menu item
+ view_name = 'collective.listingviews.%s'%view.id
+ factory = MenuItemFactory(
+ BrowserMenuItem,
+ title=view.name,
+ action=view_name,
+ #description=description,
+ # icon=icon,
+ #filter=filter, permission=permission, extra=extra, order=order,
+ # _for=(IContentish, IDefaultBrowserLayer)
+ )
+ # ensure we remove our old factory if already registered
+ gsm.unregisterAdapter(
+ required = (IFolderish, IDefaultBrowserLayer),
+ provided = menu.getMenuItemType(),
+ name = view.name,
+ )
+
+ gsm.registerAdapter(
+ factory,
+ required = (IFolderish, IDefaultBrowserLayer),
+ provided = menu.getMenuItemType(),
+ name = view.name,
+ )
+
+
+ #assert menu.getMenuItemByAction(IFolderish, self.request, view_name)
+ # pp [x for x in gsm.registeredAdapters() if x.provided == menu.getMenuItemType()]
+
+
class ListingCustomFieldControlPanel(object):
implements(IListingCustomFieldControlPanel)
View
20 src/collective/listingviews/browser/views/listing_view.py
@@ -6,15 +6,29 @@
#from collective.listingviews.utils import getListingAdapter
from collective.listingviews.adapters import BasicAdapter
+class TempSettings(object):
+ listing_choice = None
+
+
class ListingView(BrowserView):
"""
- View for file will redirect to download if user can't edit it.
+
"""
implements(IListingViews)
- select_listing_view = ViewPageTemplateFile("templates/layout.pt")
+ index = ViewPageTemplateFile("templates/layout.pt")
def __init__(self, context, request):
super(ListingView, self).__init__(context, request)
+ view_name = request.getURL().split('/')[-1]
+ listing_view_name = view_name.rsplit('.',1)[-1]
+ #self.settings = ListingSettings(self.context, interfaces=[self.adapter.schema])
+ self.settings = TempSettings()
+ self.settings.listing_choice = listing_view_name
self.adapter = BasicAdapter(self.context, self.request)
- self.settings = ListingSettings(self.context, interfaces=[self.adapter.schema])
+
+ def render(self):
+ return self.index()
+
+ def __call__(self):
+ return self.render()
Please sign in to comment.
Something went wrong with that request. Please try again.