def load_template_source(name, dirs=None): try: tname = os.path.join(settings.OSQA_DEFAULT_SKIN,'templates',name) return filesystem.load_template_source(tname,dirs) except: tname = os.path.join('default','templates',name) return filesystem.load_template_source(tname,dirs)
def load_template_source(name, dirs=None): try: tname = os.path.join(settings.OSQA_DEFAULT_SKIN,'templates',name) return filesystem.load_template_source(tname,dirs) except: tname = os.path.join('default','templates',name) return filesystem.load_template_source(tname,dirs)
def load_template_source(name, dirs=None): """Django template loader """ if dirs is None: dirs = (ASKBOT_SKIN_COLLECTION_DIR, ) else: dirs += (ASKBOT_SKIN_COLLECTION_DIR, ) try: #todo: move this to top after splitting out get_skin_dirs() tname = os.path.join(askbot_settings.ASKBOT_DEFAULT_SKIN,'templates',name) return filesystem.load_template_source(tname,dirs) except: tname = os.path.join('default','templates',name) return filesystem.load_template_source(tname,dirs)
def filesystem_load_template_source(name, dirs=None): """Django template loader """ if dirs is None: dirs = (OPENODE_SKIN_COLLECTION_DIR, ) else: dirs += (OPENODE_SKIN_COLLECTION_DIR, ) try: #todo: move this to top after splitting out get_skin_dirs() tname = os.path.join(openode_settings.OPENODE_DEFAULT_SKIN, 'templates', name) return filesystem.load_template_source(tname, dirs) except: tname = os.path.join('default', 'templates', name) return filesystem.load_template_source(tname, dirs)
def load_template_source(template_name, template_dirs=None): """ Configurable template directories for custom theme templates. Just set the theme_template_dirs during the request. """ if template_dirs is None: template_dirs = theme_template_dirs from django.template.loaders.filesystem import load_template_source return load_template_source(template_name, template_dirs)
def __init__(self, template): self.template = template #Contains the strings of all loaded classes self.loaded_classes = [] self.template_calls = [] #Accept both template names and template strings try: self.template_string, self.filepath = load_template_source(template) except: self.template_string = template self.filepath = None
def load_template_source(self, template_name, template_dirs=None): """ Template loader that only serves templates from specific app's template directory. Works for template_names in format app_label:some/template/name.html """ if ":" not in template_name: raise TemplateDoesNotExist() template_name, template_dir = self._get_template_vars(template_name) if not isdir(template_dir): raise TemplateDoesNotExist() return load_template_source(template_name, template_dirs=[template_dir])
def from_template(cls, templatepath, load_template_source): template_string, _ = load_template_source(templatepath) # Cache to speed things up. hash = _hash("_".join([templatepath, template_string])) if hash in BLOCKS: return BLOCKS[hash] try: return cls.from_string(template_string, origin=templatepath) except UnicodeDecodeError: return "/* could not load %s as a template */\n" % templatepath
def load_blocks(self): """Loads the asset blocks defined in the template handles: * extends - to track template hierachy * css,javascript - start of asset * endcss, endjavascript - end of asset * {{ .. }} - expansion of variables to settings variables according to VAR_EXPANSIONS """ try: template_string, _filepath = filesystem.load_template_source(self.templatepath) except TemplateDoesNotExist: template_string, _filepath = app_directories.load_template_source(self.templatepath) self.content_hash = hash(template_string) try: result = TemplateAssetBucket() l = Lexer(template_string, self.templatepath) within = None texts = [] for m in l.tokenize(): if m.token_type == TOKEN_BLOCK: split = m.split_contents() typ = split[0] if typ == "extends": if split[1].endswith('"') or split[1].endswith("'"): self.extends = split[1].strip('"').strip("'") else: pass #TODO figure out support for variable expansion elif typ in TemplateAssetBlock.BLOCKTAGS: within = typ prop = _parse_asset_parameters(m.split_contents()) elif typ.startswith('end'): if typ[3:] == within: within = None result.append(TemplateAssetBlock(''.join(texts), template=self, **prop)) elif typ[3:] in TemplateAssetBlock.BLOCKTAGS: assert false, "encountered dangling %s tag in '%s'" % (typ,self.templatepath) elif within: if m.token_type == TOKEN_TEXT: texts.append(m.contents) elif m.token_type == TOKEN_VAR: v = VAR_EXPANSIONS.get(m.contents,'') if v: texts.append(v) #? else: #assert False, "Variable replacement in client side magic not yet supported" return result except UnicodeDecodeError: return "/* could not load %s as a template */\n" % templatepath
def load_template_source(self, template_name, template_dirs=None): """ Template loader that only serves templates from specific app's template directory. Works for template_names in format app_label:some/template/name.html """ if ":" not in template_name: raise TemplateDoesNotExist() template_name, template_dir = self._get_template_vars(template_name) if not isdir(template_dir): raise TemplateDoesNotExist() return load_template_source(template_name, template_dirs=[template_dir])
def __init__(self, template, context=None): """ Set the initial value of the template to be parsed Allows for the template passed to be a string of a template name or a string that represents a template. """ self.template = template self.context = context #Contains the strings of all loaded classes self.loaded_classes = [] self.template_calls = [] self.tests = [] #Accept both template names and template strings try: self.template_string, self.filepath = load_template_source(template) except: self.template_string = template self.filepath = None
def __init__(self, template, context=None): """ Set the initial value of the template to be parsed Allows for the template passed to be a string of a template name or a string that represents a template. """ self.template = template self.context = context #Contains the strings of all loaded classes self.loaded_classes = [] self.template_calls = [] self.tests = [] #Accept both template names and template strings try: self.template_string, self.filepath = load_template_source(template.name) except: self.template_string = template self.filepath = None
def test_edit_tag(self): import_edit_tag = True try: from common.templatetags.edit_tags import edit_object except ImportError: import_edit_tag = False self.assertTrue(import_edit_tag) response = self.client.get('/') self.failUnlessEqual(response.status_code, 302) self.client.login(username='******', password='******') response = self.client.get('/') from django.template.loaders.filesystem import load_template_source template_content = load_template_source(response.template[0].name)[0] self.assertTrue("{% load edit_tags %}" in template_content) self.assertTrue("{% edit_object u %}" in template_content) self.assertTrue("/admin/auth/user/1/" in response.content)
def load_template_source(template_name, template_dirs=None): local_template_name = '%s/%s' % (get_language(), template_name) return filesystem.load_template_source(local_template_name, template_dirs)
def load_template_source(template_name, template_dirs=None): local_template_name = '%s/%s' % (get_language(), template_name) return filesystem.load_template_source(local_template_name, template_dirs)