# Path: newsmeme/signals.py

# 
# Path: newsmeme/helpers.py
# def render_template(template, **context):
#     import logging
#     file_handler = logging.FileHandler('app.log')
#     current_app.logger.addHandler(file_handler)
#     current_app.logger.setLevel(logging.INFO)
#     current_app.logger.info('current theme:%s' % get_theme())
#     current_app.logger.info('template:%s' % template)
#     return render_theme_template(get_theme(), template, **context)
# 
# Path: newsmeme/permissions.py

# 
# Path: newsmeme/models/comments.py
# class Comment(db.Model):
# 
#     __tablename__ = "comments"
# 
#     PER_PAGE = 20
# 
#     query_class = CommentQuery
# 
#     id = db.Column(db.Integer, primary_key=True)
# 
#     author_id = db.Column(db.Integer,
#                           db.ForeignKey(User.id, ondelete='CASCADE'),
#                           nullable=False)
# 
#     post_id = db.Column(db.Integer,
#                         db.ForeignKey(Post.id, ondelete='CASCADE'),
#                         nullable=False)
# 
#     parent_id = db.Column(db.Integer,
#                           db.ForeignKey("comments.id", ondelete='CASCADE'))
# 
#     comment = db.Column(db.UnicodeText)
#     date_created = db.Column(db.DateTime, default=datetime.utcnow)
#     score = db.Column(db.Integer, default=1)
#     votes = db.Column(DenormalizedText)
# 
#     author = db.relation(User, innerjoin=True, lazy="joined")
# 
#     post = db.relation(Post, innerjoin=True, lazy="joined")
# 
#     parent = db.relation('Comment', remote_side=[id])
# 
#     __mapper_args__ = {'order_by' : id.asc()}
# 
#     class Permissions(Permissions):
# 
# 
#         @cached_property
#         def default(self):
#             return Permission(UserNeed(self.author_id)) & moderator
# 
#         @cached_property
#         def edit(self):
#             return self.default
# 
#         @cached_property
#         def delete(self):
#             return self.default
# 
#         @cached_property
#         def vote(self):
# 
#             needs = [UserNeed(user_id) for user_id in self.votes]
#             needs.append(UserNeed(self.author_id))
# 
#             return auth & Denial(*needs)
# 
# 
#     def __init__(self, *args, **kwargs):
#         super(Comment, self).__init__(*args, **kwargs)
#         self.votes = self.votes or set()
# 
#     @cached_property
#     def permissions(self):
#         return self.Permissions(self)
# 
#     def vote(self, user):
#         self.votes.add(user.id)
# 
#     def _url(self, _external=False):
#         return '%s#comment-%d' % (self.post._url(_external), self.id)
# 
#     @cached_property
#     def url(self):
#         return self._url()
# 
#     @cached_property
#     def permalink(self):
#         return self._url(True)
# 
#     @cached_property
#     def markdown(self):
#         return Markup(markdown(self.comment or ''))
# 
# Path: newsmeme/forms/comment.py
# class CommentForm(Form):
# 
#     comment = TextAreaField(validators=[
#                             required(message=_("Comment is required"))])
# 
#     submit = SubmitField(_("Save"))
#     cancel = SubmitField(_("Cancel"))
# 
# class CommentAbuseForm(Form):
# 
#     complaint = TextAreaField("Complaint", validators=[
#                               required(message=\
#                                        _("You must enter the details"
#                                          " of the complaint"))])
# 
# 
#     submit = SubmitField(_("Send"))
# 
# Path: newsmeme/extensions.py



from flask import Module, redirect, flash, g, jsonify, current_app
from flaskext.babel import gettext as _
from newsmeme import signals
from newsmeme.helpers import render_template
from newsmeme.permissions import auth
from newsmeme.models import Comment
from newsmeme.forms import CommentForm, CommentAbuseForm
from newsmeme.extensions import db#, mail

            message = Message(subject="Report Abuse",
                              body=body,
                              sender=g.user.email,
                              recipients=admins)

            mail.send(message)

        flash(_("Your report has been sent to the admins"), "success")

        return redirect(comment.url)

    return render_template("comment/report_abuse.html",
                           comment=comment,
                           form=form)

@comment.route("/<int:comment_id>/upvote/", methods=("POST",))
@auth.require(401)
def upvote(comment_id):
    return _vote(comment_id, 1)


@comment.route("/<int:comment_id>/downvote/", methods=("POST",))
@auth.require(401)
def downvote(comment_id):
    return _vote(comment_id, -1)


def _vote(comment_id, score):


# Path: newsmeme/signals.py

