Beispiel #1
0
 def get(self, reply_id):
     reply_id = int(reply_id)
     reply = Reply.get(id=reply_id)
     if not reply:
         raise tornado.web.HTTPError(404)
     action = self.get_argument('action', None)
     user = self.current_user
     if action and user:
         if action == 'up':
             if reply.user_id != user.id:
                 result = user.up(reply_id=reply.id)
             else:
                 result = {'status': 'info', 'message': '不能为自己的评论投票'}
         if action == 'down':
             if reply.user_id != user.id:
                 result = user.down(reply_id=reply.id)
             else:
                 result = {'status': 'info', 'message': '不能为自己的评论投票'}
         if action == 'collect':
             result = user.collect(reply_id=reply.id)
         if action == 'thank':
             result = user.thank(reply_id=reply.id)
         if action == 'report':
             result = user.report(reply_id=reply.id)
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect_next_url()
     return self.render("reply/index.html", reply=reply)
Beispiel #2
0
 def get(self, reply_id):
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     if not reply.histories:
         return self.redirect(reply.topic.url)
     return self.render("reply/history.html", reply=reply, histories=reply.histories)
Beispiel #3
0
 def get(self, reply_id):
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     if not reply.histories:
         return self.redirect(reply.topic.url)
     return self.render("reply/history.html", reply=reply, histories=reply.histories)
Beispiel #4
0
 def get(self, reply_id):
     reply_id = int(reply_id)
     reply = Reply.get(id=reply_id)
     if not reply:
         raise tornado.web.HTTPError(404)
     action = self.get_argument('action', None)
     user = self.current_user
     if action and user:
         if action == 'up':
             if reply.user_id != user.id:
                 result = user.up(reply_id=reply.id)
             else:
                 result = {'status': 'info', 'message':
                         '不能为自己的评论投票'}
         if action == 'down':
             if reply.user_id != user.id:
                 result = user.down(reply_id=reply.id)
             else:
                 result = {'status': 'info', 'message':
                         '不能为自己的评论投票'}
         if action == 'collect':
             result = user.collect(reply_id=reply.id)
         if action == 'thank':
             result = user.thank(reply_id=reply.id)
         if action == 'report':
             result = user.report(reply_id=reply.id)
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect_next_url()
     return self.render("reply/index.html", reply=reply)
Beispiel #5
0
    def put(self, reply_id):
        reply_id = int(reply_id)
        reply = Reply.get(id=reply_id)
        action = self.get_argument('action', None)
        user = self.current_user

        if not reply:
            raise tornado.web.HTTPError(404)

        result = {}
        if not action:
            result = {'status': 'info', 'message':
                      '缺少 action 参数'}
        if action == 'up':
            if reply.user_id != user.id:
                result = user.up(reply_id=reply.id)
            else:
                result = {'status': 'info', 'message':
                          '不能为自己的评论投票'}
        if action == 'down':
            if reply.user_id != user.id:
                result = user.down(reply_id=reply.id)
            else:
                result = {'status': 'info', 'message':
                          '不能为自己的评论投票'}
        if action == 'collect':
            result = user.collect(reply_id=reply.id)
        if action == 'thank':
            result = user.thank(reply_id=reply.id)
        if action == 'report':
            result = user.report(reply_id=reply.id)
        return self.send_result(result)
Beispiel #6
0
 def get(self, reply_id):
     reply_id = int(reply_id)
     reply = Reply.get(id=reply_id)
     if not reply:
         raise tornado.web.HTTPError(404)
     action = self.get_argument("action", None)
     user = self.current_user
     if action and user:
         if action == "up":
             if reply.user_id != user.id:
                 result = user.up(reply_id=reply.id)
             else:
                 result = {"status": "info", "message": "不能为自己的评论投票"}
         if action == "down":
             if reply.user_id != user.id:
                 result = user.down(reply_id=reply.id)
             else:
                 result = {"status": "info", "message": "不能为自己的评论投票"}
         if action == "collect":
             result = user.collect(reply_id=reply.id)
         if action == "thank":
             result = user.thank(reply_id=reply.id)
         if action == "report":
             result = user.report(reply_id=reply.id)
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect_next_url()
     return self.render("reply/index.html", reply=reply)
Beispiel #7
0
 def get(self, reply_id):
     if not self.has_permission:
         return
     reply = Reply.get(id=reply_id)
     if not reply or (reply.author != self.current_user and not self.current_user.is_admin):
         return self.redirect_next_url()
     form = ReplyForm(content=reply.content)
     return self.render("reply/edit.html", form=form, reply=reply)
Beispiel #8
0
 def get(self, reply_id):
     if not self.has_permission:
         return
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     form = ReplyForm(content=reply.content)
     return self.render("reply/edit.html", form=form, reply=reply)
Beispiel #9
0
 def get(self, reply_id):
     if not self.has_permission:
         return
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     form = ReplyForm(content=reply.content)
     return self.render("reply/edit.html", form=form, reply=reply)
Beispiel #10
0
 def get(self, reply_id):
     if not self.has_permission:
         return
     reply = Reply.get(id=reply_id)
     if not reply or (reply.author != self.current_user
                      and not self.current_user.is_admin):
         return self.redirect_next_url()
     form = ReplyForm(content=reply.content)
     return self.render("reply/edit.html", form=form, reply=reply)
