#!/usr/bin/python
# -*- coding: UTF-8 -*-

from flask import session, render_template
import jinja2
import json

import config

from utils.db import get_account_type_id_name

def render_jinja_html( template_loc, file_name, **context ):
    return jinja2.Environment( 
        loader = jinja2.FileSystemLoader( template_loc + "/" )
    ).get_template( file_name ).render( context )

def my_render_template( *args, **kwargs ):
    kwargs[ "baseurl" ] = config.baseurl
    kwargs[ "envtype" ] = config.envtype
    kwargs[ "js" ] = config.cdnjs
    kwargs[ "css" ] = config.cdncss
    kwargs[ "session_timeout" ] = config.session_timeout
    kwargs[ "session_security_key" ] = session.get( "session_security_key" )
    kwargs[ "account_type" ] = session.get( "account_type", None )
    kwargs[ "account_type_name" ] = session.get( "account_type_name", None )
    kwargs[ "admin" ] = session.get( "account_type_name", None ) == "Administrator"
    kwargs[ "nist_file_extensions" ] = json.dumps( config.NIST_file_extensions )
    
    if session.get( "account_type", False ):
        at = get_account_type_id_name()[ session.get( "account_type" ) ]
        kwargs[ "navigation" ] = "navigations/{}.html".format( at.lower() )
    
    kwargs[ "pianosendpoint" ] = config.pianosendpoint
    
    return render_template( *args, **kwargs )
