How can I programmatically get the registration information of a view?
In my example (see below) I get the overview-controlpanel view from plone.app.customerize.registration.getViews(IBrowserRequest) into my obj variable.
From it I can get the name, the configure.zcml file and the position of the declaration in it (obj.name and obj.info)
I assume that obj.required gives me a tuple with the for attribute in its first element. Is this right?
But how can I get the class and the permission?
obj.factory gives a hint to Products.Five.browser.metaconfigure.OverviewControlPanel but not to Products.CMFPlone.controlpanel.browser.overview.OverviewControlPanel as defined in configure.zcml.
>>> from plone.app.customerize import registration
>>> from zope.publisher.interfaces.browser import IBrowserRequest
>>> import pprint
>>> obj = [view
... for view
... in registration.getViews(IBrowserRequest)
... if view.name.lower() in ['overview-controlpanel']
... ][0]
>>> with open(obj.info.file, 'r') as f:
... zcml_string = f.readlines()[obj.info.line-1:obj.info.eline]
Check obj.factory.__bases__ or obj.factory.__mro__ (when you customize a view using plone.app.customerize, it generates a subclass of the original view class).
The permissions end up on the view class's __ac_permissions__ attribute, if I recall correctly.
obj.required[0] gives me plone.base.interfaces.siteroot.IPloneSiteRoot (note siteroot) but in configure.zcml the for element is plone.base.interfaces.IPloneSiteRoot (without siteroot)
plone.base.interfaces.siteroot.IPloneSiteRoot and plone.base.interfaces.IPloneSiteRoot are the same object. plone.base.interface's __init__.py imports the interface from siteroot.py: plone.base/__init__.py at main · plone/plone.base · GitHub
plone.app.controlpanel.Overview is the zope 3 permission name and Plone Site Setup: Overview is the zope 2 permission name. I don't recall how to convert from one to the other.