Esempio n. 1
0
def postTraversehook():
    """
    This hook will be called when traversal is complete
    """

    frame = sys._getframe(2)
    published = frame.f_locals['object']

    # If we're goin to pathkey-requester form we'll skip this hook
    if published and 'pathkey-requester' in published.__name__:
        return

    # obj in here might be the template so we need to get it's parent.
    # It might also be objects method (Images, Files) - for which aq_parent
    # throws AttributeError. We'll handle this in except clause.
    try:
        obj = published.aq_parent
    except AttributeError:
        # Another try - except to make sure we'll survive dexterity
        # content types as well
        try:
            obj = published.im_self
        except AttributeError:
            # Our last hope
            obj = getattr(published, 'context', None)

    request = frame.f_locals['self']

    if IDublinCore.providedBy(obj) and hasattr(obj, 'path_key'):
        request.pathkey = True
        notify(AfterTraverseEvent(obj, request))
Esempio n. 2
0
    def getContentLanguage(self, request):
        """Checks the language of the current content if not folderish."""
        if not request:
            return []
        try:
            # This will actually work nicely with browserdefault as we get
            # attribute error...
            contentpath = request.path[:]

            # Now check if we need to exclude from using language specific path
            # See https://dev.plone.org/ticket/11263
            if (
                bool(
                    [1 for p in self.exclude_paths if p in contentpath]
                ) or
                bool(
                    [1 for p in self.exclude_exts
                     if contentpath[0].endswith(p)]
                )
            ):
                return None

            obj = getSite()
            traversed = []
            while contentpath:
                name = contentpath.pop()
                if name[0] in '@+':
                    break
                next = obj.unrestrictedTraverse(name, None)
                if next is None:
                    break
                if isinstance(next, VirtualHostMonster):
                    # next element is the VH subpath
                    contentpath.pop()
                    continue
                obj = next
                traversed.append(obj)
            for obj in reversed(traversed):
                if IDublinCore.providedBy(obj):
                    lang = obj.Language()
                    if not lang:
                        continue
                    if lang in self.getSupportedLanguages():
                        return lang
                    else:
                        return None
        except ConflictError:
            raise
        except:
            pass
        return None
Esempio n. 3
0
    def __call__(self, **kwargs):
        alsoProvides(self, IRoleManager)
        if IContentish.providedBy(self.context):
            alsoProvides(self, IContentish)
        if IMinimalDublinCore.providedBy(self.context):
            alsoProvides(self, IMinimalDublinCore)
        if IWorkflowAware.providedBy(self.context):
            alsoProvides(self, IWorkflowAware)
        if IDublinCore.providedBy(self.context):
            alsoProvides(self, IDublinCore)
        if ICatalogableDublinCore.providedBy(self.context):
            alsoProvides(self, ICatalogableDublinCore)

        for key, value in kwargs.items():
            setattr(self, key, value)
        return self.__of__(self.context)
Esempio n. 4
0
    def __call__(self, **kwargs):
        alsoProvides(self, IRoleManager)
        if IContentish.providedBy(self.context):
            alsoProvides(self, IContentish)
        if IMinimalDublinCore.providedBy(self.context):
            alsoProvides(self, IMinimalDublinCore)
        if IWorkflowAware.providedBy(self.context):
            alsoProvides(self, IWorkflowAware)
        if IDublinCore.providedBy(self.context):
            alsoProvides(self, IDublinCore)
        if ICatalogableDublinCore.providedBy(self.context):
            alsoProvides(self, ICatalogableDublinCore)

        for key, value in kwargs.items():
            setattr(self, key, value)
        return self.__of__(self.context)
 def getContentLanguage(self):
     """Checks the language of the current content if not folderish."""
     if not hasattr(self, 'REQUEST'):
         return []
     try: # This will actually work nicely with browserdefault as we get attribute error...
         contentpath = self.REQUEST.path[:]
         if 'portal_factory' in contentpath:
             return None
         obj = self.aq_parent
         traversed = []
         while contentpath:
             name = contentpath.pop()
             if name[0] in '@+':
                 break
             next = obj.unrestrictedTraverse(name, None)
             if next is None:
                 break
             if isinstance(next, VirtualHostMonster):
                 # next element is the VH subpath
                 contentpath.pop()
                 continue
             obj = next
             traversed.append(obj)
         for obj in reversed(traversed):
             if IDublinCore.providedBy(obj):
                 lang = obj.Language()
                 if not lang:
                     continue
                 if lang in self.getSupportedLanguages():
                     return lang
                 else:
                     return None
     except ConflictError:
         raise
     except:
         pass
     return None
 def getContentLanguage(self):
     """Checks the language of the current content if not folderish."""
     if not hasattr(self, 'REQUEST'):
         return []
     try:  # This will actually work nicely with browserdefault as we get attribute error...
         contentpath = self.REQUEST.path[:]
         if 'portal_factory' in contentpath:
             return None
         obj = self.aq_parent
         traversed = []
         while contentpath:
             name = contentpath.pop()
             if name[0] in '@+':
                 break
             next = obj.unrestrictedTraverse(name, None)
             if next is None:
                 break
             if isinstance(next, VirtualHostMonster):
                 # next element is the VH subpath
                 contentpath.pop()
                 continue
             obj = next
             traversed.append(obj)
         for obj in reversed(traversed):
             if IDublinCore.providedBy(obj):
                 lang = obj.Language()
                 if not lang:
                     continue
                 if lang in self.getSupportedLanguages():
                     return lang
                 else:
                     return None
     except ConflictError:
         raise
     except:
         pass
     return None
