Fixed stupid bug in i18n and sessions
This commit is contained in:
parent
ffb541ead2
commit
12de6426d1
4 changed files with 72 additions and 33 deletions
|
|
@ -40,7 +40,9 @@ class I18n:
|
|||
|
||||
s=get_session()
|
||||
|
||||
if s!=None:
|
||||
if s==None:
|
||||
|
||||
s={}
|
||||
|
||||
s['lang']=s.get('lang', I18n.default_lang)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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__)
|
||||
|
|
|
|||
|
|
@ -3,42 +3,47 @@ from importlib import import_module
|
|||
from bottle import route, get, post, run, default_app, abort, request, static_file, load
|
||||
from settings import config, modules
|
||||
from beaker.middleware import SessionMiddleware
|
||||
from mimetypes import guess_type
|
||||
|
||||
#Prepare links for static.
|
||||
#WARNING: only use this feature in development, not in production.
|
||||
|
||||
#def create_app():
|
||||
|
||||
workdir=os.getcwd()
|
||||
arr_module_path={}
|
||||
|
||||
if config.yes_static==True:
|
||||
|
||||
@route('/media/<filename:path>')
|
||||
def send_static(filename):
|
||||
return static_file(filename, root='themes/'+config.theme+'/media/')
|
||||
mimetype=guess_type(workdir+'/themes/'+config.theme+'/media/'+filename)
|
||||
return static_file(filename, root=workdir+'/themes/'+config.theme+'/media/', mimetype=mimetype)
|
||||
|
||||
def add_func_static_module(module):
|
||||
#def add_func_static_module(module):
|
||||
|
||||
@route('/mediafrom/<module>/<filename:path>')
|
||||
def send_static_module(module, filename):
|
||||
@route('/mediafrom/<module>/<filename:path>')
|
||||
def send_static_module(module, filename):
|
||||
|
||||
path_module=arr_module_path[module]+'/media/'
|
||||
path_module=arr_module_path[module]+'/media/'
|
||||
|
||||
file_path_module=path_module+filename
|
||||
file_path_module=path_module+filename
|
||||
|
||||
path='themes/'+config.theme+'/media/'+module
|
||||
path=workdir+'/themes/'+config.theme+'/media/'+module
|
||||
|
||||
file_path=path+filename
|
||||
file_path=path+filename
|
||||
|
||||
if os.path.isfile(file_path):
|
||||
return static_file(filename, root=path)
|
||||
if os.path.isfile(file_path):
|
||||
mimetype=guess_type(path+'/'+filename)
|
||||
return static_file(filename, root=path)
|
||||
|
||||
else:
|
||||
return static_file(filename, root=path_module)
|
||||
else:
|
||||
mimetype=guess_type(path_module+'/'+filename)
|
||||
return static_file(filename, root=path_module)
|
||||
"""
|
||||
else:
|
||||
|
||||
def add_func_static_module(module):
|
||||
pass
|
||||
"""
|
||||
|
||||
routes={}
|
||||
|
||||
|
|
@ -58,7 +63,8 @@ for module in config.modules:
|
|||
|
||||
dir_controllers=os.listdir(controller_base)
|
||||
|
||||
add_func_static_module(controller_base)
|
||||
#add_func_static_module(controller_base)
|
||||
|
||||
|
||||
"""
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue