Esempio n. 1
0
 def get(self, topic_id):
     topic_id = int(topic_id)
     page = force_int(self.get_argument('page', 0), 0)
     topic = Topic.get(id=topic_id)
     if not topic:
         raise tornado.web.HTTPError(404)
     category = self.get_argument('category', None)
     if not category:
         category = 'all'
     if category == 'all':
         reply_count = topic.reply_count
         url = topic.url
     elif category == 'hot':
         reply_count = orm.count(
             topic.get_replies(page=None, category=category))
         url = topic.url + '?category=hot'
     page_count = (reply_count + config.reply_paged -
                   1) // config.reply_paged
     if page == 0:
         page = page_count
     replies = topic.get_replies(page=page, category=category)
     form = ReplyForm()
     return self.render("topic/index.html",
                        topic=topic,
                        replies=replies,
                        form=form,
                        category=category,
                        page=page,
                        page_count=page_count,
                        url=url)
Esempio n. 2
0
 def put(self, topic_id):
     topic_id = int(topic_id)
     topic = Topic.get(id=topic_id)
     if not topic:
         raise tornado.web.HTTPError(404)
     action = self.get_argument('action', None)
     user = self.current_user
     if not action:
         result = {'status': 'info', 'message': '需要 action 参数'}
     if action == 'up':
         if topic.user_id != user.id:
             result = user.up(topic_id=topic_id)
         else:
             result = {'status': 'info', 'message': '不能为自己的主题投票'}
     if action == 'down':
         if topic.user_id != user.id:
             result = user.down(topic_id=topic_id)
         else:
             result = {'status': 'info', 'message': '不能为自己的主题投票'}
     if action == 'collect':
         result = user.collect(topic_id=topic_id)
     if action == 'thank':
         result = user.thank(topic_id=topic_id)
     if action == 'report':
         result = user.report(topic_id=topic_id)
     if self.is_ajax:
         return self.write(result)
     else:
         self.flash_message(**result)
         return self.redirect_next_url()
Esempio n. 3
0
 def put(self, topic_id):
     topic_id = int(topic_id)
     topic = Topic.get(id=topic_id)
     if not topic:
         raise tornado.web.HTTPError(404)
     action = self.get_argument('action', None)
     user = self.current_user
     if not action:
         result = {'status': 'info', 'message':
                   '需要 action 参数'}
     if action == 'up':
         if topic.user_id != user.id:
             result = user.up(topic_id=topic_id)
         else:
             result = {'status': 'info', 'message':
                       '不能为自己的主题投票'}
     if action == 'down':
         if topic.user_id != user.id:
             result = user.down(topic_id=topic_id)
         else:
             result = {'status': 'info', 'message':
                       '不能为自己的主题投票'}
     if action == 'collect':
         result = user.collect(topic_id=topic_id)
     if action == 'thank':
         result = user.thank(topic_id=topic_id)
     if action == 'report':
         result = user.report(topic_id=topic_id)
     if self.is_ajax:
         return self.write(result)
     else:
         self.flash_message(**result)
         return self.redirect_next_url()
Esempio n. 4
0
 def get(self, topic_id):
     topic = Topic.get(id=topic_id)
     if not topic:
         return self.redirect_next_url()
     if not topic.histories:
         return self.redirect(topic.url)
     return self.render("topic/history.html",
                        topic=topic, histories=topic.histories)
Esempio n. 5
0
 def get(self, topic_id):
     topic = Topic.get(id=topic_id)
     if not topic:
         return self.redirect_next_url()
     if not topic.histories:
         return self.redirect(topic.url)
     return self.render("topic/history.html",
                        topic=topic, histories=topic.histories)
Esempio n. 6
0
 def get(self, topic_id):
     topic = Topic.get(id=topic_id)
     if topic and\
        (topic.author == self.current_user or self.current_user.is_admin):
         selected = topic.node.name
     else:
         return self.redirect_next_url()
     choices = Node.get_node_choices()
     kwargs = {'node_name': [selected], 'title': [topic.title],
               'content': [topic.content]}
     form = TopicForm.init(choices=choices, selected=selected, **kwargs)
     return self.render("topic/create.html", form=form, node=topic.node)
Esempio n. 7
0
 def get(self, topic_id):
     topic = Topic.get(id=topic_id)
     if topic and\
        (topic.author == self.current_user or self.current_user.is_admin):
         selected = topic.node.name
     else:
         return self.redirect_next_url()
     choices = Node.get_node_choices()
     kwargs = {'node_name': [selected], 'title': [topic.title],
               'content': [topic.content]}
     form = TopicForm.init(choices=choices, selected=selected, **kwargs)
     return self.render("topic/create.html", form=form, node=topic.node)
