예제 #1
0
def post(id):
    if post := Post.query.get(id):
        post.views += 1
        db.session.commit()
        form = CommentForm()
        if form.validate_on_submit():
            name, email, content = (Markup.striptags(form.name.data),
                                    Markup.striptags(form.email.data),
                                    Markup.striptags(form.content.data))
            db.session.add(
                Comment(title=name, email=email, content=content, post_id=id))
            db.session.commit()
            s = f'Дякую, {Markup.striptags(form.name.data)}, за коментар :)'
            flash(s, 'success')
            return redirect(url_for('posts.post', id=id))
        elif form.is_submitted():
            flash("Будь ласка, заповніть всі поля відповідно до вимог.",
                  "error")
        related_posts = Post.query.filter_by(cat_id=post.cat_id).limit(5)
        return render_template('post.html',
                               title=post.title,
                               categories=Category.query.all(),
                               post=post,
                               months=months,
                               form=form,
                               related_posts=related_posts)
예제 #2
0
파일: routes.py 프로젝트: Bogusik/blog
def contact():
    form = MessageForm()
    if form.validate_on_submit():
        name, email, content = (Markup.striptags(form.name.data),
                                Markup.striptags(form.email.data),
                                Markup.striptags(form.content.data))
        db.session.add(Message(title=name, email=email, content=content))
        db.session.commit()
        s = f'Дякую, {Markup.striptags(form.name.data)}, за повідомлення :)'
        flash(s, 'success')
        return redirect(url_for('messages.contact'))
    elif form.is_submitted():
        flash("Будь ласка, заповніть всі поля відповідно до вимог.", "error")
    return render_template("contact.html",
                           categories=Category.query.all(),
                           title="Напиши мені",
                           form=form)
예제 #3
0
def get_description(body_html):
    """Get the description of the body by parsing its content.

    In cases where this fails (in case someone doesn't use the form, and
    files and issue directly on GitHub and edits the template), return
    something sensible.
    """
    stripped_body = Markup.striptags(body_html)
    description = re.search(r'Description: (.+) Steps', stripped_body)
    if description:
        return description.group(1)[0:74]
    else:
        return None
예제 #4
0
def todos_POST():
    current_page = request.values.get('page', 1)

    form = TodoCreateForm(request.form)
    if form.validate_on_submit():
        markup = Markup(form.description.data)
        description = markup.striptags()
        TodoService.save(description)
        flash('The task "{}" has been successfully added.'.format(description))
    else:
        for error in form.errors['description']:
            flash(error)

    return redirect('/todo?page={}'.format(current_page))