Esempio n. 1
0
def send_email(recipients,
               sender,
               mail_model_name,
               translation=None,
               data=None,
               send_async=False):
    """
    Method for sending email in this pluggable. Use this method to send your email, specifying
    the name of a MailModel and the language of the email (optionally).
    E.g. send_email('*****@*****.**', '*****@*****.**', 'registration_mail', 'EN')
    If a language is not specified, the default language passed as Plugin option will be used.

    :param recipients: An array representing the email address of the recipient of the email
    :param sender: A string representing the email adress of the sender of the email
    :param mail_model_name: The name of the MailModel representing an email
    :param translation: The language of a TemplateTranslation (e.g. 'EN'). If omitted, the
        default language provided while plugging mailtemplates is used
    :param data: A dictionary representing the variables used in the email template, like ${name}
    :param send_async: The email will sent asynchronously if this flag is True
    """
    if 'kajiki' not in config['render_functions']:
        raise MailTemplatesError('Kajiki must be allowed in your app.')

    __, mail_models = model.provider.query(model.MailModel,
                                           filters=dict(name=mail_model_name))
    if not mail_models:
        raise MailTemplatesError("Mail model '%s' not found." %
                                 mail_model_name)
    mail_model = mail_models[0]

    language = translation or config['_mailtemplates']['default_language']

    __, translations = model.provider.query(model.TemplateTranslation,
                                            filters=dict(mail_model=mail_model,
                                                         language=language))
    if not translations:
        raise MailTemplatesError('Translation for this mail model not found')
    tr = translations[0]

    # as the template is already translated, use a fake gettext
    data.update({'gettext': lambda x: x})

    Template = kajiki.XMLTemplate(source=tr.body)
    Template.loader = tg.config['render_functions']['kajiki'].loader
    html = Template(data).render()

    Template = kajiki.TextTemplate(tr.subject)
    subject = Template(data).render()

    _send_email(sender, recipients, subject, html, send_async)
Esempio n. 2
0
 def _convert_to_python(self, value, state):
     try:
         kajiki.TextTemplate(value)
     except:
         raise formencode.Invalid(_('Template not valid.'), value, state)
     return value
Esempio n. 3
0
    },
    "x86_sse_flow": {
        "title": "x86-SSE recommended passes",
        "pass_list": ["m128_promotion"],
    },
    "x86_avx_flow": {
        "title": "x86-AVX recommended passes",
        "pass_list": ["m128_promotion", "m256_promotion"],
    },
}

preconf_flow_script = kajiki.TextTemplate("""\
var pre_conf_map = {
%for flow in preconf_flow
    ${'"{}": [{}],\\n\\t'.format(flow, ",".join('"%s"' % tag for tag in preconf_flow[flow]['pass_list']))}
%end
};
""")({
    "preconf_flow": PRE_CONFIGURE_FLOWS
}).render()


class MetalibmWebApp:
    SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
    MAIN_TEMPLATE = os.path.join(SCRIPT_DIR, "main.xhtml")
    STAT_TEMPLATE = os.path.join(SCRIPT_DIR, "stats.xhtml")
    REPORT_ISSUE_BASE_URL = "https://github.com/metalibm/MetalibmWebApp/issues/new"

    LANGUAGE_MAP = {
        "c": C_Code,
        "ll-ir": LLVM_IR_Code,
Esempio n. 4
0
    __, translations = model.provider.query(
        model.TemplateTranslation,
        filters=dict(mail_model=mail_model, language=language)
    )
    if not translations:
        raise MailTemplatesError('Translation for this mail model not found')
    tr = translations[0]

    # as the template is already translated, use a fake gettext
    data.update({'gettext': lambda x: x})

    Template = kajiki.XMLTemplate(source=tr.body)
    Template.loader = tg.config['render_functions']['kajiki'].loader
    html = Template(data).render()

    Template = kajiki.TextTemplate(tr.subject)
    subject = Template(data).render()

    _send_email(sender, recipients, subject, html, async)


def _get_request():
    """Tests fails and can't mock get_mailer, so mock this"""
    return tg.request


def _send_email(sender, recipients, subject, html, async=True):
    if not isinstance(recipients, list):
        recipients = list(recipients)

    if async and config['_mailtemplates']['async_sender'] == 'tgext.celery':