Example #1
0
def follow(user_id):

    user = User.query.get_or_404(user_id)
    g.user.follow(user)
    db.session.commit()

    body = render_template("emails/followed.html", user=user)

    mail.send_message(subject=_("%s is now following you" % g.user.username), body=body, recipients=[user.email])

    return jsonify(success=True, reload=True)
Example #2
0
def follow(user_id):

    user = User.query.get_or_404(user_id)
    g.user.follow(user)
    db.session.commit()

    body = render_template("emails/followed.html", user=user)

    mail.send_message(subject=_("%s is now following you" % g.user.username),
                      body=body,
                      recipients=[user.email])

    return jsonify(success=True, reload=True)
Example #3
0
def add_comment(post_id, parent_id=None):
    post = Post.query.get_or_404(post_id)
    post.permissions.view.test(403)

    parent = Comment.query.get_or_404(parent_id) if parent_id else None

    form = CommentForm()

    if form.validate_on_submit():
        comment = Comment(post=post,
                          parent=parent,
                          author=g.user)

        form.populate_obj(comment)

        db.session.add(comment)
        db.session.commit()

        signals.comment_added.send(post)

        flash(_("Thanks for your comment"), "success")

        author = parent.author if parent else post.author

        if author.email_alerts and author.id != g.user.id:

            subject = _("Somebody replied to your comment") if parent else \
                _("Somebody commented on your post")

            template = "emails/comment_replied.html" if parent else \
                       "emails/post_commented.html"

            body = render_template(template,
                                   author=author,
                                   post=post,
                                   parent=parent,
                                   comment=comment)

            mail.send_message(subject=subject,
                              body=body,
                              sender=current_app.config.get(
                                  'DEFAULT_MAIL_SENDER'),
                              recipients=[post.author.email])

        return redirect(comment.url)

    return render_template("add_comment.html",
                           parent=parent,
                           post=post,
                           form=form)