<commit_before># -*- coding:utf-8 -*-

import json
import tornado.escape
import tornado.web
import tornado.gen
from torcms.handlers.post_handler import PostHandler
from torcms.model.post_model import MPost
from torcms.core.tools import logger
from config import router_post


class AdminPostHandler(PostHandler):
    def initialize(self):
        super(AdminPostHandler, self).initialize()

    def get(self, *args, **kwargs):
        url_str = args[0]
        if self.userinfo and self.userinfo.role[2] >= '3':
            pass
        else:
            return False
        url_arr = self.parse_url(url_str)

        if len(url_arr) == 2:
            if url_arr[0] in ['_edit']:
                self.to_edit(url_arr[1])
        else:
            return False

    def post(self, *args, **kwargs):
        url_str = args[0]
        if self.userinfo and self.userinfo.role[2] >= '3':
            pass
        else:
            return False

        url_arr = self.parse_url(url_str)

        if len(url_arr) == 2:
            if url_arr[0] in ['_edit']:
                self.update(url_arr[1])
        else:
            return False

    @tornado.web.authenticated
    def to_edit(self, post_uid):
        postinfo = MPost.get_by_uid(post_uid, )
        json_cnt = json.dumps(postinfo.extinfo, indent=True)
        self.render('man_post/admin_post.html',
                    postinfo=postinfo,
                    sig_dic=router_post,
                    userinfo=self.userinfo,
                    unescape=tornado.escape.xhtml_unescape,
                    json_cnt=json_cnt)

    @tornado.web.authenticated
    def update(self, post_uid):
        post_data = self.get_post_data()

        logger.info('admin post update: {0}'.format(post_data))

        MPost.update_kind(post_uid, post_data['kcat'])
        # MPost.update_jsonb(post_uid, ext_dic)
        self.update_category(post_uid)
<commit_msg>fix a bug.<commit_after># -*- coding:utf-8 -*-

import json
import tornado.escape
import tornado.web
import tornado.gen
from torcms.handlers.post_handler import PostHandler
from torcms.model.post_model import MPost
from torcms.core.tools import logger
from config import router_post


class AdminPostHandler(PostHandler):
    def initialize(self):
        super(AdminPostHandler, self).initialize()

    def get(self, *args, **kwargs):
        url_str = args[0]
        if self.userinfo and self.userinfo.role[1] >= '3':
            pass
        else:
            self.redirect('/')
        url_arr = self.parse_url(url_str)

        if len(url_arr) == 2:
            if url_arr[0] in ['_edit']:
                self.to_edit(url_arr[1])
        else:
            return False

    def post(self, *args, **kwargs):
        url_str = args[0]
        if self.userinfo and self.userinfo.role[1] >= '3':
            pass
        else:
            self.redirect('/')

        url_arr = self.parse_url(url_str)

        if len(url_arr) == 2:
            if url_arr[0] in ['_edit']:
                self.update(url_arr[1])
        else:
            return False

    @tornado.web.authenticated
    def to_edit(self, post_uid):
        postinfo = MPost.get_by_uid(post_uid, )
        json_cnt = json.dumps(postinfo.extinfo, indent=True)
        self.render('man_post/admin_post.html',
                    postinfo=postinfo,
                    sig_dic=router_post,
                    userinfo=self.userinfo,
                    unescape=tornado.escape.xhtml_unescape,
                    json_cnt=json_cnt)

    @tornado.web.authenticated
    def update(self, post_uid):
        post_data = self.get_post_data()

        logger.info('admin post update: {0}'.format(post_data))

        MPost.update_kind(post_uid, post_data['kcat'])
        # MPost.update_jsonb(post_uid, ext_dic)
        self.update_category(post_uid)

{'fraction_non_alphanumeric': 0.1072083879423329, 'fraction_numerical': 0.007339449541284404, 'mean_word_length': 2.0974025974025974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6255418', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1192, 'n_words': 236}