summaryrefslogtreecommitdiffstats
path: root/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py
diff options
context:
space:
mode:
authorRob Crittenden <rcrit@ipa.greyoak.com>2008-07-22 15:14:23 -0400
committerRob Crittenden <rcrit@ipa.greyoak.com>2008-07-29 11:32:02 -0400
commitbae3a2101fc3cf79cc90bd0f807de226aeb46f5e (patch)
tree5aeec29b0804bbe117eb45c7e44e4e99b3ccf1d4 /ipa-server/ipa-gui/ipagui/helpers/ipahelper.py
parentcdba310f02a80d63452feb098b983dbbfbbc890a (diff)
downloadfreeipa.git-bae3a2101fc3cf79cc90bd0f807de226aeb46f5e.tar.gz
freeipa.git-bae3a2101fc3cf79cc90bd0f807de226aeb46f5e.tar.xz
freeipa.git-bae3a2101fc3cf79cc90bd0f807de226aeb46f5e.zip
Fix encoding issue when manually loading templates for forms
We used to manually load the template files for the edit pages using turbogears.meta.load_kid_template(). Unfortunately this went through the one code path where encoding was completely ignored. It ended up defaulting to sys.getdefaultencoding() which is 'ascii'. So even though most of the templates are loaded as 'utf-8' the few that really mattered weren't. The fix is to call kid.load_template() ourselves and set the encoding of the class we just loaded to either the setting in the app.cfg file or to the normal default value of 'utf-8'. 454076
Diffstat (limited to 'ipa-server/ipa-gui/ipagui/helpers/ipahelper.py')
-rw-r--r--ipa-server/ipa-gui/ipagui/helpers/ipahelper.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py b/ipa-server/ipa-gui/ipagui/helpers/ipahelper.py
index 4eb7644c..9b340483 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)