def test_portlet_inheritance(self):
        portal = self.layer['portal']
        folder = portal.folder2
        request = folder.REQUEST
        view = folder.restrictedTraverse('@@plone')
        alsoProvides(view, IViewView)
        self.assertTrue(IViewView.providedBy(view))
        viewlet_manager = queryMultiAdapter(
            (folder, request, view),
            IContentProvider,
            'plone.abovecontentbody')
        viewlet = queryMultiAdapter(
            (folder, request, view, viewlet_manager),
            IViewlet,
            'collective.calltoaction')
        self.assertTrue(viewlet is not None)
        viewlet.update()
        # The portlet from the test fixture is blocked.
        self.assertEqual(len(viewlet.data), 0)

        # Show the action globally.  This ignores portlet inheritance.
        registry = getUtility(IRegistry)
        settings = registry.forInterface(
            ICollectiveCalltoactionSettings, check=False)
        self.assertFalse(settings.show_global)
        settings.show_global = True

        # Now we should see the portlet
        viewlet.update()
        self.assertEqual(len(viewlet.data), 1)
    def available(self):
        if not (IViewView.providedBy(self.view)
                or IFolderContentsView.providedBy(self.view)):
            return False

        # Context could be a default page.  We want the canonical object
        # instead.
        context = aq_inner(self.context)
        pcs = getMultiAdapter(
            (context, self.request), name='plone_context_state')
        canonical = pcs.canonical_object()
        if not IQuickUploadCapable.providedBy(canonical):
            return False
        elif IQuickUploadNotCapable.providedBy(canonical):
            return False
        elif not self.pm.checkPermission('Add portal content', canonical):
            return False
        elif isTemporary(canonical):
            return False

        upload_portal_type = self.data.upload_portal_type
        if (upload_portal_type and upload_portal_type != 'auto'
                and upload_portal_type not in [
                    t.id for t in canonical.getAllowedTypes()
                ]):
            return False
        else:
            return True
 def test_viewlet(self):
     request = self.folder.REQUEST
     view = self.folder.restrictedTraverse('@@plone')
     alsoProvides(view, IViewView)
     self.assertTrue(IViewView.providedBy(view))
     viewlet_manager = queryMultiAdapter(
         (self.folder, request, view),
         IContentProvider,
         'plone.abovecontentbody')
     viewlet = queryMultiAdapter(
         (self.folder, request, view, viewlet_manager),
         IViewlet,
         'collective.calltoaction')
     self.assertTrue(viewlet is not None)
     viewlet.update()
     # We expect data from the portlet assignment in
     # profiles/testfixture/portlets.xml.
     self.assertEqual(len(viewlet.data), 1)
     portlet = viewlet.data[0]
     self.assertIn('assignment', portlet.keys())
     self.assertIn('html', portlet.keys())
     assignment = portlet['assignment']
     self.assertEqual(assignment.milli_seconds_until_overlay, 1000)
     portlet_html = portlet['html']
     self.assertIn('portletCallToAction', portlet_html)
     self.assertIn('portletCallToAction', portlet_html)
     viewlet_html = viewlet.render()
     self.assertIn(portlet_html, viewlet_html)
     self.assertIn('data-timeout="1000"', viewlet_html)
Exemplo n.º 4
0
def get_viewlet(context=None, request=None, manager=None, name=None):
    """Helper method for getting the viewlet for the provided viewlet name
    and viewlet manager.

    :param context: context object
    :param request: request
    :param manager: viewlet manager, for which the viewlet is registered
    :param name: viewlet name
    :returns: viewlet, if found, None otherwise
    """

    # viewlet managers also require a view object for adaptation
    view = BrowserView(context, request)
    if not IViewView.providedBy(view):
        alsoProvides(view, IViewView)

    # viewlet managers are found by Multi-Adapter lookup
    manager = getMultiAdapter(
        (context, request, view), IViewletManager, manager)

    # calling update() on a manager causes it to set up its viewlets
    manager.update()

    all_viewlets = manager.viewlets
    for viewlet in all_viewlets:
        if viewlet.__name__ == name:
            return viewlet
