1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-22 09:24:21 +01:00

Merge pull request #6 from rooty0/feat/template-parse-error

adding support for display template parse error
This commit is contained in:
Carpentier Pierre-Francois 2017-03-07 22:19:15 +01:00 committed by GitHub
commit 12bb597903
2 changed files with 35 additions and 21 deletions

View File

@ -30,6 +30,7 @@ from cherrypy.lib.httputil import parse_query_string
# Mako template engines imports # Mako template engines imports
from mako.template import Template from mako.template import Template
from mako import lookup from mako import lookup
from mako import exceptions
from sets import Set from sets import Set
SESSION_KEY = '_cp_username' SESSION_KEY = '_cp_username'
@ -1133,29 +1134,37 @@ class LdapCherry(object):
standalone_groups = tmp['unusedgroups'] standalone_groups = tmp['unusedgroups']
roles_js = json.dumps(display_names, separators=(',', ':')) roles_js = json.dumps(display_names, separators=(',', ':'))
key = self.attributes.get_key() key = self.attributes.get_key()
form = self.temp['form.tmpl'].render(
attributes=self.attributes.attributes, try:
values=self._escape(user_attrs, 'attr_list'), form = self.temp['form.tmpl'].render(
modify=True, attributes=self.attributes.attributes,
keyattr=key, values=self._escape(user_attrs, 'attr_list'),
autofill=False modify=True,
keyattr=key,
autofill=False
)
roles = self.temp['roles.tmpl'].render(
roles=self.roles.flatten,
graph=self.roles.graph,
graph_js=graph_js,
roles_js=roles_js,
current_roles=user_roles,
) )
roles = self.temp['roles.tmpl'].render(
roles=self.roles.flatten, glued_template = self.temp['modify.tmpl'].render(
graph=self.roles.graph, form=form,
graph_js=graph_js, roles=roles,
roles_js=roles_js, is_admin=is_admin,
current_roles=user_roles, standalone_groups=self._escape(standalone_groups, 'lonely_groups'),
) backends_display_names=self.backends_display_names,
return self.temp['modify.tmpl'].render( custom_js=self.custom_js,
form=form, notifications=self._empty_notification(),
roles=roles,
is_admin=is_admin,
standalone_groups=self._escape(standalone_groups, 'lonely_groups'),
backends_display_names=self.backends_display_names,
custom_js=self.custom_js,
notifications=self._empty_notification(),
) )
except NameError:
raise TemplateRenderError(exceptions.text_error_template().render())
return glued_template
@cherrypy.expose @cherrypy.expose
@exception_decorator @exception_decorator

View File

@ -217,6 +217,11 @@ class GroupDoesntExist(Exception):
" in backend '" + backend + "'" " in backend '" + backend + "'"
class TemplateRenderError(Exception):
def __init__(self, error):
self.log = "Template Render Error: " + error
def exception_decorator(func): def exception_decorator(func):
def ret(self, *args, **kwargs): def ret(self, *args, **kwargs):
try: try: