def service_edit_sms_sender(service_id, sms_sender_id):
    sms_sender = current_service.get_sms_sender(sms_sender_id)
    is_inbound_number = sms_sender['inbound_number_id']
    if is_inbound_number:
        form = ServiceEditInboundNumberForm(
            is_default=sms_sender['is_default'])
    else:
        form = ServiceSmsSenderForm(**sms_sender)

    if form.validate_on_submit():
        service_api_client.update_sms_sender(
            current_service.id,
            sms_sender_id=sms_sender_id,
            sms_sender=sms_sender['sms_sender']
            if is_inbound_number else form.sms_sender.data.replace('\r', ''),
            is_default=True
            if sms_sender['is_default'] else form.is_default.data)
        return redirect(url_for('.service_sms_senders', service_id=service_id))

    form.is_default.data = sms_sender['is_default']
    if (request.endpoint == "main.service_confirm_delete_sms_sender"):
        flash("Are you sure you want to delete this text message sender?",
              'delete')
    return render_template('views/service-settings/sms-sender/edit.html',
                           form=form,
                           sms_sender=sms_sender,
                           inbound_number=is_inbound_number,
                           sms_sender_id=sms_sender_id)
示例#2
0
def service_edit_sms_sender(service_id, sms_sender_id):
    if request.form and 'delete' in request.form:
        service_api_client.delete_sms_sender(
            service_id=service_id,
            sms_sender_id=sms_sender_id,
        )
        flash(f'Text message sender {sms_sender_id} deleted',
              'default_with_tick')
        return redirect(url_for('.service_sms_senders', service_id=service_id))

    sms_sender = service_api_client.get_sms_sender(service_id, sms_sender_id)
    is_inbound_number = sms_sender['inbound_number_id']
    if is_inbound_number:
        form = ServiceEditInboundNumberForm(
            is_default=sms_sender['is_default'])
    else:
        form = ServiceSmsSenderForm(**sms_sender)

    if form.validate_on_submit():
        service_api_client.update_sms_sender(
            current_service['id'],
            sms_sender_id=sms_sender_id,
            sms_sender=sms_sender['sms_sender']
            if is_inbound_number else form.sms_sender.data.replace('\r', ''),
            is_default=True
            if sms_sender['is_default'] else form.is_default.data)
        return redirect(url_for('.service_sms_senders', service_id=service_id))

    form.is_default.data = sms_sender['is_default']

    if 'delete' in request.args:
        flash('Are you sure you want to delete this text message sender?',
              'delete')

    return render_template('views/service-settings/sms-sender/edit.html',
                           form=form,
                           sms_sender=sms_sender,
                           inbound_number=is_inbound_number,
                           sms_sender_id=sms_sender_id)
def service_edit_sms_sender(service_id, sms_sender_id):
    sms_sender = service_api_client.get_sms_sender(service_id, sms_sender_id)
    is_inbound_number = sms_sender['inbound_number_id']
    if is_inbound_number:
        form = ServiceEditInboundNumberForm(is_default=sms_sender['is_default'])
    else:
        form = ServiceSmsSenderForm(**sms_sender)

    if form.validate_on_submit():
        service_api_client.update_sms_sender(
            current_service['id'],
            sms_sender_id=sms_sender_id,
            sms_sender=sms_sender['sms_sender'] if is_inbound_number else form.sms_sender.data.replace('\r', ''),
            is_default=True if sms_sender['is_default'] else form.is_default.data
        )
        return redirect(url_for('.service_sms_senders', service_id=service_id))

    form.is_default.data = sms_sender['is_default']
    return render_template(
        'views/service-settings/sms-sender/edit.html',
        form=form,
        sms_sender=sms_sender,
        inbound_number=is_inbound_number
    )