Esempio n. 1
0
def set_sender(service_id, template_id):
    session['sender_id'] = None
    redirect_to_one_off = redirect(
        url_for('.send_one_off', service_id=service_id, template_id=template_id)
    )

    template = current_service.get_template_with_user_permission_or_403(template_id, current_user)

    if template['template_type'] == 'letter':
        return redirect_to_one_off

    sender_details = get_sender_details(service_id, template['template_type'])

    if len(sender_details) == 1:
        session['sender_id'] = sender_details[0]['id']

    if len(sender_details) <= 1:
        return redirect_to_one_off

    sender_context = get_sender_context(sender_details, template['template_type'])

    form = SetSenderForm(
        sender=sender_context['default_id'],
        sender_choices=sender_context['value_and_label'],
        sender_label=sender_context['description']
    )
    option_hints = {sender_context['default_id']: '(Default)'}
    if sender_context.get('receives_text_message', None):
        option_hints.update({sender_context['receives_text_message']: '(Receives replies)'})
    if sender_context.get('default_and_receives', None):
        option_hints = {sender_context['default_and_receives']: '(Default and receives replies)'}

    # extend all radios that need hint text
    form.sender.param_extensions = {'items': []}
    for item_id, _item_value in form.sender.choices:
        if item_id in option_hints:
            extensions = {'hint': {'text': option_hints[item_id]}}
        else:
            extensions = {}  # if no extensions needed, send an empty dict to preserve order of items
        form.sender.param_extensions['items'].append(extensions)

    if form.validate_on_submit():
        session['sender_id'] = form.sender.data
        return redirect(url_for('.send_one_off',
                                service_id=service_id,
                                template_id=template_id))

    return render_template(
        'views/templates/set-sender.html',
        form=form,
        template_id=template_id,
        sender_context={'title': sender_context['title'], 'description': sender_context['description']},
        option_hints=option_hints
    )
Esempio n. 2
0
def set_sender(service_id, template_id):
    session["sender_id"] = None
    redirect_to_one_off = redirect(
        url_for(".send_one_off",
                service_id=service_id,
                template_id=template_id))

    template = current_service.get_template_with_user_permission_or_403(
        template_id, current_user)

    if template["template_type"] == "letter":
        return redirect_to_one_off

    sender_details = get_sender_details(service_id, template["template_type"])
    if len(sender_details) <= 1:
        return redirect_to_one_off

    sender_context = get_sender_context(sender_details,
                                        template["template_type"])

    form = SetSenderForm(
        sender=sender_context["default_id"],
        sender_choices=sender_context["value_and_label"],
        sender_label=sender_context["description"],
    )
    option_hints = {sender_context["default_id"]: _l("(Default)")}
    if sender_context.get("receives_text_message", None):
        option_hints.update({
            sender_context["receives_text_message"]:
            _l("(Receives replies)")
        })
    if sender_context.get("default_and_receives", None):
        option_hints = {
            sender_context["default_and_receives"]:
            _l("(Default and receives replies)")
        }

    if form.validate_on_submit():
        session["sender_id"] = form.sender.data
        return redirect(
            url_for(".send_one_off",
                    service_id=service_id,
                    template_id=template_id))

    return render_template(
        "views/templates/set-sender.html",
        form=form,
        template_id=template_id,
        sender_context={
            "title": sender_context["title"],
            "description": sender_context["description"],
        },
        option_hints=option_hints,
    )
Esempio n. 3
0
def set_sender(service_id, template_id):
    session['sender_id'] = None
    redirect_to_one_off = redirect(
        url_for('.send_one_off',
                service_id=service_id,
                template_id=template_id))

    template = current_service.get_template_with_user_permission_or_403(
        template_id, current_user)

    if template['template_type'] == 'letter':
        return redirect_to_one_off

    sender_details = get_sender_details(service_id, template['template_type'])
    if len(sender_details) <= 1:
        return redirect_to_one_off

    sender_context = get_sender_context(sender_details,
                                        template['template_type'])

    form = SetSenderForm(sender=sender_context['default_id'],
                         sender_choices=sender_context['value_and_label'],
                         sender_label=sender_context['description'])
    option_hints = {sender_context['default_id']: _l('(Default)')}
    if sender_context.get('receives_text_message', None):
        option_hints.update({
            sender_context['receives_text_message']:
            _l('(Receives replies)')
        })
    if sender_context.get('default_and_receives', None):
        option_hints = {
            sender_context['default_and_receives']:
            _l('(Default and receives replies)')
        }

    if form.validate_on_submit():
        session['sender_id'] = form.sender.data
        return redirect(
            url_for('.send_one_off',
                    service_id=service_id,
                    template_id=template_id))

    return render_template('views/templates/set-sender.html',
                           form=form,
                           template_id=template_id,
                           sender_context={
                               'title': sender_context['title'],
                               'description': sender_context['description']
                           },
                           option_hints=option_hints)