Beispiel #1
0
def isLinked(obj):
    """Check if the given content object is linked from another one."""
    log_deprecated(
        "utils.isLinked is deprecated, you should use plone.app.linkintegrity.utils.hasIncomingLinks"
    )  # noqa
    from plone.app.linkintegrity.utils import hasIncomingLinks
    return hasIncomingLinks(obj)
Beispiel #2
0
 def transitionObjectsByPaths(self, workflow_action, paths, comment='',
                              expiration_date=None, effective_date=None,
                              include_children=False, handle_errors=True,
                              REQUEST=None):
     log_deprecated("transitionObjectsByPaths is deprecated")
     failure = {}
     # use the portal for traversal in case we have relative paths
     portal = getToolByName(self, 'portal_url').getPortalObject()
     traverse = portal.restrictedTraverse
     for path in paths:
         if handle_errors:
             sp = transaction.savepoint(optimistic=True)
         try:
             o = traverse(path, None)
             if o is not None:
                 o.content_status_modify(workflow_action,
                                         comment,
                                         effective_date=effective_date,
                                         expiration_date=expiration_date)
         except ConflictError:
             raise
         except Exception, e:
             if handle_errors:
                 # skip this object but continue with sub-objects.
                 sp.rollback()
                 failure[path] = e
             else:
                 raise
         if getattr(o, 'isPrincipiaFolderish', None) and include_children:
             subobject_paths = ["%s/%s" % (path, id) for id in o]
             self.transitionObjectsByPaths(workflow_action, subobject_paths,
                                           comment, expiration_date,
                                           effective_date, include_children,
                                           handle_errors)
 def bodyClass(self, template, view):
     """Returns the CSS class to be used on the body tag.
     """
     log_deprecated("@@plone_view/bodyClass as been deprecated, you should use @@plone_layout/bodyClass")
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.bodyClass(template, view)
Beispiel #4
0
 def deleteObjectsByPaths(self, paths, handle_errors=True, REQUEST=None):
     log_deprecated("deleteObjectsByPaths is deprecated, you should use. "
                    "plone.api.content.delete. This method no longer does link integrity checks")  # noqa
     failure = {}
     success = []
     # use the portal for traversal in case we have relative paths
     portal = getToolByName(self, 'portal_url').getPortalObject()
     traverse = portal.restrictedTraverse
     for path in paths:
         # Skip and note any errors
         if handle_errors:
             sp = transaction.savepoint(optimistic=True)
         try:
             obj = traverse(path)
             obj_parent = aq_parent(aq_inner(obj))
             obj_parent.manage_delObjects([obj.getId()])
             success.append('%s (%s)' % (obj.getId(), path))
         except ConflictError:
             raise
         except Exception, e:
             if handle_errors:
                 sp.rollback()
                 failure[path] = e
                 log_exc()
             else:
                 raise
 def icons_visible(self):
     """Returns True if icons should be shown or False otherwise.
     """
     log_deprecated("@@plone_view/icons_visible as been deprecated, you should use @@plone_layout/icons_visible")
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.icons_visible()
 def transitionObjectsByPaths(self, workflow_action, paths, comment='',
                              expiration_date=None, effective_date=None,
                              include_children=False, handle_errors=True,
                              REQUEST=None):
     log_deprecated("transitionObjectsByPaths is deprecated")
     failure = {}
     # use the portal for traversal in case we have relative paths
     portal = getToolByName(self, 'portal_url').getPortalObject()
     traverse = portal.restrictedTraverse
     for path in paths:
         if handle_errors:
             sp = transaction.savepoint(optimistic=True)
         try:
             o = traverse(path, None)
             if o is not None:
                 o.content_status_modify(workflow_action,
                                         comment,
                                         effective_date=effective_date,
                                         expiration_date=expiration_date)
         except ConflictError:
             raise
         except Exception as e:
             if handle_errors:
                 # skip this object but continue with sub-objects.
                 sp.rollback()
                 failure[path] = e
             else:
                 raise
         if getattr(o, 'isPrincipiaFolderish', None) and include_children:
             subobject_paths = ["%s/%s" % (path, id) for id in o]
             self.transitionObjectsByPaths(workflow_action, subobject_paths,
                                           comment, expiration_date,
                                           effective_date, include_children,
                                           handle_errors)
     return failure
 def hide_columns(self, column_left, column_right):
     """Returns a CSS class matching the current column status.
     """
     log_deprecated("@@plone_view/hide_columns as been deprecated, you should use @@plone_layout/hide_columns")
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.hide_columns(column_left, column_right)
Beispiel #8
0
 def deleteObjectsByPaths(self, paths, handle_errors=True, REQUEST=None):
     log_deprecated(
         "deleteObjectsByPaths is deprecated, you should use. "
         "plone.api.content.delete. This method no longer does link integrity checks"
     )  # noqa
     failure = {}
     success = []
     # use the portal for traversal in case we have relative paths
     portal = getToolByName(self, 'portal_url').getPortalObject()
     traverse = portal.restrictedTraverse
     for path in paths:
         # Skip and note any errors
         if handle_errors:
             sp = transaction.savepoint(optimistic=True)
         try:
             obj = traverse(path)
             obj_parent = aq_parent(aq_inner(obj))
             obj_parent.manage_delObjects([obj.getId()])
             success.append('%s (%s)' % (obj.getId(), path))
         except ConflictError:
             raise
         except Exception, e:
             if handle_errors:
                 sp.rollback()
                 failure[path] = e
                 log_exc()
             else:
                 raise
 def have_portlets(self, manager_name, view=None):
     """Determine whether a column should be shown. The left column is
     called plone.leftcolumn; the right column is called plone.rightcolumn.
     """
     log_deprecated("@@plone_view/have_portlets as been deprecated, you should use @@plone_layout/have_portlets")
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.have_portlets(manager_name, view=view)
 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.
     """
     log_deprecated("@@plone_view/mark_view as been deprecated, you should use @@plone_layout/mark_view")
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     layout.mark_view(view)
 def hide_columns(self, column_left, column_right):
     """Returns a CSS class matching the current column status.
     """
     log_deprecated(
         "@@plone_view/hide_columns as been deprecated, you should use @@plone_layout/hide_columns"
     )
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.hide_columns(column_left, column_right)
 def icons_visible(self):
     """Returns True if icons should be shown or False otherwise.
     """
     log_deprecated(
         "@@plone_view/icons_visible as been deprecated, you should use @@plone_layout/icons_visible"
     )
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.icons_visible()
 def bodyClass(self, template, view):
     """Returns the CSS class to be used on the body tag.
     """
     log_deprecated(
         "@@plone_view/bodyClass as been deprecated, you should use @@plone_layout/bodyClass"
     )
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.bodyClass(template, view)
 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.
     """
     log_deprecated(
         "@@plone_view/mark_view as been deprecated, you should use @@plone_layout/mark_view"
     )
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     layout.mark_view(view)
 def have_portlets(self, manager_name, view=None):
     """Determine whether a column should be shown. The left column is
     called plone.leftcolumn; the right column is called plone.rightcolumn.
     """
     log_deprecated(
         "@@plone_view/have_portlets as been deprecated, you should use @@plone_layout/have_portlets"
     )
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.have_portlets(manager_name, view=view)
 def getIcon(self, item):
     """Returns an object which implements the IContentIcon interface and
     provides the informations necessary to render an icon. The item
     parameter needs to be adaptable to IContentIcon. Icons can be disabled
     globally or just for anonymous users with the icon_visibility property
     in site_properties.
     """
     log_deprecated("@@plone_view/getIcon as been deprecated, you should use @@plone_layout/getIcon")
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.getIcon(item)
 def getActionIcon(self, category, action_id, context=None):
     ai = BaseTool.getActionIcon(self, category, action_id, context=context)
     if ai:
         log_deprecated("The icon for the '%s/%s' action was obtained from "
                        "the action icons tool. The action icons tool has "
                        "been deprecated and will be removed in Plone 5. "
                        "You should register action icons directly on the "
                        "action now, using the 'icon_expr' "
                        "setting." % (category, action_id))
         return ai
     return None
    def addAction(
        self,
        id,
        name,
        action,
        condition='',
        permission='',
        category='Plone',
        visible=1,
        appId=None,
        imageUrl=None,
        icon_expr='',
        description='',
        REQUEST=None,
    ):
        """ Add an action to our list.
        """
        if not name:
            raise ValueError('A name is required.')

        a_expr = action and Expression(text=str(action)) or ''
        c_expr = condition and Expression(text=str(condition)) or ''

        if type(permission) != type(()):
            permission = permission and (str(permission), ) or ()

        if imageUrl:
            log_deprecated("The imageUrl parameter of the control panel "
                           "tool's addAction/registerConfiglet method has "
                           "been deprecated and will be removed in Plone 5. "
                           "Please use the icon_expr parameter instead.")
            icon_expr = 'string:${portal_url}/%s' % imageUrl

        new_actions = self._cloneActions()

        new_action = PloneConfiglet(
            id=str(id),
            title=name,
            action=a_expr,
            condition=c_expr,
            permissions=permission,
            category=str(category),
            visible=int(visible),
            appId=appId,
            description=description,
            icon_expr=icon_expr,
        )

        new_actions.append(new_action)
        self._actions = tuple(new_actions)

        if REQUEST is not None:
            return self.manage_editActionsForm(REQUEST,
                                               manage_tabs_message='Added.')
 def getClips(self):
     """Return  a list of Press Clips for this Press Room only if they should be shown
     """
     log_deprecated('getClips is deprecated and will be removed'
                    ' in PressRoom 4.0. Please update your pressroom_view template'
                    ' to query the appropriate collection directly.')
          
     if self.context.getShow_clips():
         source = self.context.restrictedTraverse('press-clips/all-press-clips', None)
         if source:
             return source.queryCatalog()
     return ()
 def isDiscussable(self, encoding=None):
     log_deprecated(
         "The isDiscussable method from the ExtensibleMetadata in "
         "Products.ATContentTypes has been deprecated and will be removed "
         "in Plone 5. This method belongs to the old discussion "
         "infrastructure that already has been replaced by "
         "plone.app.discussion in Plone 4.1.")
     if not 'portal_discussion' in self.objectIds():
         return
     # Returns either True or False
     dtool = getToolByName(self, 'portal_discussion')
     return dtool.isDiscussionAllowedFor(self)
 def addActionIcon(self, category, action_id, icon_expr, title=None,
                   priority=0):
     combination = '%s/%s' % (category, action_id)
     if combination not in WHITELISTED_AI:
         log_deprecated("An icon for the '%s' action is being added to "
                        "the action icons tool. The action icons tool has "
                        "been deprecated and will be removed in Plone 5. "
                        "You should register action icons directly on the "
                        "action now, using the 'icon_expr' "
                        "setting." % combination)
     return BaseTool.addActionIcon(self, category, action_id, icon_expr,
                                   title, priority)
 def queryActionIcon(self, category, action_id, default=None, context=None):
     ai = BaseTool.queryActionIcon(self, category, action_id,
                                   default=default, context=context)
     if ai:
         log_deprecated("The icon for the '%s/%s' action was obtained from "
                        "the action icons tool. The action icons tool has "
                        "been deprecated and will be removed in Plone 5. "
                        "You should register action icons directly on the "
                        "action now, using the 'icon_expr' "
                        "setting." % (category, action_id))
         return ai
     return None
 def updateActionIcon(self, category, action_id, icon_expr,
                      title=None, priority=0):
     """ update ActionIcons and remove cache entry """
     log_deprecated("The icon for the '%s/%s' action is being updated on "
                    "the action icons tool. The action icons tool has "
                    "been deprecated and will be removed in Plone 5. "
                    "You should register action icons directly on the "
                    "action now, using the 'icon_expr' "
                    "setting." % (category, action_id))
     BaseTool.updateActionIcon(self, category, action_id, icon_expr,
                               title, priority)
     removeAICacheEntry(category, action_id)
    def addAction(self,
                  id,
                  name,
                  action,
                  condition='',
                  permission='',
                  category='Plone',
                  visible=1,
                  appId=None,
                  imageUrl=None,
                  icon_expr = '',
                  description='',
                  REQUEST=None,
                  ):
        """ Add an action to our list.
        """
        if not name:
            raise ValueError('A name is required.')

        a_expr = action and Expression(text=str(action)) or ''
        c_expr = condition and Expression(text=str(condition)) or ''

        if type(permission) != type(()):
            permission = permission and (str(permission), ) or ()

        if imageUrl:
            log_deprecated("The imageUrl parameter of the control panel tool's "
                           "addAction/registerConfiglet method has been "
                           "deprecated and will be removed in Plone 5. "
                           "Please use the icon_expr parameter instead.")
            icon_expr = 'string:${portal_url}/%s' % imageUrl

        new_actions = self._cloneActions()

        new_action = PloneConfiglet(id=str(id),
                                    title=name,
                                    action=a_expr,
                                    condition=c_expr,
                                    permissions=permission,
                                    category=str(category),
                                    visible=int(visible),
                                    appId=appId,
                                    description=description,
                                    icon_expr = icon_expr,
                                    )

        new_actions.append(new_action)
        self._actions = tuple(new_actions)

        if REQUEST is not None:
            return self.manage_editActionsForm(
                REQUEST, manage_tabs_message='Added.')
 def isDiscussable(self, encoding=None):
     log_deprecated(
         "The isDiscussable method from the ExtensibleMetadata in "
         "Products.ATContentTypes has been deprecated and will be removed "
         "in Plone 5. This method belongs to the old discussion "
         "infrastructure that already has been replaced by "
         "plone.app.discussion in Plone 4.1."
     )
     if not 'portal_discussion' in self.objectIds():
         return
     # Returns either True or False
     dtool = getToolByName(self, 'portal_discussion')
     return dtool.isDiscussionAllowedFor(self)
 def getIcon(self, item):
     """Returns an object which implements the IContentIcon interface and
     provides the informations necessary to render an icon. The item
     parameter needs to be adaptable to IContentIcon. Icons can be disabled
     globally or just for anonymous users with the icon_visibility property
     in site_properties.
     """
     log_deprecated(
         "@@plone_view/getIcon as been deprecated, you should use @@plone_layout/getIcon"
     )
     context = aq_inner(self.context)
     layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     return layout.getIcon(item)
 def rawIsDiscussable(self):
     log_deprecated(
         "The rawIsDiscussable method from the ExtensibleMetadata in "
         "Products.ATContentTypes has been deprecated and will be removed "
         "in Plone 5. This method belongs to the old discussion "
         "infrastructure that already has been replaced by "
         "plone.app.discussion in Plone 4.1.")
     if not 'portal_discussion' in self.objectIds():
         return
     # Returns True, False or None where None means use the default
     result = getattr(aq_base(self), 'allow_discussion', None)
     if result is not None:
         result = bool(result)
     return result
 def rawIsDiscussable(self):
     log_deprecated(
         "The rawIsDiscussable method from the ExtensibleMetadata in "
         "Products.ATContentTypes has been deprecated and will be removed "
         "in Plone 5. This method belongs to the old discussion "
         "infrastructure that already has been replaced by "
         "plone.app.discussion in Plone 4.1."
     )
     if not 'portal_discussion' in self.objectIds():
         return
     # Returns True, False or None where None means use the default
     result = getattr(aq_base(self), 'allow_discussion', None)
     if result is not None:
         result = bool(result)
     return result
 def editIsDiscussable(self, encoding=None):
     log_deprecated(
         "The editIsDiscussable method from the ExtensibleMetadata in "
         "Products.ATContentTypes has been deprecated and will be removed "
         "in Plone 5. This method belongs to the old discussion "
         "infrastructure that already has been replaced by "
         "plone.app.discussion in Plone 4.1.")
     if not 'portal_discussion' in self.objectIds():
         return
     # Returns True, False or if None the default value
     result = self.rawIsDiscussable()
     if result is not None:
         return result
     default = self.defaultIsDiscussable()
     return default
 def defaultIsDiscussable(self):
     log_deprecated(
         "The defaultIsDiscussable method from the ExtensibleMetadata in "
         "Products.ATContentTypes has been deprecated and will be removed "
         "in Plone 5. This method belongs to the old discussion "
         "infrastructure that already has been replaced by "
         "plone.app.discussion in Plone 4.1.")
     if not 'portal_discussion' in self.objectIds():
         return
     # Returns the default value, either True or False
     default = None
     typeInfo = self.getTypeInfo()
     if typeInfo:
         default = typeInfo.allowDiscussion()
     return default
 def editIsDiscussable(self, encoding=None):
     log_deprecated(
         "The editIsDiscussable method from the ExtensibleMetadata in "
         "Products.ATContentTypes has been deprecated and will be removed "
         "in Plone 5. This method belongs to the old discussion "
         "infrastructure that already has been replaced by "
         "plone.app.discussion in Plone 4.1."
     )
     if not 'portal_discussion' in self.objectIds():
         return
     # Returns True, False or if None the default value
     result = self.rawIsDiscussable()
     if result is not None:
         return result
     default = self.defaultIsDiscussable()
     return default
 def updateActionIcon(self,
                      category,
                      action_id,
                      icon_expr,
                      title=None,
                      priority=0):
     """ update ActionIcons and remove cache entry """
     log_deprecated("The icon for the '%s/%s' action is being updated on "
                    "the action icons tool. The action icons tool has "
                    "been deprecated and will be removed in Plone 5. "
                    "You should register action icons directly on the "
                    "action now, using the 'icon_expr' "
                    "setting." % (category, action_id))
     BaseTool.updateActionIcon(self, category, action_id, icon_expr, title,
                               priority)
     removeAICacheEntry(category, action_id)
 def defaultIsDiscussable(self):
     log_deprecated(
         "The defaultIsDiscussable method from the ExtensibleMetadata in "
         "Products.ATContentTypes has been deprecated and will be removed "
         "in Plone 5. This method belongs to the old discussion "
         "infrastructure that already has been replaced by "
         "plone.app.discussion in Plone 4.1."
     )
     if not 'portal_discussion' in self.objectIds():
         return
     # Returns the default value, either True or False
     default = None
     typeInfo = self.getTypeInfo()
     if typeInfo:
         default = typeInfo.allowDiscussion()
     return default
 def addActionIcon(self,
                   category,
                   action_id,
                   icon_expr,
                   title=None,
                   priority=0):
     combination = '%s/%s' % (category, action_id)
     if combination not in WHITELISTED_AI:
         log_deprecated("An icon for the '%s' action is being added to "
                        "the action icons tool. The action icons tool has "
                        "been deprecated and will be removed in Plone 5. "
                        "You should register action icons directly on the "
                        "action now, using the 'icon_expr' "
                        "setting." % combination)
     return BaseTool.addActionIcon(self, category, action_id, icon_expr,
                                   title, priority)
    def allowDiscussion(self, allowDiscussion=None, **kw):
        log_deprecated(
            "The allowDiscussion method from the ExtensibleMetadata in "
            "Products.ATContentTypes has been deprecated and will be removed "
            "in Plone 5. This method belongs to the old discussion "
            "infrastructure that already has been replaced by "
            "plone.app.discussion in Plone 4.1."
        )
        if not 'portal_discussion' in self.objectIds():
            return
        default = self.defaultIsDiscussable()
        current = self.rawIsDiscussable()

        # If we already overwrote the default or the value we try to set is
        # not the default we change it. Otherwise we keep what's there.
        if (current is not None or
            (current is None and default != allowDiscussion)):
            dtool = getToolByName(self, 'portal_discussion', None)
            try:
                if dtool is not None:
                    try:
                        dtool.overrideDiscussionFor(self, allowDiscussion)
                    except AttributeError:
                        # CMF 2.1.0's CMFDefault.DiscussionTool
                        # has tried to delete the class attribute.
                        # TODO: remove this when we move to a later
                        # CMF.
                        pass
            except Unauthorized:
                # Catch Unauthorized exception that could be raised by the
                # discussion tool when the authenticated users hasn't
                # ModifyPortalContent permissions.
                # Explanation:
                # A user might have CreatePortalContent but not ModifyPortalContent
                # so allowDiscussion could raise a Unauthorized error although it's
                # called from trusted code. That is VERY bad inside setDefault()!
                log('Catched Unauthorized on discussiontool.' \
                    'overrideDiscussionFor(%s)' % self.absolute_url(1),
                    level=DEBUG)
    def allowDiscussion(self, allowDiscussion=None, **kw):
        log_deprecated(
            "The allowDiscussion method from the ExtensibleMetadata in "
            "Products.ATContentTypes has been deprecated and will be removed "
            "in Plone 5. This method belongs to the old discussion "
            "infrastructure that already has been replaced by "
            "plone.app.discussion in Plone 4.1."
        )
        if not 'portal_discussion' in self.objectIds():
            return
        default = self.defaultIsDiscussable()
        current = self.rawIsDiscussable()

        # If we already overwrote the default or the value we try to set is
        # not the default we change it. Otherwise we keep what's there.
        if (current is not None or
            (current is None and default != allowDiscussion)):
            dtool = getToolByName(self, 'portal_discussion', None)
            try:
                if dtool is not None:
                    try:
                        dtool.overrideDiscussionFor(self, allowDiscussion)
                    except AttributeError:
                        # CMF 2.1.0's CMFDefault.DiscussionTool
                        # has tried to delete the class attribute.
                        # TODO: remove this when we move to a later
                        # CMF.
                        pass
            except Unauthorized:
                # Catch Unauthorized exception that could be raised by the
                # discussion tool when the authenticated users hasn't
                # ModifyPortalContent permissions.
                # Explanation:
                # A user might have CreatePortalContent but not ModifyPortalContent
                # so allowDiscussion could raise a Unauthorized error although it's
                # called from trusted code. That is VERY bad inside setDefault()!
                log('Catched Unauthorized on discussiontool.' \
                    'overrideDiscussionFor(%s)' % self.absolute_url(1),
                    level=DEBUG)
Beispiel #37
0
def isLinked(obj):
    """Check if the given content object is linked from another one."""
    log_deprecated("utils.isLinked is deprecated, you should use plone.app.linkintegrity.utils.hasIncomingLinks")  # noqa
    from plone.app.linkintegrity.utils import hasIncomingLinks
    return hasIncomingLinks(obj)