<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time

import tornado.web
from tornado import gen
from bson.objectid import ObjectId

from . import BaseHandler
from .utils import make_content

class TopicListHandler(BaseHandler):
    def get(self):
        if not self.current_user:
            self.render('home.html')
        topics = self.db.topics.find(sort=[('last_reply_time', -1)])
        topics_count = topics.count()
        p = int(self.get_argument('p', 1))
        self.render(
            'topic/list.html',
            topics = topics,
            topics_count = topics_count,
            p = p,
        )

class TopicHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, topic_id):
        topic = self.get_topic(topic_id)
        if self.current_user:
            yield self.async_db.notifications.update({
                'topic': ObjectId(topic_id),
                'to': self.current_user['name_lower']
            }, {'$set': {'read': True}}, multi = True)
            if 'read' in topic:
                yield self.async_db.topics.update(
                    {'_id': ObjectId(topic_id)},
                    {'$addToSet': {'read': self.current_user['name_lower']}}
                )
            else:
                yield self.async_db.topics.update(
                    {'_id': ObjectId(topic_id)},
                    {'$set': {'read': [self.current_user['name_lower']]}}
                )
        replies = self.db.replies.find({'topic': topic_id},
                                       sort=[('index', 1)])
        replies_count = replies.count()
        p = int(self.get_argument('p', 1))
        if p < 1:
            p = 1

        self.render('topic/topic.html',
                    topic = topic,
                    replies = replies,
                    replies_count = replies_count,
                    p = p,
        )

class CreateHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self):
        node_name = self.get_argument("node", "")
        self.render('topic/create.html', node_name = node_name)

    @tornado.web.authenticated
    @gen.coroutine
    def post(self):
        node = self.get_argument("node", None)
        title = self.get_argument('title', None)
        content = self.get_argument('content', None)
        if not (node and title and content):
            self.send_message('请完整填写信息喵')
        if len(title) > 100:<commit_msg>fix a bug<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time

import tornado.web
from tornado import gen
from bson.objectid import ObjectId

from . import BaseHandler
from .utils import make_content

class TopicListHandler(BaseHandler):
    def get(self):
        if not self.current_user:
            self.render('home.html')
        topics = self.db.topics.find(sort=[('last_reply_time', -1)])
        topics_count = topics.count()
        p = int(self.get_argument('p', 1))
        self.render(
            'topic/list.html',
            topics = topics,
            topics_count = topics_count,
            p = p,
        )

class TopicHandler(BaseHandler):
    @tornado.web.authenticated
    @gen.coroutine
    def get(self, topic_id):
        topic = self.get_topic(topic_id)
        if self.current_user:
            yield self.async_db.notifications.update({
                'topic': ObjectId(topic_id),
                'to': self.current_user['name_lower']
            }, {'$set': {'read': True}}, multi = True)
            if 'read' in topic:
                yield self.async_db.topics.update(
                    {'_id': ObjectId(topic_id)},
                    {'$addToSet': {'read': self.current_user['name_lower']}}
                )
            else:
                yield self.async_db.topics.update(
                    {'_id': ObjectId(topic_id)},
                    {'$set': {'read': [self.current_user['name_lower']]}}
                )
        replies = self.db.replies.find({'topic': ObjectId(topic_id)},
                                       sort=[('index', 1)])
        replies_count = replies.count()
        p = int(self.get_argument('p', 1))
        if p < 1:
            p = 1

        self.render('topic/topic.html',
                    topic = topic,
                    replies = replies,
                    replies_count = replies_count,
                    p = p,
        )

class CreateHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self):
        node_name = self.get_argument("node", "")
        self.render('topic/create.html', node_name = node_name)

    @tornado.web.authenticated
    @gen.coroutine
    def post(self):
        node = self.get_argument("node", None)
        title = self.get_argument('title', None)
        content = self.get_argument('content', None)
        if not (node and title and content):
            self.send_message('请完整填写信息喵')
        if len(title) > 100:
{'fraction_non_alphanumeric': 0.127944760357433, 'fraction_numerical': 0.004061738424045491, 'mean_word_length': 1.7967064168086315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3901367', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1465, 'n_words': 293}