<commit_before>from req import RequestHandler
from req import reqenv
from req import Service
import math


class WebProblemsHandler(RequestHandler):
    @reqenv
    def get(self):
        args = ["page"]
        meta = self.get_args(args)
        meta['count'] = 100
        meta["group_id"] = self.current_group
        meta["is_admin"] = 1 if 1 in self.current_group_power else 0
        ### default page is 1
        if not meta['page']:
            meta['page'] = 1
        ### if get page is not int then redirect to page 1 
        try:
            meta["page"] = int(meta["page"])
        except:
            self.redirect('/group/'+meta['group_id']+'/problems/')
            return
        ### modify page in range (1, page_count)
        err, count = yield from Service.Problem.get_problem_list_count(meta)
        page_count = max(math.ceil(count / meta['count']), 1)
        if int(meta['page']) < 1:
            self.redirect('/group/'+meta['group_id']+'/problems/')
            return
        if int(meta['page']) > page_count:
            self.redirect('/group/'+meta['group_id']+'/problems/?page='+str(page_count))
            return
        ### get data
        err, data = yield from Service.Problem.get_problem_list(meta)
        ### about pagination 
        page = {}
        page['total'] = page_count
        page['current'] = meta['page']
        page['url'] = '/group/' + meta['group_id'] + '/problems/'
        page['get'] = {}
        self.Render('./problems/problems.html', data=data, page=page)

class WebProblemHandler(RequestHandler):
    @reqenv
    def get(self, id):
        meta = {}
        meta['id'] = id
        meta['group_id'] = self.current_group
        err, data = yield from Service.Problem.get_problem(meta)
        if err:
            self.write_error(404)
        else:
            if int(data['visible']) == 2:
                self.Render('./problems/problem.html', data=data)
            elif int(data['group_id']) == int(meta['group_id']) and int(data['visible']==1):
                self.Render('./problems/problem.html', data=data)
            else:
                self.write_error(403)

        


class WebProblemEditHandler(RequestHandler):
    @reqenv
    def get(self, id, action = None):
        meta = {}
        meta['id'] = id
        meta['group_id'] = self.current_group
        if not 1 in self.current_group_power:
            self.write_error(403)
            return
        err, data = yield from Service.Problem.get_problem(meta)
        if err:
            self.write_error(404)
            return
        else:
            if int(data['group_id']) != int(meta['group_id']):
                self.write_error(403)
                return<commit_msg>Update problem.py<commit_after>from req import RequestHandler
from req import reqenv
from req import Service
import math


class WebProblemsHandler(RequestHandler):
    @reqenv
    def get(self):
        args = ["page"]
        meta = self.get_args(args)
        meta['count'] = 100
        meta["group_id"] = self.current_group
        meta["is_admin"] = 1 if 1 in self.current_group_power else 0
        ### default page is 1
        if not meta['page']:
            meta['page'] = 1
        ### if get page is not int then redirect to page 1 
        try:
            meta["page"] = int(meta["page"])
        except:
            self.redirect('/group/%s/problems/'%meta['group_id'])
            return
        ### modify page in range (1, page_count)
        err, count = yield from Service.Problem.get_problem_list_count(meta)
        page_count = max(math.ceil(count / meta['count']), 1)
        if int(meta['page']) < 1:
            self.redirect('/group/%s/problems/'%meta['group_id'])
            return
        if int(meta['page']) > page_count:
            self.redirect('/group/%s/problems/?page=%s'%(meta['group_id'], str(page_count)))
            return
        ### get data
        err, data = yield from Service.Problem.get_problem_list(meta)
        ### about pagination 
        page = {}
        page['total'] = page_count
        page['current'] = meta['page']
        page['url'] = '/group/%s/problems/' % meta['group_id']
        page['get'] = {}
        self.Render('./problems/problems.html', data=data, page=page)

class WebProblemHandler(RequestHandler):
    @reqenv
    def get(self, id):
        meta = {}
        meta['id'] = id
        meta['group_id'] = self.current_group
        err, data = yield from Service.Problem.get_problem(meta)
        if err:
            self.write_error(404)
        else:
            if int(data['visible']) == 2:
                self.Render('./problems/problem.html', data=data)
            elif int(data['group_id']) == int(meta['group_id']) and int(data['visible']) == 1:
                self.Render('./problems/problem.html', data=data)
            else:
                self.write_error(403)

        


class WebProblemEditHandler(RequestHandler):
    @reqenv
    def get(self, id, action = None):
        meta = {}
        meta['id'] = id
        meta['group_id'] = self.current_group
        if 1 not in self.current_group_power:
            self.write_error(403)
            return
        err, data = yield from Service.Problem.get_problem(meta)
        if err:
            self.write_error(404)
            return
        else:
            if int(data['group_id']) != int(meta['group_id']):
                self.write_error(403)
                return
{'fraction_non_alphanumeric': 0.1382607096892811, 'fraction_numerical': 0.011031439602868174, 'mean_word_length': 2.0391061452513966, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1320220', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1564, 'n_words': 355}