def quick_maketext(templatefile, dict=None, lang=None, mlist=None): """Create an output using a template""" # Used by various html output functions such as as_html, html_TOC and write_index_entry if mlist is None: listname = '' else: listname = mlist._internal_name if lang is None: if mlist is None: lang = mm_cfg.DEFAULT_SERVER_LANGUAGE else: lang = mlist.preferred_language cachekey = (templatefile, lang, listname) filepath = _templatefilepathcache.get(cachekey) if filepath: template = _templatecache.get(filepath) if filepath is None or template is None: # Use the basic maketext, with defaults to get the raw template template, filepath = Utils.findtext(templatefile, lang=lang, raw=True, mlist=mlist) _templatefilepathcache[cachekey] = filepath _templatecache[filepath] = template # Copied from Utils.maketext() text = template if dict is not None: try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, Utils.GetCharSet(lang), 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError): # The template is really screwed up pass # Make sure the text is in the given character set, or html-ify any bogus # characters. return Utils.uncanonstr(text, lang)
def quick_maketext(templatefile, dict=None, lang=None, mlist=None): if mlist is None: listname = '' else: listname = mlist._internal_name if lang is None: if mlist is None: lang = mm_cfg.DEFAULT_SERVER_LANGUAGE else: lang = mlist.preferred_language cachekey = (templatefile, lang, listname) filepath = _templatefilepathcache.get(cachekey) if filepath: template = _templatecache.get(filepath) if filepath is None or template is None: # Use the basic maketext, with defaults to get the raw template template, filepath = Utils.findtext(templatefile, lang=lang, raw=True, mlist=mlist) _templatefilepathcache[cachekey] = filepath _templatecache[filepath] = template # Copied from Utils.maketext() text = template if dict is not None: try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, Utils.GetCharSet(lang), 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError): # The template is really screwed up pass # Make sure the text is in the given character set, or html-ify any bogus # characters. return Utils.uncanonstr(text, lang)
def quick_maketext(templatefile, dict=None, lang=None, mlist=None): if mlist is None: listname = '' else: listname = mlist._internal_name if lang is None: if mlist is None: lang = mm_cfg.DEFAULT_SERVER_LANGUAGE else: lang = mlist.preferred_language cachekey = (templatefile, lang, listname) filepath = _templatefilepathcache.get(cachekey) if filepath: template = _templatecache.get(filepath) if filepath is None or template is None: # Use the basic maketext, with defaults to get the raw template template, filepath = Utils.findtext(templatefile, lang=lang, raw=True, mlist=mlist) _templatefilepathcache[cachekey] = filepath _templatecache[filepath] = template # Copied from Utils.maketext() text = template if dict is not None: try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, Utils.GetCharSet(lang), 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError), e: # The template is really screwed up syslog('error', 'broken template: %s\n%s', filepath, e)
# you've got a really broken installation, must be there. try: filename = os.path.join(mm_cfg.TEMPLATE_DIR, 'en', templatefile) fp = open(filename) except IOError, e: if e.errno <> errno.ENOENT: raise # We never found the template. BAD! raise IOError(errno.ENOENT, 'No template file found', templatefile) template = fp.read() fp.close() text = template if dict is not None: try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, GetCharSet(lang), 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError), e: # The template is really screwed up syslog('error', 'broken template: %s\n%s', filename, e) pass if raw: return text, filename return wrap(text), filename def maketext(templatefile, dict=None, raw=False, lang=None, mlist=None): return findtext(templatefile, dict, raw, lang, mlist)[0]