Esempio n. 8
0
    def post(self):
        page = int(self.get_argument('page', 1))
        category = self.get_argument('category', 'index')
        topic_id = int(self.get_argument('topic_id', 0))
        topic = Topic.get(id=topic_id)
        if not topic_id:
            result = {'status': 'error', 'message': '无此主题,不能创建评论'}
            if self.is_ajax:
                return self.write(result)
            else:
                self.flash_message(**result)
                return self.redirect_next_url()
        user = self.current_user
        form = ReplyForm(self.request.arguments)
        if form.validate():
            reply = form.save(user=user, topic=topic)
            reply.put_notifier()
            result = {
                'status': 'success',
                'message': '评论创建成功',
                'content': reply.content,
                'name': reply.author.name,
                'nickname': reply.author.nickname,
                'author_avatar': reply.author.get_avatar(size=48),
                'author_url': reply.author.url,
                'author_name': reply.author.name,
                'author_nickname': reply.author.nickname,
                'reply_url': reply.url,
                'created': reply.created,
                'id': reply.id,
                'floor': reply.floor
            }
            if self.is_ajax:
                return self.write(result)
            self.flash_message(**result)
            return self.redirect(topic.url)

        reply_count = topic.reply_count
        page_count = (reply_count + config.reply_paged -
                      1) // config.reply_paged
        replies = topic.get_replies(page=page, category=category)
        data = dict(form=form,
                    topic=topic,
                    replies=replies,
                    category=category,
                    page=page,
                    page_count=page_count,
                    url=topic.url)
        return self.send_result_and_render(form.result, "topic/index.html",
                                           data)
Esempio n. 9
0
 def delete(self, topic_id):
     topic = Topic.get(id=topic_id)
     if not topic:
         return self.redirect_next_url()
     subject = "主题删除通知 - " + config.site_name
     template = (
         '<p>尊敬的 <strong>{nickname}</strong> 您好!</p>'
         '<p>您的主题 <strong>「{topic_title}」</strong>'
         '由于违反社区规定而被删除,我们以邮件的形式给您进行了备份,备份数据如下:</p>'
         '<div class="content">{content}</div>'
     )
     content = template.format(
         nickname=topic.author.nickname,
         topic_title=topic.title,
         content=topic.content
     )
     self.send_email(self, topic.author.email, subject, content)
     replies = topic.replies
     users = []
     content_dict = {}
     for reply in replies:
         if reply.author not in users:
             users.append(reply.author)
             content = '<li>' + reply.content + '</li>'
         else:
             content = content_dict.get(reply.author.name)
             content += '<li>' + reply.content + '</li>'
         content_dict.update({reply.author.name: content})
     for name, content in content_dict.iteritems():
         user = User.get(name=name)
         subject = "评论删除通知 - " + config.site_name
         template = (
             '<p>尊敬的 <strong>{nickname}</strong> 您好!</p>'
             '<p>主题 <strong>「{topic_title}」</strong>'
             '由于某些原因被删除,您在此主题下的评论收到了牵连,遂给您以邮件的形式进行了备份,备份数据如下:</p>'
             '<ul class="content">{content}</ul>'
         )
         content = template.format(
             nickname=user.nickname,
             topic_title=topic.title,
             content=content
         )
         self.send_email(self, user.email, subject, content)
     topic.delete()
     result = {'status': 'success', 'message': '已成功删除'}
     return self.write(result)
