<commit_before>import os.path
import sys
import cStringIO
import xml.etree.cElementTree as ET
import HTMLParser
import json

from collections import defaultdict
from jinja2 import Template
from jinja2 import FileSystemLoader
from jinja2.environment import Environment

from dummy_data_layout import LAYOUT_SCHEMA
from service_api import service_gateway_get
from config import CACHED_LAYOUT

DEFINED_VIEWS = [
    '2163152', # Facepage
    '2163153', # Status
    '2163154', # Related
    '2163156', # Dashboard
    # '2163810', # Dashboard 2,
    '2163157', # Command
    '2163158', # Direct Command
]

class LayoutApi(object):
    @staticmethod
    def get_new_layout_schema():
        layout_schema = service_gateway_get('directory', 'get_ui_specs', params={'user_id': 'tboteler'})
        return layout_schema

    # Brute force method to quickly experiment with different rendering strategies
    # with CSS rules, etc. Optimizations/refactoring will be underway soon.
    @staticmethod
    def process_layout(layout_schema=None, interactions=None):
        env = Environment()
        env.loader = FileSystemLoader('templates')
        tmpl_unparsed = env.get_template('ion_ux.html').render()
        tmpl = ET.fromstring(tmpl_unparsed.encode('utf-8'))

        # Body element for appending scripts/templates
        body_elmt = tmpl.find('body')

        layout_schema = LayoutApi.get_new_layout_schema()

        resource_types = []
        metadata_processed = []
        
        # Do not create HTML elmts for subattributes
        excluded_sub_attributes = ['table_ooi', 'chart_ooi']
        
        for view_id in DEFINED_VIEWS:
            view = layout_schema['spec']['elements'][view_id] 
            script_elmt = ET.SubElement(body_elmt, 'script')
            script_elmt.set('id', view_id)
            script_elmt.set('type', 'text/template')

            # BEGIN BASIC PAGE STRUCTURE 
            # Creating page structure via Twitter Bootstrap
            # conventions. This will be optimized.

            # Fluid row to hold page heading<commit_msg>When deployed to a server, accessing the templates files with relative path were generating errors. Update the code to use absolute file path.<commit_after>import os.path
import sys
import cStringIO
import xml.etree.cElementTree as ET
import HTMLParser
import json

from collections import defaultdict
from jinja2 import Template
from jinja2 import FileSystemLoader
from jinja2.environment import Environment

from dummy_data_layout import LAYOUT_SCHEMA
from service_api import service_gateway_get
from config import CACHED_LAYOUT

DEFINED_VIEWS = [
    '2163152', # Facepage
    '2163153', # Status
    '2163154', # Related
    '2163156', # Dashboard
    # '2163810', # Dashboard 2,
    '2163157', # Command
    '2163158', # Direct Command
]

class LayoutApi(object):
    @staticmethod
    def get_new_layout_schema():
        layout_schema = service_gateway_get('directory', 'get_ui_specs', params={'user_id': 'tboteler'})
        return layout_schema

    # Brute force method to quickly experiment with different rendering strategies
    # with CSS rules, etc. Optimizations/refactoring will be underway soon.
    @staticmethod
    def process_layout(layout_schema=None, interactions=None):
        env = Environment()
        env.loader = FileSystemLoader(os.environ['PORTAL_ROOT']+'templates')
        tmpl_unparsed = env.get_template('ion_ux.html').render()
        tmpl = ET.fromstring(tmpl_unparsed.encode('utf-8'))

        # Body element for appending scripts/templates
        body_elmt = tmpl.find('body')

        layout_schema = LayoutApi.get_new_layout_schema()

        resource_types = []
        metadata_processed = []
        
        # Do not create HTML elmts for subattributes
        excluded_sub_attributes = ['table_ooi', 'chart_ooi']
        
        for view_id in DEFINED_VIEWS:
            view = layout_schema['spec']['elements'][view_id] 
            script_elmt = ET.SubElement(body_elmt, 'script')
            script_elmt.set('id', view_id)
            script_elmt.set('type', 'text/template')

            # BEGIN BASIC PAGE STRUCTURE 
            # Creating page structure via Twitter Bootstrap
            # conventions. This will be optimized.

            # Fluid row to hold page heading
{'fraction_non_alphanumeric': 0.08253894443152755, 'fraction_numerical': 0.025110439432690073, 'mean_word_length': 3.1766990291262136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2168798', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1228, 'n_words': 335}