def get_template(tpl_type): """ Return a template for the given type. If template path is set, try that, but fall back on default template.""" if tpl_type in TPL_CACHE.keys(): return TPL_CACHE[tpl_type] tpl_paths = Registry.get_html_template_path() tpl = None for tpl_path in tpl_paths: if tpl_path and not tpl_path.startswith("."): tpl = "%s/%s.pt" % (tpl_path, tpl_type) else: tpl = find_file("templates/%s/%s.pt" % (tpl_path, tpl_type), __file__) if os.path.isfile(tpl): break if not (tpl and os.path.isfile(tpl)): tpl = find_file("templates/%s.pt" % tpl_type, __file__) tpl = PageTemplateFile(tpl, encoding="utf-8") TPL_CACHE[tpl_type] = tpl return tpl
def __form__(self, request): """ Volatile form """ try: return self._v_form except: form = find_file(self.edit_form, self.__class__) xmlff = XMLFormFactory(FormFile(form).filename) self._v_form = xmlff.create_form(action="") return self._v_form
from chameleon import PageTemplateFile from w20e.forms.utils import find_file TEMPLATES = {} TEMPLATES['INPUT'] = PageTemplateFile( find_file("templates/input.pt", __file__)) TEMPLATES['TEXTAREA'] = PageTemplateFile( find_file("templates/textarea.pt", __file__)) TEMPLATES['SELECT_COMPACT'] = PageTemplateFile( find_file("templates/select.pt", __file__)) TEMPLATES['SELECT_FULL'] = PageTemplateFile( find_file("templates/select_full.pt", __file__)) TEMPLATES['HIDDEN'] = PageTemplateFile( find_file("templates/hidden.pt", __file__)) TEMPLATES['CONTROL_HDR'] ="""<div id="%(id)s" class="control %(type)s %(extra_classes)s"> <div class="control-info"> <label class="control-label" for="input-%(id)s">%(label)s</label> <div class="alert">%(alert)s</div> <div class="hint">%(hint)s</div> </div><div class="control-widget">""" TEMPLATES['CONTROL_FTR'] ="""</div></div>""" TEMPLATES['CONTROL_HDR_PLAIN'] ="""<div id="%(id)s" class="control %(type)s %(extra_classes)s">"""
def setup_class(self): xml = find_file('test_xml_form.xml', __file__) self.form = XMLFormFactory(xml).create_form()
from chameleon import PageTemplateFile from w20e.forms.utils import find_file TEMPLATES = {} TEMPLATES['INPUT'] = PageTemplateFile(find_file("templates/input.pt", __file__)) TEMPLATES['TEXTAREA'] = PageTemplateFile( find_file("templates/textarea.pt", __file__)) TEMPLATES['SELECT_COMPACT'] = PageTemplateFile( find_file("templates/select.pt", __file__)) TEMPLATES['SELECT_FULL'] = PageTemplateFile( find_file("templates/select_full.pt", __file__)) TEMPLATES['HIDDEN'] = PageTemplateFile( find_file("templates/hidden.pt", __file__)) TEMPLATES[ 'CONTROL_HDR'] = """<div id="%(id)s" class="control %(type)s %(extra_classes)s"> <div class="control-info"> <label class="control-label" for="input-%(id)s">%(label)s</label> <div class="alert">%(alert)s</div> <div class="hint">%(hint)s</div> </div><div class="control-widget">""" TEMPLATES['CONTROL_FTR'] = """</div></div>""" TEMPLATES[ 'CONTROL_HDR_PLAIN'] = """<div id="%(id)s" class="control %(type)s %(extra_classes)s">"""
def setup_class(self): xml = find_file('test_xml_form.xml', __file__) self.form = XMLFormFactory(xml).create_form()