Esempio n. 10
0
 def delete(self, topic_id):
     topic = Topic.get(id=topic_id)
     if not topic:
         return self.redirect_next_url()
     subject = "主题删除通知 - " + config.site_name
     template = (
         '<p>尊敬的 <strong>{nickname}</strong> 您好!</p>'
         '<p>您的主题 <strong>「{topic_title}」</strong>'
         '由于违反社区规定而被删除,我们以邮件的形式给您进行了备份,备份数据如下:</p>'
         '<div class="content">{content}</div>'
     )
     content = template.format(
         nickname=topic.author.nickname,
         topic_title=topic.title,
         content=topic.content
     )
     self.send_email(self, topic.author.email, subject, content)
     replies = topic.replies
     users = []
     content_dict = {}
     for reply in replies:
         if reply.author not in users:
             users.append(reply.author)
             content = '<li>' + reply.content + '</li>'
         else:
             content = content_dict.get(reply.author.name)
             content += '<li>' + reply.content + '</li>'
         content_dict.update({reply.author.name: content})
     for name, content in content_dict.items():
         user = User.get(name=name)
         subject = "评论删除通知 - " + config.site_name
         template = (
             '<p>尊敬的 <strong>{nickname}</strong> 您好!</p>'
             '<p>主题 <strong>「{topic_title}」</strong>'
             '由于某些原因被删除,您在此主题下的评论收到了牵连,遂给您以邮件的形式进行了备份,备份数据如下:</p>'
             '<ul class="content">{content}</ul>'
         )
         content = template.format(
             nickname=user.nickname,
             topic_title=topic.title,
             content=content
         )
         self.send_email(self, user.email, subject, content)
     topic.delete()
     result = {'status': 'success', 'message': '已成功删除'}
     return self.write(result)
Esempio n. 11
0
 def post(self, topic_id):
     topic = Topic.get(id=topic_id)
     if not topic or (topic.author != self.current_user and not self.current_user.is_admin):
         return self.redirect_next_url()
     user = self.current_user
     form = TopicForm(self.request.arguments)
     if form.validate():
         topic = form.save(user=user, topic=topic)
         topic.put_notifier()
         result = {'status': 'success', 'message': '主题修改成功',
                   'topic_url': topic.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(**result)
         return self.redirect(topic.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("topic/create.html", form=form, node=topic.node)
Esempio n. 12
0
 def post(self, topic_id):
     topic = Topic.get(id=topic_id)
     if not topic or (topic.author != self.current_user and not self.current_user.is_admin):
         return self.redirect_next_url()
     user = self.current_user
     form = TopicForm(self.request.arguments)
     if form.validate():
         topic = form.save(user=user, topic=topic)
         topic.put_notifier()
         result = {'status': 'success', 'message': '主题修改成功',
                   'topic_url': topic.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(**result)
         return self.redirect(topic.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("topic/create.html", form=form, node=topic.node)
Esempio n. 13
0
    def post(self):
        page = int(self.get_argument('page', 1))
        category = self.get_argument('category', 'index')
        topic_id = int(self.get_argument('topic_id', 0))
        topic = Topic.get(id=topic_id)
        if not topic_id:
            result = {'status': 'error', 'message': '无此主题,不能创建评论'}
            if self.is_ajax:
                return self.write(result)
            else:
                self.flash_message(**result)
                return self.redirect_next_url()
        user = self.current_user
        form = ReplyForm(self.request.arguments)
        if form.validate():
            reply = form.save(user=user, topic=topic)
            reply.put_notifier()
            result = {'status': 'success', 'message': '评论创建成功',
                      'content': reply.content, 'name': reply.author.name,
                      'nickname': reply.author.nickname, 'author_avatar':
                      reply.author.get_avatar(size=48), 'author_url':
                      reply.author.url, 'author_name': reply.author.name,
                      'author_nickname': reply.author.nickname,
                      'reply_url': reply.url, 'created': reply.created,
                      'id': reply.id, 'floor': reply.floor}
            if self.is_ajax:
                return self.write(result)
            self.flash_message(**result)
            return self.redirect(topic.url)

        reply_count = topic.reply_count
        page_count = (reply_count + config.reply_paged - 1) // config.reply_paged
        replies = topic.get_replies(page=page, category=category)
        data = dict(form=form, topic=topic, replies=replies, category=category, page=page, page_count=page_count,
                    url=topic.url)
        return self.send_result_and_render(form.result, "topic/index.html", data)
Esempio n. 14
0
 def get(self, topic_id):
     topic_id = int(topic_id)
     page = force_int(self.get_argument('page', 0), 0)
     topic = Topic.get(id=topic_id)
     if not topic:
         raise tornado.web.HTTPError(404)
     category = self.get_argument('category', None)
     if not category:
         category = 'all'
     if category == 'all':
         reply_count = topic.reply_count
         url = topic.url
     elif category == 'hot':
         reply_count = orm.count(topic.get_replies(page=None,
                                                   category=category))
         url = topic.url + '?category=hot'
     page_count = (reply_count + config.reply_paged - 1) // config.reply_paged
     if page == 0:
         page = page_count
     replies = topic.get_replies(page=page, category=category)
     form = ReplyForm()
     return self.render("topic/index.html", topic=topic, replies=replies,
                        form=form, category=category, page=page,
                        page_count=page_count, url=url)