Beispiel #1
0
def get_article_by_id(art_id, username):
    try:
        article = Article.get_by_id(int(art_id))
        if User.get(User.name ==
                    username).id != article.owner.id and article.is_draft:
            return None
        return article
    except (ValueError, DoesNotExist):
        return None
Beispiel #2
0
def publish_article(username, article_id):
    article = Article.get_by_id(article_id)
    user = article.owner
    if user.name != username:
        return False
    Article\
        .update({Article.is_draft: False})\
        .where(Article.id == article_id)\
        .execute()
    User\
        .update({User.articles_count: user.articles_count + 1})\
        .where(User.id == user.id)\
        .execute()
    return True