# 
# Path: newsmeme/helpers.py
# def render_template(template, **context):
#     import logging
#     file_handler = logging.FileHandler('app.log')
#     current_app.logger.addHandler(file_handler)
#     current_app.logger.setLevel(logging.INFO)
#     current_app.logger.info('current theme:%s' % get_theme())
#     current_app.logger.info('template:%s' % template)
#     return render_theme_template(get_theme(), template, **context)
# 
# Path: newsmeme/permissions.py

# 
# Path: newsmeme/models/comments.py
# class Comment(db.Model):
# 
#     __tablename__ = "comments"
# 
#     PER_PAGE = 20
# 
#     query_class = CommentQuery
# 
#     id = db.Column(db.Integer, primary_key=True)
# 
#     author_id = db.Column(db.Integer,
#                           db.ForeignKey(User.id, ondelete='CASCADE'),
#                           nullable=False)
# 
#     post_id = db.Column(db.Integer,
#                         db.ForeignKey(Post.id, ondelete='CASCADE'),
#                         nullable=False)
# 
#     parent_id = db.Column(db.Integer,
#                           db.ForeignKey("comments.id", ondelete='CASCADE'))
# 
#     comment = db.Column(db.UnicodeText)
#     date_created = db.Column(db.DateTime, default=datetime.utcnow)
#     score = db.Column(db.Integer, default=1)
#     votes = db.Column(DenormalizedText)
# 
#     author = db.relation(User, innerjoin=True, lazy="joined")
# 
#     post = db.relation(Post, innerjoin=True, lazy="joined")
# 
#     parent = db.relation('Comment', remote_side=[id])
# 
#     __mapper_args__ = {'order_by' : id.asc()}
# 
#     class Permissions(Permissions):
# 
# 
#         @cached_property
#         def default(self):
#             return Permission(UserNeed(self.author_id)) & moderator
# 
#         @cached_property
#         def edit(self):
#             return self.default
# 
#         @cached_property
#         def delete(self):
#             return self.default
# 
#         @cached_property
#         def vote(self):
# 
#             needs = [UserNeed(user_id) for user_id in self.votes]
#             needs.append(UserNeed(self.author_id))
# 
#             return auth & Denial(*needs)
# 
# 
#     def __init__(self, *args, **kwargs):
#         super(Comment, self).__init__(*args, **kwargs)
#         self.votes = self.votes or set()
# 
#     @cached_property
#     def permissions(self):
#         return self.Permissions(self)
# 
#     def vote(self, user):
#         self.votes.add(user.id)
# 
#     def _url(self, _external=False):
#         return '%s#comment-%d' % (self.post._url(_external), self.id)
# 
#     @cached_property
#     def url(self):
#         return self._url()
# 
#     @cached_property
#     def permalink(self):
#         return self._url(True)
# 
#     @cached_property
#     def markdown(self):
#         return Markup(markdown(self.comment or ''))
# 
# Path: newsmeme/forms/comment.py
# class CommentForm(Form):
# 
#     comment = TextAreaField(validators=[
#                             required(message=_("Comment is required"))])
# 
#     submit = SubmitField(_("Save"))
#     cancel = SubmitField(_("Cancel"))
# 
# class CommentAbuseForm(Form):
# 
#     complaint = TextAreaField("Complaint", validators=[
#                               required(message=\
#                                        _("You must enter the details"
#                                          " of the complaint"))])
# 
# 
#     submit = SubmitField(_("Send"))
# 
# Path: newsmeme/extensions.py



# Path: newsmeme/views/comment.py
from flask import Module, redirect, flash, g, jsonify, current_app
from flaskext.babel import gettext as _
from newsmeme import signals
from newsmeme.helpers import render_template
from newsmeme.permissions import auth
from newsmeme.models import Comment
from newsmeme.forms import CommentForm, CommentAbuseForm
from newsmeme.extensions import db#, mail


            message = Message(subject="Report Abuse",
                              body=body,
                              sender=g.user.email,
                              recipients=admins)

            mail.send(message)

        flash(_("Your report has been sent to the admins"), "success")

        return redirect(comment.url)

    return render_template("comment/report_abuse.html",
                           comment=comment,
                           form=form)

@comment.route("/<int:comment_id>/upvote/", methods=("POST",))
@auth.require(401)
def upvote(comment_id):
    return _vote(comment_id, 1)


@comment.route("/<int:comment_id>/downvote/", methods=("POST",))
@auth.require(401)
def downvote(comment_id):
    return _vote(comment_id, -1)


def _vote(comment_id, score):


    comment = Comment.query.get_or_404(comment_id)