Esempio n. 7
0
def postTraversehook():
    """
    This hook will be called when traversal is complete
    """

    frame = sys._getframe(2)
    published = frame.f_locals['object']

    # If we're goin to pathkey-requester form we'll skip this hook
    if 'pathkey-requester' in published.__name__:
        return

    # obj in here might be the template so we need to get it's parent.
    # It might also be objects method (Images, Files) - for which aq_parent
    # throws AttributeError. We'll handle this in except clause.
    try:
        obj = published.aq_parent
    except AttributeError:
        obj = published.im_self
    
    request = frame.f_locals['self']
    
    if IDublinCore.providedBy(obj) and hasattr(obj, 'path_key'):
        notify(AfterTraverseEvent(obj, request))
Esempio n. 8
0
    def editMetadata(self, obj, allowDiscussion=None, title=None,
                     subject=None, description=None, contributors=None,
                     effective_date=None, expiration_date=None, format=None,
                     language=None, rights=None, **kwargs):
        # Responsible for setting metadata on a content object.
        # We assume the obj implements IDublinCoreMetadata.
        mt = getToolByName(self, 'portal_membership')
        if not mt.checkPermission(ModifyPortalContent, obj):
            # FIXME: Some scripts rely on this being string?
            raise Unauthorized

        REQUEST = self.REQUEST
        pfx = self.field_prefix

        def getfield(request, name, default=None, pfx=pfx):
            return request.form.get(pfx + name, default)

        def tuplify(value):
            return tuple(filter(None, value))

        if IDublinCore.providedBy(obj):
            if title is None:
                title = getfield(REQUEST, 'title')
            if description is None:
                description = getfield(REQUEST, 'description')
            if subject is None:
                subject = getfield(REQUEST, 'subject')
            if subject is not None:
                subject = tuplify(subject)
            if contributors is None:
                contributors = getfield(REQUEST, 'contributors')
            if contributors is not None:
                contributors = tuplify(contributors)
            if effective_date is None:
                effective_date = getfield(REQUEST, 'effective_date')
            if effective_date == '':
                effective_date = 'None'
            if expiration_date is None:
                expiration_date = getfield(REQUEST, 'expiration_date')
            if expiration_date == '':
                expiration_date = 'None'

        if IMutableDublinCore.providedBy(obj):
            if title is not None:
                obj.setTitle(title)
            if description is not None:
                obj.setDescription(description)
            if subject is not None:
                obj.setSubject(subject)
            if contributors is not None:
                obj.setContributors(contributors)
            if effective_date is not None:
                obj.setEffectiveDate(effective_date)
            if expiration_date is not None:
                obj.setExpirationDate(expiration_date)
            if format is not None:
                obj.setFormat(format)
            if language is not None:
                obj.setLanguage(language)
            if rights is not None:
                obj.setRights(rights)
            # Make the catalog aware of changes
            obj.reindexObject()
Esempio n. 9
0
    def editMetadata(self,
                     obj,
                     allowDiscussion=None,
                     title=None,
                     subject=None,
                     description=None,
                     contributors=None,
                     effective_date=None,
                     expiration_date=None,
                     format=None,
                     language=None,
                     rights=None,
                     **kwargs):
        # Responsible for setting metadata on a content object.
        # We assume the obj implements IDublinCoreMetadata.
        mt = getToolByName(self, 'portal_membership')
        if not mt.checkPermission(ModifyPortalContent, obj):
            # FIXME: Some scripts rely on this being string?
            raise Unauthorized

        REQUEST = self.REQUEST
        pfx = self.field_prefix

        def getfield(request, name, default=None, pfx=pfx):
            return request.form.get(pfx + name, default)

        def tuplify(value):
            return tuple(filter(None, value))

        if IDublinCore.providedBy(obj):
            if title is None:
                title = getfield(REQUEST, 'title')
            if description is None:
                description = getfield(REQUEST, 'description')
            if subject is None:
                subject = getfield(REQUEST, 'subject')
            if subject is not None:
                subject = tuplify(subject)
            if contributors is None:
                contributors = getfield(REQUEST, 'contributors')
            if contributors is not None:
                contributors = tuplify(contributors)
            if effective_date is None:
                effective_date = getfield(REQUEST, 'effective_date')
            if effective_date == '':
                effective_date = 'None'
            if expiration_date is None:
                expiration_date = getfield(REQUEST, 'expiration_date')
            if expiration_date == '':
                expiration_date = 'None'

        if IMutableDublinCore.providedBy(obj):
            if title is not None:
                obj.setTitle(title)
            if description is not None:
                obj.setDescription(description)
            if subject is not None:
                obj.setSubject(subject)
            if contributors is not None:
                obj.setContributors(contributors)
            if effective_date is not None:
                obj.setEffectiveDate(effective_date)
            if expiration_date is not None:
                obj.setExpirationDate(expiration_date)
            if format is not None:
                obj.setFormat(format)
            if language is not None:
                obj.setLanguage(language)
            if rights is not None:
                obj.setRights(rights)
            # Make the catalog aware of changes
            obj.reindexObject()