def update_article(slug, **kwargs): article = Article.query.filter_by(slug=slug, author_id=current_identity.profile.id).first() if not article: raise InvalidUsage.article_not_found() article.update(updatedAt=dt.datetime.utcnow, **kwargs) article.save() return article
def make_comment_on_article(slug, body, **kwargs): article = Article.query.filter_by(slug=slug).first() if not article: raise InvalidUsage.article_not_found() comment = Comment(article, current_user.profile, body, **kwargs) comment.save() return comment
def get_article(slug): article = Article.query.filter_by(slug=slug).first() if not article: raise InvalidUsage.article_not_found() article.update(views=article.views+1) article.save() return article
def favorite_an_article(slug): profile = current_user.profile article = Article.query.filter_by(slug=slug).first() if not article: raise InvalidUsage.article_not_found() article.favourite(profile) article.save() return article
def delete_comment_on_article(slug, cid): article = Article.query.filter_by(slug=slug).first() if not article: raise InvalidUsage.article_not_found() comment = article.comments.filter_by(id=cid, author=current_user.profile).first() comment.delete() return '', 200
def unbookmark_an_article(slug): profile = current_user.profile article = Article.query.filter_by(slug=slug).first() if not article: raise InvalidUsage.article_not_found() article.unbookmark(profile) article.save() return article
def make_comment_on_article(slug, body, comment_id=None, **kwargs): article = Article.query.filter_by(slug=slug).first() if not article and not comment_id: raise InvalidUsage.article_not_found() if comment_id: comment = Comment(None, current_user.profile, body, comment_id, **kwargs) comment.comment_id = comment_id else: comment = Comment(article, current_user.profile, body, comment_id, **kwargs) comment.save() return comment
def get_user_articles(type=None): res = Article.query if type != "all": if type == "drafts": res = res.filter_by(isPublished=False) elif type == "published": res = res.filter_by(isPublished=True) else: raise InvalidUsage.article_not_found() res = res.join( Article.author).join(User).filter_by(username=current_user.username) return res.all()
def submit_article_for_review(org_slug, slug): organization = Organization.query.filter_by(slug=org_slug).first() if not organization: raise InvalidUsage.organization_not_found() article = Article.query.filter_by(slug=slug).first() if not article: raise InvalidUsage.article_not_found() article.needsReview = True article.save() organization.request_review(article) organization.save() return article
def reviewed_article(slug, org_slug, **kwargs): profile = current_user.profile organization = Organization.query.filter_by(slug=org_slug).first() article = Article.query.filter_by(slug=slug).first() if not organization.moderator(profile): raise InvalidUsage.not_admin() if article not in organization.pending_articles: raise InvalidUsage.article_not_found() organization.pending_articles.remove(article) organization.save() article.add_organization(organization) article.save() return '', 200
def review_article(slug, articleSlug): profile = current_user.profile tag = Tags.query.filter_by(slug=slug).first() if not tag: raise InvalidUsage.tag_not_found() if tag not in profile.moderated_tags: raise InvalidUsage.not_moderator() article = Article.query.filter_by(slug=articleSlug).first() if not article: raise InvalidUsage.article_not_found() if article.needsReview: article.remove_needReviewTag(tag) if article.is_allTagReviewed(): article.set_needsReview(False) article.save() return article
def get_article(slug): article = Article.query.filter_by(slug=slug).first() if not article: raise InvalidUsage.article_not_found() return article
def get_comments(slug): article = Article.query.filter_by(slug=slug).first() if not article: raise InvalidUsage.article_not_found() beeline.add_field("comment_count", article.comments.count()) return article.comments