changement de structure
darcs-hash:20060920201205-f46e9-1eb5e174b56f63387321970baaa769c5baaf9f98.gz
This commit is contained in:
parent
b5b3e3b72e
commit
3dc01c0c2d
6 changed files with 288 additions and 255 deletions
78
intranet/plugins/templatesfilter.py
Normal file
78
intranet/plugins/templatesfilter.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
from cherrypy.filters.basefilter import BaseFilter
|
||||
import cherrypy._cputil, os
|
||||
from Cheetah.Template import Template
|
||||
|
||||
# ######################################################## #
|
||||
# Configuration de Cheetah #
|
||||
# ######################################################## #
|
||||
|
||||
def serverSidePath(self, path):
|
||||
if (cherrypy.config.configMap["global"]["server.environment"] == "development"):
|
||||
if os.path.isfile(os.getcwd()+'/templates/'+path+".dev"):
|
||||
return cherrypy.config.configMap["global"]["rootDir"]+'/templates/'+path+".dev"
|
||||
# les template se trouve dans le dossier template
|
||||
return cherrypy.config.configMap["global"]["rootDir"]+'/templates/'+path
|
||||
|
||||
# on surcharge cette fonction dans la classe Template
|
||||
Template.serverSidePath = serverSidePath
|
||||
|
||||
|
||||
##########################
|
||||
# templatesEngine
|
||||
##########################
|
||||
#
|
||||
# Application des templates,
|
||||
# avec plein de test chians
|
||||
#
|
||||
class TemplatesFilter(BaseFilter):
|
||||
|
||||
def _getBodyTemplate(self, body):
|
||||
if isinstance(body, dict):
|
||||
if body.has_key('template'):
|
||||
if body['template'].endswith(".py"):
|
||||
return body['template']
|
||||
elif body['template'].endswith(".tmpl"):
|
||||
return body['template']
|
||||
else:
|
||||
return body['template'] + ".tmpl"
|
||||
return False
|
||||
|
||||
def _isStandaloneBody(self, body):
|
||||
if isinstance(body, dict):
|
||||
if body.has_key('standalone'):
|
||||
return body['standalone']
|
||||
if body.has_key('template'):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
return True
|
||||
|
||||
def _getBodyNameSpace(self, body):
|
||||
if isinstance(body, dict):
|
||||
if body.has_key('values'):
|
||||
return body['values']
|
||||
return {}
|
||||
|
||||
def _useMainTemplate(self, body):
|
||||
t = Template(file='main.tmpl', searchList=[body,{'login':cherrypy.session['uid'], 'environment':cherrypy.config.configMap["global"]["server.environment"]}])
|
||||
return str(t)
|
||||
|
||||
|
||||
|
||||
def beforeFinalize(self):
|
||||
|
||||
body = cherrypy.response.body
|
||||
if isinstance(body, dict):
|
||||
bodyTemplate = self._getBodyTemplate(body)
|
||||
if bodyTemplate:
|
||||
templatevalues = self._getBodyNameSpace(body)
|
||||
t = Template(file=bodyTemplate, searchList=[templatevalues])
|
||||
body['page'] = str(t)
|
||||
|
||||
if not self._isStandaloneBody(body):
|
||||
body = self._useMainTemplate(body)
|
||||
else:
|
||||
body = body["page"]
|
||||
|
||||
cherrypy.response.body = body
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue