Пример #1
0
def _edit_post(author, postid, struct, publish):
    try:
        post = Post.objects.get(tag_uri=postid)
        if not post.blog.is_author(author):
            log.debug("Author '%s' cannot delete post: %s", author.user.username, postid)
            raise PermissionDeniedException()

        log.debug("Author '%s' editing post: %s", author.user.username, postid)    
        
        post = mt_edit_post(struct, post)
        
        title = struct.get('title', None)
        if title is not None:
            post.headline = title

        excerpt = struct.get('description', None)
        if excerpt is not None:
            post.raw_excerpt = excerpt

        if publish:
            post.status = POST_PUBLISHED
        else:
            post.status = POST_DRAFT
            
        post.set_categories_by_name(struct.get('categories', []))
        
        threadlocals.set_current_user(author.user)
        post.save()
        
        return True
        
    except Post.DoesNotExist:
        log.debug("Could not find post: %s", postid)
        raise ResourceNotFoundException()
Пример #2
0
def _new_post(author, blogid, struct, publish):
    blog = Blog.objects.by_slug(blogid)
    if not blog:
        raise ResourceNotFoundException()
    
    if not blog.is_author(author):
        raise PermissionDeniedException()
    
    if publish:
        status = POST_PUBLISHED
    else:
        status = POST_DRAFT

    title = struct.get('title', None)
    if title is None:
        title = datetime.datetime.now().isoformat()
    
    rawdate = struct['dateCreated']
    dt = date_from_iso8601(rawdate)
    
    post = Post(headline = title,
                create_date = dt,
                status = status,
                blog = blog,
                )

    post = mt_edit_post(struct, post)

    excerpt = struct.get('description', None)
    if excerpt is not None:
        post.raw_excerpt = excerpt

    threadlocals.set_current_user(author.user)
    post.save()
    post.set_categories_by_name(struct.get('categories', []))
    
    return post.tag_uri