<commit_before>#!/usr/bin/env python

from django.template import loader, Template, Context
from django.conf import settings

class HTMLBuilder():
    def __init__(self, layers_applier, toc_applier):
        self.markup = u''
        self.sections = None
        self.tree = None
        self.layers_applier = layers_applier
        self.toc_applier = toc_applier
        
        if not settings.configured:
            settings.configure(TEMPLATE_DEBUG=False, 
                TEMPLATE_LOADERS=('django.template.loaders.filesystem.Loader',), 
                TEMPLATE_DIRS = ('templates/',))

    def generate_all_html(self):
        generate_html(self.tree[''])

    def generate_html(self):
        self.process_node(self.tree)

    def node_type(self, tree_level, parts):
        """ A node in the regulation can be part of the appendix, the interpretation 
        section or simply the normal regulation text. We style them differently, hence we 
        need to distinguish between them. """

        if tree_level > 0:
            level_two_id = parts[1]

            if level_two_id == 'Interpretations':
                return 'interpretation'
            elif level_two_id.isalpha():
                return 'appendix'
            else:
                return 'regulation'

    def process_node(self, node):
        if 'title' in node['label']:
            node['markup_title']  = node['label']['title']

        node['markup_id'] = "-".join(node['label']['parts'])
        node['tree_level'] = len(node['label']['parts']) - 1

        node['node_type'] = self.node_type(node['tree_level'], node['label']['parts'])

        if len(node['text'].strip()):
            node['marked_up'] = self.layers_applier.apply_layers(node['text'], node['markup_id'])

        toc = self.toc_applier.apply_layer(node['markup_id'])

        if toc:
            node[toc[0]] = toc[1]

        for c in node['children']:
            self.process_node(c)

    def render_markup(self, f=None):
        main_template = loader.get_template('simpler.html')
        c = Context({'tree':self.tree})
        return main_template.render(c) 

<commit_msg>Moved Django settings away from here<commit_after>#!/usr/bin/env python

from django.template import loader, Template, Context
from django.conf import settings

import settings as app_settings

class HTMLBuilder():
    def __init__(self, layers_applier, toc_applier):
        self.markup = u''
        self.sections = None
        self.tree = None
        self.layers_applier = layers_applier
        self.toc_applier = toc_applier
        
    def generate_all_html(self):
        generate_html(self.tree[''])

    def generate_html(self):
        self.process_node(self.tree)

    def node_type(self, tree_level, parts):
        """ A node in the regulation can be part of the appendix, the interpretation 
        section or simply the normal regulation text. We style them differently, hence we 
        need to distinguish between them. """

        if tree_level > 0:
            level_two_id = parts[1]

            if level_two_id == 'Interpretations':
                return 'interpretation'
            elif level_two_id.isalpha():
                return 'appendix'
            else:
                return 'regulation'

    def process_node(self, node):
        if 'title' in node['label']:
            node['markup_title']  = node['label']['title']

        node['markup_id'] = "-".join(node['label']['parts'])
        node['tree_level'] = len(node['label']['parts']) - 1

        node['node_type'] = self.node_type(node['tree_level'], node['label']['parts'])

        if len(node['text'].strip()):
            node['marked_up'] = self.layers_applier.apply_layers(node['text'], node['markup_id'])

        toc = self.toc_applier.apply_layer(node['markup_id'])

        if toc:
            node[toc[0]] = toc[1]

        for c in node['children']:
            self.process_node(c)

    def render_markup(self, f=None):
        main_template = loader.get_template('simpler.html')
        c = Context({'tree':self.tree, 
                        'GOOGLE_ANALYTICS_SITE':app_settings.GOOGLE_ANALYTICS_SITE, 
                        'GOOGLE_ANALYTICS_ID':app_settings.GOOGLE_ANALYTICS_ID})
        return main_template.render(c) 


{'fraction_non_alphanumeric': 0.12143191389798784, 'fraction_numerical': 0.002339728591483388, 'mean_word_length': 2.4615384615384617, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5816684', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1231, 'n_words': 274}