Exemplo n.º 5
0
 def update(self):
     super(ToolbarViewlet, self).update()
     if IViewView.providedBy(self.__parent__):
         # Ensure this viewlet has the interface that the iterate
         # alert viewlets are registered against such that they
         # only show up on view, not on edit.
         alsoProvides(self, IViewView)
 def show_history(self):
     if not _checkPermission('CMFEditions: Access previous versions', self.context):
         return False
     if IViewView.providedBy(self.__parent__):
         return True
     if IFolderContentsView.providedBy(self.__parent__):
         return True
     return False
Exemplo n.º 7
0
    def update(self):
        # The drop-down menus are pulled in via a simple content provider
        # from plone.app.contentmenu. This behaves differently depending on
        # whether the view is marked with IViewView. If our parent view
        # provides that marker, we should do it here as well.
        super(ContentViewsViewlet, self).update()
        if IViewView.providedBy(self.__parent__):
            alsoProvides(self, IViewView)

        self.tabSet1, self.tabSet2 = self.getTabSets()
Exemplo n.º 8
0
    def mark_view(self, view):
        """Adds a marker interface to the view if it is "the" view for the
        context May only be called from a template.
        """
        if not view:
            return

        context_state = getMultiAdapter((self.context, self.request), name=u"plone_context_state")

        if context_state.is_view_template() and not IViewView.providedBy(view):
            alsoProvides(view, IViewView)
    def update(self):
        context = aq_inner(self.context)
        context_state = getMultiAdapter((context, self.request),
                                        name=u'plone_context_state')

        self.object_actions = context_state.actions('object_actions')

        # The drop-down menus are pulled in via a simple content provider
        # from plone.app.contentmenu. This behaves differently depending on
        # whether the view is marked with IViewView. If our parent view
        # provides that marker, we should do it here as well.
        if IViewView.providedBy(self.__parent__):
            alsoProvides(self, IViewView)
 def test_viewlet_only_on_view(self):
     # When the view is not on IViewView, the viewlet is not registered.
     request = self.folder.REQUEST
     view = self.folder.restrictedTraverse('@@plone')
     self.assertFalse(IViewView.providedBy(view))
     viewlet_manager = queryMultiAdapter(
         (self.folder, request, view),
         IContentProvider,
         'plone.abovecontentbody')
     viewlet = queryMultiAdapter(
         (self.folder, request, view, viewlet_manager),
         IViewlet,
         'collective.calltoaction')
     self.assertTrue(viewlet is None)
    def available(self):
        if not (IViewView.providedBy(self.view) \
             or IFolderContentsView.providedBy(self.view)):
            return False

        context = aq_inner(self.context)

        if not IQuickUploadCapable.providedBy(context):
            return False
        elif IQuickUploadNotCapable.providedBy(context):
            return False
        elif not self.pm.checkPermission('Add portal content', context):
            return False
        elif isTemporary(context):
            return False

        upload_portal_type = self.data.upload_portal_type
        if (upload_portal_type and upload_portal_type != 'auto'
                and upload_portal_type not in [t.id for t
                        in self.context.getAllowedTypes()]):
            return False
        else:
            return True
Exemplo n.º 12
0
    def show_viewlet(self):

        # TODO => all details, even the default ones, should be defined
        # through an item detail viewlet
        man = ItemDetailViewletManager(self.context, self.request, self)
        man.update()

        if man.viewlets:
            return True

        if hasattr(self.view, 'show_facility_viewlet'):
            return self.view.show_facility_viewlet

        # Only show on default view
        if not IViewView.providedBy(self.view):
            return False

        attributes = [
            'image',
            'opening_hours',
            'description',
            'contact',
            'infrastructure',
            'terms_of_use',
            'notes',
        ]

        for a in attributes:
            if not hasattr(self.context, a):
                return False

        for a in attributes:
            if getattr(self.context, a):
                return True

        return False
Exemplo n.º 13
0
 def update(self):
     if IViewView.providedBy(self.__parent__):
         alsoProvides(self, IViewView)
Exemplo n.º 14
0
 def enabled(self, view=None):
     if view and not IViewView.providedBy(view):
         return False
     enabled_portal_types = self.enabled_portal_types()
     return self.context.portal_type in enabled_portal_types
