Fixed stupid bug in i18n and sessions

This commit is contained in:
Antonio de la Rosa 2016-03-25 03:27:43 +01:00
parent ffb541ead2
commit 12de6426d1
4 changed files with 72 additions and 33 deletions

View file

@ -40,7 +40,9 @@ class I18n:
s=get_session()
if s!=None:
if s==None:
s={}
s['lang']=s.get('lang', I18n.default_lang)

View file

@ -33,7 +33,7 @@ class ptemplate:
show_basic_template=True
def __init__(self, module):
def __init__(self, module, cache_enabled=True, cache_impl='', cache_args={}):
ext=module[len(module)-3:]
@ -43,10 +43,22 @@ class ptemplate:
self.autoescape_ext=('html', 'htm', 'xml', 'phtml')
self.cache_enabled=cache_enabled
self.cache_impl=cache_impl
self.cache_args=cache_args
self.module_directory="./tmp/modules"
self.env=self.env_theme(module)
self.filters={}
#Place where templates contexts is loaded
self.templates={}
#Adding basic filters for urls
self.add_filter(make_url)
@ -114,22 +126,34 @@ class ptemplate:
#Standard templates
#print(standard_templates)
return TemplateLookup(directories=[theme_templates, module_templates, standard_templates], default_filters=['h'], input_encoding='utf-8', encoding_errors='replace')
return TemplateLookup(directories=[theme_templates, module_templates, standard_templates], default_filters=['h'], input_encoding='utf-8', encoding_errors='replace', cache_enabled=self.cache_enabled, cache_impl=self.cache_impl, cache_args=self.cache_args, module_directory=self.module_directory)
#, cache_enabled=self.cache_enabled, cache_impl=self.cache_impl, cache_args=self.cache_args
#return Environment(autoescape=self.guess_autoescape, auto_reload=True, loader=FileSystemLoader([theme_templates, module_templates]))
def load_templates(self, template_files):
for template_file in template_files:
self.templates[template_file]=self.env.get_template(template_file)
def load_template(self, template_file, **arguments):
template = self.env.get_template(template_file)
#Will be nice add hooks here
#z = x.copy()
arguments.update(self.filters)
#arguments['make_media_url']=make_media_url
return template.render(**arguments)
def render_template(self, template_file, **arguments):
arguments['make_media_url']=make_media_url
return self.templates[template_file].render(**arguments)
def add_filter(self, filter_name):
self.filters[filter_name.__name__]=filter_name

View file

@ -1,9 +1,9 @@
#!/usr/bin/python
from jinja2 import Template, Environment, FileSystemLoader
from citoplasma.urls import make_url, make_media_url, make_media_url_module, add_get_parameters
from citoplasma.i18n import I18n
from citoplasma.sessions import get_session
from paramecio.citoplasma.urls import make_url, make_media_url, make_media_url_module, add_get_parameters
from paramecio.citoplasma.i18n import I18n
from paramecio.citoplasma.sessions import get_session
from settings import config
# Preparing envs for views of modules, and views of
@ -62,9 +62,11 @@ class ptemplate:
def env_theme(self, module):
theme_templates='themes/'+config.theme+'/templates'
#standard_templates=path.dirname(__file__)+'/templates'
module_templates=config.base_modules+'/'+module+'/templates'
module_templates=module+'/templates'
theme_templates='themes/'+config.theme+'/templates'
return Environment(autoescape=self.guess_autoescape, auto_reload=True, loader=FileSystemLoader([theme_templates, module_templates]))
@ -107,6 +109,8 @@ class HeaderHTML:
for js in HeaderHTML.js:
final_js.append('<script language="Javascript" src="'+make_media_url('js/'+js)+'"></script>')
HeaderHTML.js=[]
return "\n".join(final_js)
def css_home():
@ -116,6 +120,8 @@ class HeaderHTML:
for css in HeaderHTML.css:
final_css.append('<link href="'+make_media_url('css/'+css)+'" rel="stylesheet" type="text/css"/>')
HeaderHTML.css=[]
return "\n".join(final_css)
@ -170,3 +176,4 @@ def show_flash_message():
return message
standard_t=ptemplate(__file__)