def get_aritle(number): article = get_aritle_by_number(number) if article is None or not article.is_public: return render_template('404.html'), 404 form = CommentForm() if request.method == 'POST': if form.validate_on_submit(): try: month_number = int(form.checker.data) except ValueError: month_number = 0 if month_number != datetime.date.today().month: form.checker.errors = ["Sorry, but please prove you are a human."] form.checker.data = "" else: comment = Comment( article_number=number, author=form.author.data, comment=form.comment.data, ) comment.save() return redirect(article.get_absolute_url()) comments = get_comments(number) return render_template( 'article.html', article=article, form=form, comments=comments, )
def edit_article(number): """Add a article.""" article = get_aritle_by_number(number) if article is None: return render_template('404.html'), 404 form = ArticleForm( title=article.title, content=article.content, is_public=article.is_public, tags=article.tags, ) if request.method == 'POST': if form.validate_on_submit(): article.title = form.title.data article.content = form.content.data article.is_public = form.is_public.data article.tags = form.tags.data article.save() return redirect(article.get_absolute_url()) action_url = url_for('edit_article', number=number) return render_template('add_article.html', form=form, action_url=action_url)
def get_private_aritle(number): """Render website's index page.""" article = get_aritle_by_number(number) if article is None: return render_template('404.html'), 404 return render_template('article.html', article=article)