<commit_before>from tornado import auth, web, httpclient
from StringIO import StringIO
from operator import itemgetter
import logging
import magic
import zipfile
import yaml
import time
import markdown2

import db
from helper import *


class ShowGroup(myRequestHandler):
    """
    """
    @web.removeslash
    @web.authenticated
    def get(self, entity_definition_keyname=None):
        """
        Show entities page with menu.

        """
        self.require_setting('quota_entities', 'this application')
        self.require_setting('quota_size_bytes', 'this application')

        entity_definition_keyname = entity_definition_keyname.strip('/').split('/')[0]
        entity = db.Entity(user_locale=self.get_user_locale(), user_id=self.current_user.id)
        entity_definition = None
        if entity_definition_keyname:
            entity_definition = entity.get_entity_definition(entity_definition_keyname=entity_definition_keyname)

        db_connection = db.connection()
        quota_entities_used = db_connection.get('SELECT COUNT(DISTINCT entity_id) AS entities, COUNT(*) AS properties FROM property WHERE deleted IS NULL;').entities
        # quota_size_used = db_connection.get('SELECT SUM(data_length + index_length) AS size FROM information_schema.TABLES;').size
        quota_size_used = db_connection.get('SELECT SUM(file) AS size FROM file;').size

        try:
            f = open('../HISTORY.md', 'r')
            history = markdown2.markdown('## '.join(f.read().split('## ')[:4]).replace('## ', '#### '))
        except:
            history = ''



        self.render('entity/start.html',
            page_title = entity_definition[0].label_plural if entity_definition else '',
            menu = entity.get_menu(),
            show_list = True if entity_definition_keyname else False,
            entity_definition = entity_definition_keyname,
            add_definitions = entity.get_definitions_with_default_parent(entity_definition_keyname) if entity_definition_keyname else None,
            history = history,
            quota_entities = int(self.settings['quota_entities']),
            quota_entities_used = int(quota_entities_used),
            quota_size = int(self.settings['quota_size_bytes']),
            quota_size_human = GetHumanReadableBytes(self.settings['quota_size_bytes'], 0),
            quota_size_used = int(quota_size_used),
            quota_size_used_human = GetHumanReadableBytes(quota_size_used, 0)
        )

    @web.authenticated<commit_msg>Hotfix<commit_after>from tornado import auth, web, httpclient
from StringIO import StringIO
from operator import itemgetter
import logging
import magic
import zipfile
import yaml
import time
import markdown2

import db
from helper import *


class ShowGroup(myRequestHandler):
    """
    """
    @web.removeslash
    @web.authenticated
    def get(self, entity_definition_keyname=None):
        """
        Show entities page with menu.

        """
        self.require_setting('quota_entities', 'this application')
        self.require_setting('quota_size_bytes', 'this application')

        entity_definition_keyname = entity_definition_keyname.strip('/').split('/')[0]
        entity = db.Entity(user_locale=self.get_user_locale(), user_id=self.current_user.id)
        entity_definition = None
        if entity_definition_keyname:
            entity_definition = entity.get_entity_definition(entity_definition_keyname=entity_definition_keyname)

        db_connection = db.connection()
        quota_entities_used = db_connection.get('SELECT COUNT(DISTINCT entity_id) AS entities, COUNT(*) AS properties FROM property WHERE deleted IS NULL;').entities
        # quota_size_used = db_connection.get('SELECT SUM(data_length + index_length) AS size FROM information_schema.TABLES;').size
        quota_size_used = db_connection.get('SELECT SUM(filesize) AS size FROM file;').size

        try:
            f = open('../HISTORY.md', 'r')
            history = markdown2.markdown('## '.join(f.read().split('## ')[:4]).replace('## ', '#### '))
        except:
            history = ''



        self.render('entity/start.html',
            page_title = entity_definition[0].label_plural if entity_definition else '',
            menu = entity.get_menu(),
            show_list = True if entity_definition_keyname else False,
            entity_definition = entity_definition_keyname,
            add_definitions = entity.get_definitions_with_default_parent(entity_definition_keyname) if entity_definition_keyname else None,
            history = history,
            quota_entities = int(self.settings['quota_entities']),
            quota_entities_used = int(quota_entities_used),
            quota_size = int(self.settings['quota_size_bytes']),
            quota_size_human = GetHumanReadableBytes(self.settings['quota_size_bytes'], 1),
            quota_size_used = int(quota_size_used) if quota_size_used else 0,
            quota_size_used_human = GetHumanReadableBytes(quota_size_used, 1) if quota_size_used else '0B'
        )

    @web.authenticated
{'fraction_non_alphanumeric': 0.09905288082083662, 'fraction_numerical': 0.0031570639305445935, 'mean_word_length': 3.3361847733105217, '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': '6221039', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1450, 'n_words': 289}