Пример #1
0
    def render_dynamic_page(self, pagename: str, data) -> str:
        page_template_path: str = self.template_path + pagename + ".tpl"
        assert (os.path.exists(page_template_path)
                and not os.path.isdir(page_template_path))

        template = TemplateLookup(
            directories=self.template_path).get_template(pagename + ".tpl")
        return template.render(data_o=data)
Пример #2
0
 def _render(self, tmpl, ctx, file):
     ctx["desc"] = self.desc
     ctx["NUM_COLORS"] = self.NUM_COLORS
     t = TemplateLookup([self.TMPL_DIR]).get_template(tmpl + ".html")
     assert not os.path.exists(file)
     try: 
         with open(file, "w") as f: f.write(t.render(**ctx))
     except:
         print(exceptions.text_error_template().render())
         raise
Пример #3
0
 def _render(self, tmpl, ctx, file):
     ctx["desc"] = self.desc
     ctx["NUM_COLORS"] = self.NUM_COLORS
     t = TemplateLookup([self.TMPL_DIR]).get_template(tmpl + ".html")
     assert not os.path.exists(file)
     try:
         with open(file, "w") as f:
             f.write(t.render(**ctx))
     except:
         print(exceptions.text_error_template().render())
         raise
Пример #4
0
def main(output_dir=TMPDIR, media_dir=MEDIA_DIR, abs_media_dir=CURDIR):
    """
    all files should be accessible in abs_media_dir
    media_dir is for html access
    output_dir is where html is written
    """
    outro = open(os.path.join(abs_media_dir, OUTRO_FILE)).read()
    tmp = TemplateLookup(directories=[abs_media_dir]).get_template('interview.html')
    for i, issue in enumerate(load_issues(abs_media_dir)):
        content = tmp.render(title=issue.title, mediadir=media_dir, photo=issue.photo, subject=issue.subject, intro=issue.intro, sections=issue.sections, locations=issue.locations, outro=outro)
        write(output_dir, content, i+1)
Пример #5
0
def render_to_string(template_name,
		dictionary=None,
		request=None,
        tmpldir=None):
    '''
render a template to a string(like render_to_string django.template.loader)
'''
    #if another template dir is specified,then use it.
    if tmpldir==None or tmpldir=="":
        t=djlookup.get_template(template_name)
    else:
        t=TemplateLookup(directories=tmpldir,input_encoding="utf-8").get_template(template_name)
    if request!=None:
        dictionary.update(csrf(request))
    page=t.render(**dictionary)
    return page
Пример #6
0
def main(output_dir=TMPDIR, media_dir=MEDIA_DIR, abs_media_dir=CURDIR):
    """
    all files should be accessible in abs_media_dir
    media_dir is for html access
    output_dir is where html is written
    """
    outro = open(os.path.join(abs_media_dir, OUTRO_FILE)).read()
    tmp = TemplateLookup(
        directories=[abs_media_dir]).get_template('interview.html')
    for i, issue in enumerate(load_issues(abs_media_dir)):
        content = tmp.render(title=issue.title,
                             mediadir=media_dir,
                             photo=issue.photo,
                             subject=issue.subject,
                             intro=issue.intro,
                             sections=issue.sections,
                             locations=issue.locations,
                             outro=outro)
        write(output_dir, content, i + 1)