Beispiel #11
0
 def post(self, reply_id):
     reply = Reply.get(id=reply_id)
     if not reply or (reply.author != self.current_user and not self.current_user.is_admin):
         return self.redirect_next_url()
     user = self.current_user
     form = ReplyForm(self.request.arguments)
     if form.validate():
         reply = form.save(user=user, topic=reply.topic, reply=reply)
         reply.put_notifier()
         result = {'status': 'success', 'message': '评论修改成功',
                   'reply_url': reply.url}
         return self.send_result(result, reply.url)
     data = dict(form=form, reply=reply)
     return self.send_result_and_render(form.result, "reply/edit.html", data)
Beispiel #12
0
 def post(self, reply_id):
     if not self.has_permission:
         return
     reply = Reply.get(id=reply_id)
     if not reply or (reply.author != self.current_user and not self.current_user.is_admin):
         return self.redirect_next_url()
     user = self.current_user
     form = ReplyForm(self.request.arguments)
     if form.validate():
         reply = form.save(user=user, topic=reply.topic, reply=reply)
         result = {"status": "success", "message": "评论修改成功", "reply_url": reply.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect(reply.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("reply/edit.html", form=form, reply=reply)
Beispiel #13
0
 def post(self, reply_id):
     if not self.has_permission:
         return
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     user = self.current_user
     form = ReplyForm(self.request.arguments)
     if form.validate():
         reply = form.save(user=user, topic=reply.topic, reply=reply)
         result = {'status': 'success', 'message': '评论修改成功',
                 'reply_url': reply.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect(reply.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("reply/edit.html", form=form, reply=reply)
Beispiel #14
0
 def post(self, reply_id):
     if not self.has_permission:
         return
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     user = self.current_user
     form = ReplyForm(self.request.arguments)
     if form.validate():
         reply = form.save(user=user, topic=reply.topic, reply=reply)
         result = {'status': 'success', 'message': '评论修改成功',
                 'reply_url': reply.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect(reply.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("reply/edit.html", form=form, reply=reply)
Beispiel #15
0
 def delete(self, reply_id):
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     subject = "评论删除通知 - " + config.site_name
     template = (
         '<p>尊敬的 <strong>%(nickname)s</strong> 您好!</p>'
         '<p>您在主题 <strong><a href="%(topic_url)s">「%(topic_title)s」</a></strong>'
         '下的评论由于违反社区规定而被删除,我们以邮件的形式给您进行了备份,备份数据如下:</p>'
         '<div class="content">%(content)s</div>'
     ) % {'nickname': reply.author.nickname,
          'topic_url': config.site_url + reply.topic.url,
          'topic_title': reply.topic.title,
          'content': reply.content}
     self.send_email(self, reply.author.email, subject, template)
     reply.remove()
     result = {'status': 'success', 'message': '已成功删除'}
     return self.send_result(result)
Beispiel #16
0
 def delete(self, reply_id):
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     subject = "评论删除通知 - " + config.site_name
     template = (
             '<p>尊敬的 <strong>%(nickname)s</strong> 您好!</p>'
             '<p>您在主题 <strong><a href="%(topic_url)s">「%(topic_title)s」</a></strong>'
             '下的评论由于违反社区规定而被删除,我们以邮件的形式给您进行了备份,备份数据如下:</p>'
             '<div class="content">%(content)s</div>'
             ) % {'nickname': reply.author.nickname,
                     'topic_url': config.site_url + reply.topic.url,
                     'topic_title': reply.topic.title,
                     'content': reply.content}
     self.send_email(self, reply.author.email, subject, template)
     reply.remove()
     result = {'status': 'success', 'message': '已成功删除'}
     return self.write(result)
Beispiel #17
0
 def get(self, reply_id):
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     reply = Reply.get(id=reply_id)
     if not reply:
         return self.redirect_next_url()
     subject = "评论删除通知 - " + config.site_name
     template = (
         "<p>尊敬的 <strong>%(nickname)s</strong> 您好!</p>"
         '<p>您在主题 <strong><a href="%(topic_url)s">「%(topic_title)s」</a></strong>'
         "下的评论由于违反社区规定而被删除,我们以邮件的形式给您进行了备份,备份数据如下:</p>"
         '<div class="content">%(content)s</div>'
     ) % {
         "nickname": reply.author.nickname,
         "topic_url": config.site_url + reply.topic.url,
         "topic_title": reply.topic.title,
         "content": reply.content,
     }
     self.send_email(self, reply.author.email, subject, template)
     reply.remove()
     result = {"status": "success", "message": "已成功删除"}
     self.flash_message(result)
     return self.redirect_next_url()
Beispiel #18
0
 def get(self, reply_id):
     reply_id = int(reply_id)
     reply = Reply.get(id=reply_id)
     if not reply:
         raise tornado.web.HTTPError(404)
     return self.render("reply/index.html", reply=reply)
Beispiel #19
0
 def get(self, reply_id):
     reply_id = int(reply_id)
     reply = Reply.get(id=reply_id)
     if not reply:
         raise tornado.web.HTTPError(404)
     return self.render("reply/index.html", reply=reply)