diff --git a/ipa-server/ipa-gui/ipagui/forms/delegate.py b/ipa-server/ipa-gui/ipagui/forms/delegate.py index 0c080b32a..e7ba03f98 100644 --- a/ipa-server/ipa-gui/ipagui/forms/delegate.py +++ b/ipa-server/ipa-gui/ipagui/forms/delegate.py @@ -17,6 +17,7 @@ import turbogears from turbogears import validators, widgets +from ipagui.helpers import ipahelper from ipagui.forms.user import UserFields @@ -101,7 +102,7 @@ class DelegateForm(widgets.Form): def __init__(self, *args, **kw): super(DelegateForm,self).__init__(*args, **kw) - (self.template_c, self.template) = widgets.meta.load_kid_template( + (self.template_c, self.template) = ipahelper.load_template( "ipagui.templates.delegateform") self.delegate_fields = DelegateFields diff --git a/ipa-server/ipa-gui/ipagui/forms/group.py b/ipa-server/ipa-gui/ipagui/forms/group.py index 0904d319f..4835e9168 100644 --- a/ipa-server/ipa-gui/ipagui/forms/group.py +++ b/ipa-server/ipa-gui/ipagui/forms/group.py @@ -18,6 +18,7 @@ import turbogears from turbogears import validators, widgets from tg_expanding_form_widget.tg_expanding_form_widget import ExpandingForm +from ipagui.helpers import ipahelper class GroupFields(object): cn = widgets.TextField(name="cn", label="Name") @@ -50,7 +51,7 @@ class GroupNewForm(widgets.Form): def __init__(self, *args, **kw): super(GroupNewForm,self).__init__(*args, **kw) - (self.template_c, self.template) = widgets.meta.load_kid_template("ipagui.templates.groupnewform") + (self.template_c, self.template) = ipahelper.load_template("ipagui.templates.groupnewform") self.group_fields = GroupFields def update_params(self, params): @@ -80,5 +81,5 @@ class GroupEditForm(widgets.Form): def __init__(self, *args, **kw): super(GroupEditForm,self).__init__(*args, **kw) - (self.template_c, self.template) = widgets.meta.load_kid_template("ipagui.templates.groupeditform") + (self.template_c, self.template) = ipahelper.load_template("ipagui.templates.groupeditform") self.group_fields = GroupFields diff --git a/ipa-server/ipa-gui/ipagui/forms/ipapolicy.py b/ipa-server/ipa-gui/ipagui/forms/ipapolicy.py index 8d39fa402..7ad9fe083 100644 --- a/ipa-server/ipa-gui/ipagui/forms/ipapolicy.py +++ b/ipa-server/ipa-gui/ipagui/forms/ipapolicy.py @@ -18,6 +18,7 @@ import turbogears from turbogears import validators, widgets from tg_expanding_form_widget.tg_expanding_form_widget import ExpandingForm +from ipagui.helpers import ipahelper class IPAPolicyFields(object): # From cn=ipaConfig @@ -78,7 +79,7 @@ class IPAPolicyForm(widgets.Form): def __init__(self, *args, **kw): super(IPAPolicyForm,self).__init__(*args, **kw) - (self.template_c, self.template) = widgets.meta.load_kid_template( + (self.template_c, self.template) = ipahelper.load_template( "ipagui.templates.ipapolicyeditform") self.ipapolicy_fields = IPAPolicyFields diff --git a/ipa-server/ipa-gui/ipagui/forms/principal.py b/ipa-server/ipa-gui/ipagui/forms/principal.py index 6c1ac56a7..02c62f26a 100644 --- a/ipa-server/ipa-gui/ipagui/forms/principal.py +++ b/ipa-server/ipa-gui/ipagui/forms/principal.py @@ -18,6 +18,7 @@ import turbogears from turbogears import validators, widgets from tg_expanding_form_widget.tg_expanding_form_widget import ExpandingForm +from ipagui.helpers import ipahelper class PrincipalFields(object): hostname = widgets.TextField(name="hostname", label="Host Name") @@ -50,7 +51,7 @@ class PrincipalNewForm(widgets.Form): def __init__(self, *args, **kw): super(PrincipalNewForm,self).__init__(*args, **kw) - (self.template_c, self.template) = widgets.meta.load_kid_template("ipagui.templates.principalnewform") + (self.template_c, self.template) = ipahelper.load_template("ipagui.templates.principalnewform") self.principal_fields = PrincipalFields def update_params(self, params): diff --git a/ipa-server/ipa-gui/ipagui/forms/user.py b/ipa-server/ipa-gui/ipagui/forms/user.py index 350283749..22a49653c 100644 --- a/ipa-server/ipa-gui/ipagui/forms/user.py +++ b/ipa-server/ipa-gui/ipagui/forms/user.py @@ -19,6 +19,7 @@ import turbogears from turbogears import validators, widgets from tg_expanding_form_widget.tg_expanding_form_widget import ExpandingForm from ipagui.helpers.validators import * +from ipagui.helpers import ipahelper class UserFields(object): givenname = widgets.TextField(name="givenname", label="First Name") @@ -120,7 +121,8 @@ class UserNewForm(widgets.Form): def __init__(self, *args, **kw): super(UserNewForm,self).__init__(*args, **kw) - (self.template_c, self.template) = widgets.meta.load_kid_template("ipagui.templates.usernewform") + (self.template_c, self.template) = ipahelper.load_template("ipagui.templates.usernewform") + self.user_fields = UserFields def update_params(self, params): @@ -172,7 +174,8 @@ class UserEditForm(widgets.Form): def __init__(self, *args, **kw): super(UserEditForm,self).__init__(*args, **kw) - (self.template_c, self.template) = widgets.meta.load_kid_template("ipagui.templates.usereditform") + (self.template_c, self.template) = ipahelper.load_template("ipagui.templates.usereditform") + self.user_fields = UserFields diff --git a/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py b/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py index 4eb7644cf..9b3404837 100644 --- a/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py +++ b/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py @@ -17,6 +17,10 @@ import re import logging +import turbogears +import kid +from turbokid import kidsupport +from pkg_resources import resource_filename def javascript_string_escape(input): """Escapes the ' " and \ characters in a string so @@ -60,3 +64,25 @@ def fix_incoming_fields(fields, fieldname, multifieldname): logging.warn("fix_incoming_fields error: " + str(e)) return fields + +def load_template(classname, encoding=None): + """ + Loads the given template. This only handles .kid files. + Returns a tuple (compiled_tmpl, None) to emulate + turbogears.meta.load_kid_template() which ends up not properly handling + encoding. + """ + if not encoding: + encoding = turbogears.config.get('kid.encoding', kidsupport.KidSupport.assume_encoding) + divider = classname.rfind(".") + package, basename = classname[:divider], classname[divider+1:] + file_path = resource_filename(package, basename + ".kid") + + tclass = kid.load_template( + file_path, + name = classname, + ).Template + tclass.serializer = kid.HTMLSerializer(encoding=encoding) + tclass.assume_encoding=encoding + + return (tclass, None)