Exemplo n.º 1
0
def choose_template(service_id, template_type='all'):
    templates = service_api_client.get_service_templates(service_id)['data']

    has_multiple_template_types = len({
        template['template_type'] for template in templates
    }) > 1

    template_nav_items = [
        (label, key, url_for('.choose_template', service_id=current_service['id'], template_type=key), '')
        for label, key in filter(None, [
            ('All', 'all'),
            ('Text message', 'sms'),
            ('Email', 'email'),
            ('Letter', 'letter') if 'letter' in current_service['permissions'] else None,
        ])
    ]

    templates_on_page = [
        template for template in templates
        if template_type in ['all', template['template_type']]
    ]

    return render_template(
        'views/templates/choose.html',
        templates=templates_on_page,
        show_search_box=(len(templates_on_page) > 7),
        show_template_nav=has_multiple_template_types and (len(templates) > 2),
        template_nav_items=template_nav_items,
        template_type=template_type,
        search_form=SearchTemplatesForm(),
    )
Exemplo n.º 2
0
def choose_template(service_id, template_type='all'):
    templates = service_api_client.get_service_templates(service_id)['data']

    letters_available = ('letter' in current_service['permissions']
                         and current_user.has_permissions('view_activity'))

    available_template_types = list(
        filter(None, (
            'email',
            'sms',
            'letter' if letters_available else None,
        )))

    templates = [
        template for template in templates
        if template['template_type'] in available_template_types
    ]

    has_multiple_template_types = len(
        {template['template_type']
         for template in templates}) > 1

    template_nav_items = [
        (label, key,
         url_for('.choose_template',
                 service_id=current_service['id'],
                 template_type=key), '')
        for label, key in filter(None, [
            ('All', 'all'),
            ('Text message', 'sms'),
            ('Email', 'email'),
            ('Letter', 'letter') if letters_available else None,
        ])
    ]

    templates_on_page = [
        template for template in templates
        if (template_type in ['all', template['template_type']]
            and template['template_type'] in available_template_types)
    ]

    if current_user.has_permissions('view_activity'):
        page_title = 'Templates'
    else:
        page_title = 'Choose a template'

    return render_template(
        'views/templates/choose.html',
        page_title=page_title,
        templates=templates_on_page,
        show_search_box=(len(templates_on_page) > 7),
        show_template_nav=has_multiple_template_types and (len(templates) > 2),
        template_nav_items=template_nav_items,
        template_type=template_type,
        search_form=SearchTemplatesForm(),
    )
Exemplo n.º 3
0
def service_dashboard(service_id):
    if session.get('invited_user'):
        session.pop('invited_user', None)
        session['service_id'] = service_id

    return render_template(
        'views/dashboard/dashboard.html',
        updates_url=url_for(".service_dashboard_updates",
                            service_id=service_id),
        templates=service_api_client.get_service_templates(service_id)['data'],
        partials=get_dashboard_partials(service_id))
Exemplo n.º 4
0
def service_dashboard(service_id):

    if session.get('invited_user'):
        session.pop('invited_user', None)
        session['service_id'] = service_id

    return render_template(
        'views/dashboard/dashboard.html',
        updates_url=url_for(".service_dashboard_updates", service_id=service_id),
        templates=service_api_client.get_service_templates(service_id)['data'],
        partials=get_dashboard_partials(service_id)
    )
Exemplo n.º 5
0
def choose_template(service_id, template_type):
    if template_type not in ['email', 'sms']:
        abort(404)
    return render_template(
        'views/templates/choose.html',
        templates=[
            Template(template,
                     prefix=current_service['name'],
                     sms_sender=current_service['sms_sender']) for template in
            service_api_client.get_service_templates(service_id)['data']
            if template['template_type'] == template_type
        ],
        template_type=template_type,
        page_heading=get_page_headings(template_type))
Exemplo n.º 6
0
def service_dashboard(service_id):

    if session.get('invited_user'):
        session.pop('invited_user', None)
        session['service_id'] = service_id

    if not current_user.has_permissions('view_activity'):
        return redirect(url_for('main.choose_template', service_id=service_id))

    return render_template(
        'views/dashboard/dashboard.html',
        updates_url=url_for(".service_dashboard_updates", service_id=service_id),
        templates=service_api_client.get_service_templates(service_id)['data'],
        partials=get_dashboard_partials(service_id)
    )
Exemplo n.º 7
0
def choose_template(service_id, template_type):
    if template_type not in ['email', 'sms']:
        abort(404)
    return render_template(
        'views/templates/choose.html',
        templates=[
            Template(
                template,
                prefix=current_service['name']
            ) for template in service_api_client.get_service_templates(service_id)['data']
            if template['template_type'] == template_type
        ],
        template_type=template_type,
        page_heading=get_page_headings(template_type)
    )
Exemplo n.º 8
0
def choose_template_to_copy(service_id):
    return render_template(
        'views/templates/copy.html',
        services=[{
            'name':
            service['name'],
            'id':
            service['id'],
            'templates': [
                template for template in
                service_api_client.get_service_templates(service['id'])['data']
                if template['template_type'] in current_service['permissions']
            ],
        } for service in user_api_client.get_services_for_user(current_user)],
    )
Exemplo n.º 9
0
def conversation_reply(
    service_id,
    notification_id,
):

    templates = [
        template for template in service_api_client.get_service_templates(
            service_id)['data'] if template['template_type'] == 'sms'
    ]

    return render_template(
        'views/templates/choose-reply.html',
        templates=templates,
        show_search_box=(len(templates) > 7),
        template_type='sms',
        search_form=SearchTemplatesForm(),
        notification_id=notification_id,
    )
Exemplo n.º 10
0
def service_templates_report_json(service_id):
    get_template_version = lambda template: template['version']
    common_template_fields = [
        "name",
        "content",
        "subject",
        "template_type",
        "reply_to",
        "reply_to_text",
        "version",
    ]

    def present_template_version(template_version):
        response = {
            field: template_version.get(field)
            for field in common_template_fields
        }
        response['created_by'] = template_version.get('created_by',
                                                      {}).get('email_address')
        return response

    def present_template(template):
        template_id = template['id']
        template_version_data = service_api_client.get_service_template_versions(
            service_id, template_id)['data']
        template_version_data = sorted(template_version_data,
                                       key=get_template_version)
        template_versions = [
            present_template_version(version)
            for version in template_version_data
        ]

        response = {
            field: template.get(field)
            for field in common_template_fields
        }
        response['versions'] = template_versions
        return response

    templates = service_api_client.get_service_templates(service_id)['data']
    response = [present_template(template) for template in templates]
    return json_download(response, f'service-{service_id}-templates')