<commit_before>__author__ = 'tinyms'

import json
import logging as log
from tornado.web import RequestHandler
from tornado.util import import_object
from tinyms.common import Plugin,JsonEncoder
from tinyms.point import IAjax, IApi
from tinyms.orm import SessionFactory
from tinyms.widgets import DataTableModule

class IRequest(RequestHandler): pass

class DataTableHandler(IRequest):
    def post(self, id):
        name = DataTableModule.__entity_mapping__.get(id)
        entity = import_object(name)
        cnn = SessionFactory.new()
        ds = cnn.query(entity).all()
        self.set_header("Content-Type", "text/json;charset=utf-8")
        results = dict()
        results["sEcho"] = self.get_argument("sEcho")
        results["iTotalRecords"] = len(ds)
        results["iTotalDisplayRecords"] = len(ds)
        results["aaData"] = [item.dict() for item in ds]
        log.info(results)
        self.write(json.dumps(results,cls=JsonEncoder))

class ApiHandler(IRequest):
    def get(self, class_full_name, method_name):
        self.req(class_full_name, method_name)

    def post(self, class_full_name, method_name):
        self.req(class_full_name, method_name)

    def req(self, class_full_name, method_name):
        """
        Url: localhost/api/module.class/method
        :param class_full_name:
        :return:
        """
        #ver = self.get_argument("ver")
        self.set_header("Content-Type", "text/json;charset=utf-8")
        if not class_full_name:
            self.write("Class Name Require.")
        else:<commit_msg>ORM Pack<commit_after>__author__ = 'tinyms'

import json
import logging as log
from tornado.web import RequestHandler
from tornado.util import import_object
from sqlalchemy import func
from tinyms.common import Plugin,JsonEncoder,Utils
from tinyms.point import IAjax, IApi
from tinyms.orm import SessionFactory
from tinyms.widgets import DataTableModule

class IRequest(RequestHandler): pass

class DataTableHandler(IRequest):
    def post(self, id):
        name = DataTableModule.__entity_mapping__.get(id)
        entity = import_object(name)

        self.set_header("Content-Type", "text/json;charset=utf-8")
        display_start = Utils.parse_int(self.get_argument("iDisplayStart"))
        display_length = Utils.parse_int(self.get_argument("iDisplayLength"))
        cols_num = self.get_argument("iColumns")
        gloabal_search_fieldname = self.get_argument("sSearch")
        print(display_start,display_length,cols_num,gloabal_search_fieldname)
        cnn = SessionFactory.new()
        nums = cnn.query(func.count(entity.id)).one()
        ds = cnn.query(entity).offset(display_start).limit(display_length)
        results = dict()
        results["sEcho"] = self.get_argument("sEcho")
        results["iTotalRecords"] = nums[0]
        results["iTotalDisplayRecords"] = nums[0]
        results["aaData"] = [item.dict() for item in ds]
        log.info(results)
        self.write(json.dumps(results,cls=JsonEncoder))

class ApiHandler(IRequest):
    def get(self, class_full_name, method_name):
        self.req(class_full_name, method_name)

    def post(self, class_full_name, method_name):
        self.req(class_full_name, method_name)

    def req(self, class_full_name, method_name):
        """
        Url: localhost/api/module.class/method
        :param class_full_name:
        :return:
        """
        #ver = self.get_argument("ver")
        self.set_header("Content-Type", "text/json;charset=utf-8")
        if not class_full_name:
            self.write("Class Name Require.")
        else:
{'fraction_non_alphanumeric': 0.11052190901479207, 'fraction_numerical': 0.0016745743790120011, 'mean_word_length': 3.4246913580246914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '53699', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1086, 'n_words': 217}