def test_gatherer(self): views = registration.getViews(IBrowserRequest) self.backends = [ view.factory(self.portal, self.request) for view in views if IGathererBackend.implementedBy(view.factory) ] self.assertEqual(len(self.backends), 1)
def getLayouts(context, request): """ @return: List of Layout objects. """ from plone.app.customerize import registration from zope.publisher.interfaces.browser import IBrowserView from zope.publisher.interfaces.browser import IBrowserRequest views = registration.getViews(IBrowserRequest) views = [ view for view in views if ILayoutView.implementedBy(view.factory) ] def constructLayout(view): """ Extract layout definition from class attributes """ icon = getattr(view.factory, "icon", None) # default title to class name if not present title = getattr(view.factory, "title", view.name) blocks = getattr(view.factory, "block_definitions", []) show_portlets = getattr(view.factory, "show_portlets", True) return Layout(view.name, view.name, title, icon, blocks, show_portlets) # Do not include abstract base class in the available view list return [ constructLayout(view) for view in views ]
def getViewletByName(self, name): views = registration.getViews(IBrowserRequest) for v in views: if v.provided == IViewlet: if v.name == name: # if str(v.required[1]) == '<InterfaceClass plone.app.discussion.interfaces.IDiscussionLayer>': return v return None
def getViewletByName(self,name): views = registration.getViews(IBrowserRequest) for v in views: if v.provided == IViewlet: if v.name == name: if str(v.required[1]) == '<InterfaceClass plone.app.discussion.interfaces.IDiscussionLayer>': return v return None
def FlowViewsVocabulary( context ): base = [SimpleTerm('content', 'content', _(u"label_content", default=u"Content")), SimpleTerm('summary', 'summary', _(u"label_summary", default=u"Summary")), SimpleTerm('banner', 'banner', _(u"label_banner", default=u"Banner")), SimpleTerm('custom', 'custom', _(u"label_custom", default=u"Custom"))] views = registration.getViews(IBrowserRequest) for name in [a.name for a in views if IFlowViewMarker in a.required and a.name not in ['flowview-settings', 'flowview-content']]: base.append(SimpleTerm(name,name,_(name))) return SimpleVocabulary(base)
def __call__(self, interface=IAPIViewlet, layer=ITelesurAPILayer): #views = registration.getViews(IBrowserRequest) views = registration.getViews(layer) terms = [] if interface is not None: for v in views: if v.provided == IViewlet: if interface.providedBy(v.factory): terms.append(SimpleVocabulary.createTerm(v.factory, u"%s" % v.name, v.name)) return SimpleVocabulary(terms)
def get_viewlet(self, name, context=None): if context is None: context = self.context views = registration.getViews(IBrowserRequest) viewlet = None for v in views: if v.provided == IViewlet and v.name == name: viewlet = v break factory = viewlet.factory try: return factory(context, self.request, self, None).__of__(context) except: return None
def get_viewlet(self, name, context=None): if context is None: context = self.context views = registration.getViews(IBrowserRequest) viewlet = None for v in views: if v.provided == IViewlet and v.name == name: viewlet = v break factory = viewlet.factory try: return factory(context, self.request, self, None).__of__(context) except: return None
def _get_viewlet_by_name(self, name, context): from plone.app.customerize.registration import getViews from zope.publisher.interfaces.browser import IBrowserRequest from zope.viewlet.interfaces import IViewlet request = self.request registration = None for v in getViews(IBrowserRequest): if v.provided == IViewlet: if v.name == name: registration = v if registration is None: raise ValueError viewlet = registration.factory(context, request, None, None).__of__(context) viewlet.update() return viewlet
def get_views(self, interface=None): views = [] key = 'views' if key not in self.cached_components: #http://developer.plone.org/views/browserviews.html views = [view.factory for view in \ registration.getViews(IBrowserRequest)] self.cached_components[key] = views if interface is not None: key = key + '.' + interface.__module__ + '.' + interface.__name__ if key not in self.cached_components: views = [view for view in views \ if interface.implementedBy(view)] self.cached_components[key] = views return self.cached_components[key]
def _get_viewlet_by_name(self, name, context): from plone.app.customerize.registration import getViews from zope.publisher.interfaces.browser import IBrowserRequest from zope.viewlet.interfaces import IViewlet request = self.request registration = None for v in getViews(IBrowserRequest): if v.provided == IViewlet: if v.name == name: registration = v if registration is None: raise ValueError viewlet = registration.factory(context, request, None, None) viewlet.update() return viewlet
def getViewletByName(self, name): """ Viewlets allow through-the-web customizations. Through-the-web customization magic is managed by five.customerize. We need to think of this when looking up viewlets. @return: Viewlet registration object """ views = registration.getViews(IBrowserRequest) for v in views: if v.provided == IViewlet: # Note that we might have conflicting BrowserView with the same # name, thus we need to check for provided if v.name == name: return v return None
def getViewletByName(self, name): """ Viewlets allow through-the-web customizations. Through-the-web customization magic is managed by five.customerize. We need to think of this when looking up viewlets. @return: Viewlet registration object """ views = registration.getViews(IBrowserRequest) for v in views: if v.provided == IViewlet: # Note that we might have conflicting BrowserView with the same name, # thus we need to check for provided if v.name == name: return v return None
def test_nota_view(self): registered = [v.name for v in registration.getViews(ITelesurLayer)] self.assertTrue('nota' in registered) view = queryMultiAdapter((self.n1, self.request), name='nota') self.assertTrue(view is not None) self.assertEquals(view.has_images(), 0) self.assertEquals(view.has_files(), 0) self.assertEquals(view.has_links(), 0) self.n1.invokeFactory('Image', 'foo', title='Foo', description='FOO', image=StringIO(zptlogo), filename='zpt.gif') self.n1.invokeFactory('File', 'bar', title='Bar', description='BAR', image=StringIO(zptlogo), filename='zpt.gif') self.n1.invokeFactory('Link', 'baz', title='Baz', url='http://baz/') self.assertEquals(view.has_images(), 1) self.assertEquals(view.has_files(), 1) self.assertEquals(view.has_links(), 1) self.assertEquals(view.getImage()['id'], 'foo')
def getViewletByName(self, name): views = registration.getViews(IBrowserRequest) found = None # Get active layers on the currest request object wanted_layers = list(self.request.__provides__.__iro__) # List of all viewlet registration with the name # Note: several registrations possible due to layers possible = [] for v in views: if v.provided == IViewlet: # Note that we might have conflicting BrowserView with the same name, # thus we need to check for provided if v.name == name: possible.append(v) wanted_layers = wanted_layers[:] for layer in wanted_layers: for viewlet_registration in possible: theme_layer = viewlet_registration.required[1] if theme_layer == layer: return viewlet_registration return None
def test_live_signal_alternative_view(self): registered = [v.name for v in registration.getViews(ITelesurLayer)] self.assertTrue('live-signal-alternative' in registered) view = queryMultiAdapter((self.n1, self.request), name='live-signal-alternative') self.assertTrue(view is not None)
def test_schedule_view(self): registered = [v.name for v in registration.getViews(ITelesurLayer)] self.assertTrue('schedule' in registered) view = queryMultiAdapter((self.n1, self.request), name='schedule') self.assertTrue(view is not None)
def test_folder_summary_view(self): registered = [v.name for v in registration.getViews(ITelesurLayer)] self.assertTrue('folder_summary_view' in registered) view = queryMultiAdapter((self.n1, self.request), name='nota') self.assertTrue(view is not None)
def test_more_articles_view_exists(self): registered = [v.name for v in registration.getViews(ITelesurLayer)] self.assertTrue('more-articles-view' in registered) view = queryMultiAdapter((self.n1, self.request), name='more-articles-view') self.assertTrue(view is not None)
def test_default_view_registered(self): pt = self.portal['portal_types'] self.assertEqual(pt['collective.nitf.content'].default_view, 'view') registered = [v.name for v in registration.getViews(INITFBrowserLayer)] self.assertTrue('view' in registered)
def test_scrollable_view_registered(self): registered = [v.name for v in registration.getViews(INITFBrowserLayer)] self.assertTrue('scrollable' in registered) view = queryMultiAdapter((self.n1, self.request), name='scrollable') self.assertTrue(view is not None)
def test_default_view_is_registered(self): pt = self.portal['portal_types'] self.assertEqual(pt['Article'].default_view, 'view') registered = [v.name for v in registration.getViews(Interface)] self.assertIn('view', registered)
def test_view_is_registered(self): registered = [v.name for v in registration.getViews(INITFLayer)] self.assertIn(self.name, registered)
def test_views_registered_task(self): views = ["view", "create-response", "edit-response", "save-response", "delete-response", "watching"] registered = [v.name for v in registration.getViews(IDefaultBrowserLayer)] # empty set only if all 'views' are 'registered' self.assertEqual(set(views) - set(registered), set([]))
def test_galleria_view_is_registered(self): registered = [v.name for v in registration.getViews(INITFLayer)] self.assertIn('galleria', registered) # raises InvalidParameterError if the view is not registered api.content.get_view(u'galleria', self.n1, self.request)
def test_donde_distribucion_view(self): registered = [v.name for v in registration.getViews(ITelesurLayer)] self.assertTrue('donde-distribucion' in registered) view = queryMultiAdapter((self.n1, self.request), name='donde-distribucion') self.assertTrue(view is not None)
def getViewletByName(self, name): views = registration.getViews(IBrowserRequest) for v in views: if v.name == name: return v return None
def test_default_view_is_registered(self): pt = self.portal['portal_types'] self.assertEqual(pt['Periodical'].default_view, 'view') registered = [v.name for v in registration.getViews(IPeriodicalLayer)] self.assertIn('view', registered)
def test_views_registered(self): views = ['view', 'gallery', 'folder_summary_view'] registered = [v.name for v in registration.getViews(INITFBrowserLayer)] # empty set only if all 'views' are 'registered' self.assertEquals(set(views) - set(registered), set([]))
def getViewletByName(self, name): views = registration.getViews(IBrowserRequest) for v in views: if v.name == name: return v return None
def test_view_is_registered(self): registered = [v.name for v in registration.getViews(IPloneQRLayer)] self.assertIn('ploneqrcode.belowcontentbody', registered)
def test_view_is_registered(self): registered = [v.name for v in registration.getViews(INITFLayer)] self.assertIn(self.name, registered)