Exemplo n.º 15
0
    def _initializeData(self, options=None, view=None, template=None):
        # We don't want to do this in __init__ because the view provides
        # methods which are useful outside of globals.  Also, performing
        # actions during __init__ is dangerous because instances are usually
        # created during traversal, which means authentication hasn't yet
        # happened.
        context = aq_inner(self.context)
        if options is None:
            options = {}
        if view is None:
            view = self

        show_portlets = not options.get("no_portlets", False)
        def_actions = options.get("actions", None)

        # XXX: Can't store data as attributes directly because it will
        # insert the view into the acquisition chain. Someone should
        # come up with a way to prevent this or get rid of the globals
        # view altogether

        tools = getMultiAdapter((context, self.request), name=u"plone_tools")
        portal_state = getMultiAdapter((context, self.request), name=u"plone_portal_state")
        context_state = getMultiAdapter((context, self.request), name=u"plone_context_state")

        self._data["utool"] = utool = tools.url()
        self._data["portal"] = portal = portal_state.portal()
        self._data["portal_url"] = portal_state.portal_url()
        self._data["mtool"] = mtool = tools.membership()
        self._data["atool"] = atool = tools.actions()
        self._data["putils"] = putils = getToolByName(context, "plone_utils")
        self._data["acl_users"] = getToolByName(context, "acl_users")
        self._data["wtool"] = wtool = tools.workflow()
        self._data["ifacetool"] = tools.interface()
        self._data["syntool"] = tools.syndication()
        self._data["portal_title"] = portal_state.portal_title()
        self._data["object_title"] = context_state.object_title()
        self._data["checkPermission"] = checkPermission = mtool.checkPermission
        self._data["member"] = portal_state.member()
        self._data["membersfolder"] = mtool.getMembersFolder()
        self._data["isAnon"] = portal_state.anonymous()
        self._data["actions"] = actions = def_actions or context_state.actions()
        self._data["keyed_actions"] = def_actions or context_state.keyed_actions()
        self._data["user_actions"] = actions["user"]
        self._data["workflow_actions"] = actions["workflow"]
        self._data["folder_actions"] = actions["folder"]
        self._data["global_actions"] = actions["global"]

        portal_tabs_view = getMultiAdapter((context, context.REQUEST), name="portal_tabs_view")
        self._data["portal_tabs"] = portal_tabs_view.topLevelTabs(actions=actions)

        self._data["wf_state"] = context_state.workflow_state()
        self._data["portal_properties"] = props = tools.properties()
        self._data["site_properties"] = site_props = props.site_properties
        self._data["ztu"] = ZTUtils
        self._data["isFolderish"] = context_state.is_folderish()

        self._data["sl"] = have_left_portlets = show_portlets and self.have_portlets("plone.leftcolumn", view)
        self._data["sr"] = have_right_portlets = show_portlets and self.have_portlets("plone.rightcolumn", view)
        self._data["hidecolumns"] = self.hide_columns(have_left_portlets, have_right_portlets)

        self._data["here_url"] = context_state.object_url()
        self._data["default_language"] = portal_state.default_language()
        self._data["language"] = portal_state.language()
        self._data["is_editable"] = context_state.is_editable()
        self._data["isLocked"] = context_state.is_locked()
        self._data["isRTL"] = portal_state.is_rtl()
        self._data["visible_ids"] = self.visibleIdsEnabled() or None
        self._data["current_page_url"] = context_state.current_page_url()
        self._data["normalizeString"] = putils.normalizeString
        self._data["toLocalizedTime"] = self.toLocalizedTime
        self._data["isStructuralFolder"] = context_state.is_structural_folder()
        self._data["isContextDefaultPage"] = context_state.is_default_page()

        self._data["navigation_root_url"] = portal_state.navigation_root_url()
        self._data["Iterator"] = utils.IndexIterator
        self._data["tabindex"] = utils.IndexIterator(pos=30000, mainSlot=False)
        self._data["uniqueItemIndex"] = utils.RealIndexIterator(pos=0)

        template_id = options.get("template_id", None)
        if template_id is None and template is not None:
            template_id = template.getId()
        self._data["template_id"] = template_id

        isViewTemplate = context_state.is_view_template()
        if isViewTemplate and not IViewView.providedBy(view):
            # Mark the view as being "the" view
            alsoProvides(view, IViewView)

        self._data["isViewTemplate"] = isViewTemplate