def publish_post(post):
    """ Publish the post if it is not already published.

    Files and links uploaded to a post are moved to its workspace,
    related to the post they were added to and published."""
    pw = getToolByName(post, 'portal_workflow')
    reviewState = pw.getInfoFor(post, 'review_state')
    ws = post.aq_parent
    if reviewState == 'private':
        post = utilities.rename(post)
        pw.doActionFor(post, 'publish')

    for itemId, item in post.items():
        if not IRichMetaData.providedBy(item):
            continue
        # before moving we check if an object with this id already exists in
        # the workspace:
        if itemId in ws:
            newId = utilities.find_possible_id(itemId, ws)
            post.manage_renameObjects([itemId], [newId])
            itemId = newId
        # move:
        clip = post.manage_cutObjects([itemId])
        ws.manage_pasteObjects(clip)
        item = ws[itemId]
        # relate:
        intids = getUtility(IIntIds)
        relation = RelationValue(intids.getId(item))
        post.aq_base.relatedFiles = getattr(post.aq_base, 'relatedFiles', [])
        if not relation.to_id in (x.to_id for x in post.aq_base.relatedFiles):
            post.aq_base.relatedFiles.append(relation)
Esempio n. 2
0
    def publishTraverse(self, request, name):
        target = super(WorkspacePublishTraverse, self)\
            .publishTraverse(request, name)

        if not request.path:
            if IThreaded.providedBy(target):
                self.redirect('/conversation#entryanchor-' + target.id)
            elif IRichMetaData.providedBy(target):
                self.redirect('/material#materialanchor-' + target.id)
            elif IATEvent.providedBy(target):
                self.redirect('#eventanchor-' + target.id)

        return target
def clean_up(post):
    """Delete post if it isn't already published, discard uploaded material
    if it is. returns the post if it still exists, or otherwise it's parent."""
    pw = getToolByName(post, 'portal_workflow')
    reviewState = pw.getInfoFor(post, 'review_state')
    if reviewState == 'private':
        parent = post.aq_parent
        parent.manage_delObjects([post.id])
        return parent
    else:
        for itemId, item in post.items():
            if IRichMetaData.providedBy(item):
                post.manage_delObjects([itemId])
    return post