Beispiel #1
0
 def put(self, obj, attribute, value):
     assert IMailingList.providedBy(obj), obj
     template_name = TEMPLATE_ATTRIBUTES[attribute]
     getUtility(ITemplateManager).set(template_name, obj.list_id, value)
Beispiel #2
0
 def get(self, name, context=None, **kws):
     """See `ITemplateLoader`."""
     # Gather some additional information based on the context.
     substitutions = {}
     if IMailingList.providedBy(context):
         mlist = context
         domain = context.domain
         lookup_contexts = [
             mlist.list_id,
             mlist.mail_host,
             None,
         ]
         substitutions.update(
             dict(
                 list_id=mlist.list_id,
                 # For backward compatibility, we call this $listname.
                 listname=mlist.fqdn_listname,
                 domain_name=domain.mail_host,
                 language=mlist.preferred_language.code,
             ))
     elif IDomain.providedBy(context):
         mlist = None
         domain = context
         lookup_contexts = [
             domain.mail_host,
             None,
         ]
         substitutions['domain_name'] = domain.mail_host
     elif context is None:
         mlist = domain = None
         lookup_contexts = [None]
     else:
         raise ValueError('Bad context type: {!r}'.format(context))
     # The passed in keyword arguments take precedence.
     substitutions.update(kws)
     # See if there's a cached template registered for this name and
     # context, passing in the url substitutions.  This handles http:,
     # https:, and file: urls.
     for lookup_context in lookup_contexts:
         try:
             contents = getUtility(ITemplateManager).get(
                 name, lookup_context, **substitutions)
         except (HTTPError, URLError):
             pass
         else:
             if contents is not None:
                 return contents
     # Fallback to searching within the source code.
     code = substitutions.get('language', config.mailman.default_language)
     # Find the template, mutating any missing template exception.
     missing = object()
     default_uri = ALL_TEMPLATES.get(name, missing)
     if default_uri is None:
         return ''
     elif default_uri is missing:
         raise URLError('No such file')
     path, fp = find(default_uri, mlist, code)
     try:
         return fp.read()
     finally:
         fp.close()
Beispiel #3
0
 def get(self, obj, attribute):
     assert IMailingList.providedBy(obj), obj
     template_name = TEMPLATE_ATTRIBUTES[attribute]
     template = getUtility(ITemplateManager).raw(template_name, obj.list_id)
     return '' if template is None else template.uri