示例#1
0
文件: reply.py 项目: ywmmmw/collipa
 def save(self, user, topic, reply=None):
     data = self.data
     content = str(data.get('content'))
     data.update({
         'user_id': user.id,
         'topic_id': topic.id,
         'content': strip_xss_tags(content)
     })
     if reply:
         category = 'edit'
         pre_content = reply.content
         cur_content = data.get('content')
         changed = 0
         if pre_content != cur_content:
             diff_content = ghdiff.diff(pre_content, cur_content, css=None)
             changed = 1
         if changed == 1:
             reply.content = cur_content
             History(user_id=user.id,
                     content=diff_content,
                     reply_id=reply.id).save()
         else:
             return reply
     else:
         category = 'create'
         reply = Reply(**data)
     return reply.save(category=category)
示例#2
0
文件: reply.py 项目: wbbim/collipa
    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)
示例#3
0
文件: reply.py 项目: wbbim/collipa
 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)
示例#4
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)
示例#5
0
 def get(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()
     form = ReplyForm(content=reply.content)
     return self.render("reply/edit.html", form=form, reply=reply)
示例#6
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)
示例#7
0
文件: reply.py 项目: wbbim/collipa
 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)
示例#8
0
 def save(self, user, topic, reply=None):
     data = self.data
     content = str(data.get('content'))
     data.update({'user_id': user.id, 'topic_id': topic.id,
                  'content': strip_xss_tags(content)})
     if reply:
         category = 'edit'
         pre_content = reply.content
         cur_content = data.get('content')
         changed = 0
         if pre_content != cur_content:
             diff_content = ghdiff.diff(pre_content, cur_content, css=None)
             changed = 1
         if changed == 1:
             reply.content = cur_content
             History(user_id=user.id, content=diff_content,
                     reply_id=reply.id).save()
         else:
             return reply
     else:
         category = 'create'
         reply = Reply(**data)
     return reply.save(category=category)
示例#9
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)
示例#10
0
文件: reply.py 项目: wbbim/collipa
 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)
示例#11
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}</strong> 您好!</p>'
         '<p>您在主题 <strong><a href="{topic_url}">「{topic_title}」</a></strong>'
         '下的评论由于违反社区规定而被删除,我们以邮件的形式给您进行了备份,备份数据如下:</p>'
         '<div class="content">{content}</div>')
     content = template.format(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, content)
     reply.delete()
     result = {'status': 'success', 'message': '已成功删除'}
     return self.send_result(result)
示例#12
0
文件: reply.py 项目: wbbim/collipa
 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)
示例#13
0
文件: reply.py 项目: iselu/collipa
 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}</strong> 您好!</p>'
         '<p>您在主题 <strong><a href="{topic_url}">「{topic_title}」</a></strong>'
         '下的评论由于违反社区规定而被删除,我们以邮件的形式给您进行了备份,备份数据如下:</p>'
         '<div class="content">{content}</div>'
     )
     content = template.format(
         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, content)
     reply.delete()
     result = {'status': 'success', 'message': '已成功删除'}
     return self.send_result(result)
示例#14
0
文件: reply.py 项目: wbbim/collipa
 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)
示例#15
0
文件: reply.py 项目: wbbim/collipa
 def get(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()
     form = ReplyForm(content=reply.content)
     return self.render("reply/edit.html", form=form, reply=reply)
示例#16
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)