Esempio n. 1
0
def main():
    resolver = path.DottedNameResolver()
    for cmd in SUBCOMMANDS:
        cli.add_command(resolver.resolve(cmd))
    cli(prog_name="hypothesis", obj={})
Esempio n. 2
0
def send_from_notification_dispatch(request, notification_dispatch_id):
    """Boilerplate to extract information from the notification
    dispatch and send an email.
    Please note that no verification if it should
    be sent is made prior to sending.
    """

    lookup = repo.LookupNotificationDispatch()
    dotted_name_resolver = path.DottedNameResolver()

    notification_dispatch = lookup(notification_dispatch_id)
    if not notification_dispatch:
        return False

    # Extract information from the notification dispatch.
    spec = notification_dispatch.single_spec
    send_to = notification_dispatch.address
    view = dotted_name_resolver.resolve(notification_dispatch.view)
    event = notification_dispatch.notification.event
    bcc = notification_dispatch.bcc
    context = event.parent
    channel = notification_dispatch.category

    # Get the template vars.
    tmpl_vars = view(request, context, send_to, event, event.action)

    # Set some defaults for the template vars.
    tmpl_vars.setdefault('data', context)
    tmpl_vars.setdefault('to', send_to)
    tmpl_vars.setdefault('from', util.extract_from(request))
    tmpl_vars.setdefault('state_or_action', event.action)
    tmpl_vars.setdefault('event', event)
    tmpl_vars.setdefault('subject', '{0} {1}'.format(event.target,
                                                     event.action))
    # Check if we should add bcc.
    if bcc:
        tmpl_vars.setdefault('bcc', bcc)

    # Extract form tmpl_vars and remove.
    subject = tmpl_vars['subject']
    to_ = tmpl_vars['to']
    from_ = tmpl_vars['from']
    del tmpl_vars['subject']
    del tmpl_vars['to']
    del tmpl_vars['from']

    # Send emails / sms.
    if channel == 'email':
        email = request.render_email(from_, to_, subject, spec, tmpl_vars,
                                     **tmpl_vars)
        request.send_email(email)
    elif channel == 'sms':
        pass
    else:
        raise Exception('Unknown channel to send the notification')

    # Set the sent info in our db.
    notification_dispatch.sent = datetime.datetime.now()
    bm.save(notification_dispatch)

    return True