def add_user_satisfaction(admin_client, uuid):
    template_context = base_template_context()
    template_context.update({
        'user': session['oauth_user'],
    })
    form = DonePageURLForm()
    if form.validate_on_submit():
        url = form.data['done_page_url']
        match = re.search('/done/([^/?]+)', url)
        if match is None:
            return redirect(url_for('get_in_touch', uuid=uuid))
        data_group = match.group(1)
        data_type = 'user-satisfaction-score'
        data_set = admin_client.get_data_set(data_group, data_type)
        if data_set is None:
            return redirect(url_for('get_in_touch', uuid=uuid))
        module_config = _module_config({
            'data_group':
            data_group,
            'data_type':
            data_type,
            'type_id':
            _get_user_satisfaction_module_type(admin_client)['id']
        })
        admin_client.add_module_to_dashboard(uuid, module_config)
        return redirect(url_for('dashboard_hub', uuid=uuid))
    if form.errors:
        flash(to_error_list(form.errors), 'danger')
    return render_template('builder/user_satisfaction/add.html',
                           uuid=uuid,
                           form=form,
                           **template_context)
def add_user_satisfaction(admin_client, uuid):
    template_context = base_template_context()
    template_context.update({
        'user': session['oauth_user'],
    })
    form = DonePageURLForm()
    if form.validate_on_submit():
        url = form.data['done_page_url']
        match = re.search('/done/([^/?]+)', url)
        if match is None:
            return redirect(url_for('get_in_touch', uuid=uuid))
        data_group = match.group(1)
        data_type = 'user-satisfaction-score'
        data_set = admin_client.get_data_set(data_group, data_type)
        if data_set is None:
            return redirect(url_for('get_in_touch', uuid=uuid))
        module_config = _module_config({
            'data_group': data_group,
            'data_type': data_type,
            'type_id': _get_user_satisfaction_module_type(admin_client)['id']})
        admin_client.add_module_to_dashboard(uuid, module_config)
        return redirect(url_for('dashboard_hub', uuid=uuid))
    if form.errors:
        flash(to_error_list(form.errors), 'danger')
    return render_template(
        'builder/user_satisfaction/add.html',
        uuid=uuid,
        form=form,
        **template_context)
def about_your_service():
    form = AboutYourServiceForm()
    template_context = base_template_context()
    if form.validate_on_submit():
        session['service_name'] = form.data['service_name']
        session['service_url'] = form.data['service_url']
        session['service_description'] = form.data['service_description']
        send_application_email()
        return redirect(url_for('confirmation'))
    if form.errors:
        flash(to_error_list(form.errors), 'danger')
    return render_template('registrations/about-your-service.html',
                           form=form,
                           **template_context)
def about_your_service():
    form = AboutYourServiceForm()
    template_context = base_template_context()
    if form.validate_on_submit():
        session['service_name'] = form.data['service_name']
        session['service_url'] = form.data['service_url']
        session['service_description'] = form.data['service_description']
        send_application_email()
        return redirect(url_for('confirmation'))
    if form.errors:
        flash(to_error_list(form.errors), 'danger')
    return render_template(
        'registrations/about-your-service.html',
        form=form,
        **template_context)
def about_you():
    admin_client = AdminAPI(app.config['STAGECRAFT_HOST'], None)
    form = AboutYouForm(admin_client)
    template_context = base_template_context()
    if form.validate_on_submit():
        session['full_name'] = form.data['full_name']
        session['email_address'] = form.data['email_address']
        session['organisation_name'] = get_organisation_name(
            form.data['organisation'], form.organisation.choices)
        return redirect(url_for('about_your_service'))
    if form.errors:
        flash(to_error_list(form.errors), 'danger')
    return render_template('registrations/about-you.html',
                           form=form,
                           **template_context)
def about_you():
    admin_client = AdminAPI(app.config['STAGECRAFT_HOST'], None)
    form = AboutYouForm(admin_client)
    template_context = base_template_context()
    if form.validate_on_submit():
        session['full_name'] = form.data['full_name']
        session['email_address'] = form.data['email_address']
        session['organisation_name'] = get_organisation_name(
            form.data['organisation'], form.organisation.choices)
        return redirect(url_for('about_your_service'))
    if form.errors:
        flash(to_error_list(form.errors), 'danger')
    return render_template(
        'registrations/about-you.html',
        form=form,
        **template_context)
def upload_options(admin_client, uuid):
    template_context = base_template_context()
    template_context.update({
        'user': session['oauth_user'],
    })

    form = UploadOptionsForm()
    if form.validate_on_submit():
        session['upload_choice'] = form.data['upload_option']
        if session['upload_choice'] != 'api':
            return redirect(url_for('channel_options', uuid=uuid))
        else:
            return redirect(url_for('api_get_in_touch', uuid=uuid))
    if form.errors:
        flash(to_error_list(form.errors), 'danger')
    return render_template(
        'builder/digital_take_up/upload-options.html',
        uuid=uuid,
        upload_options=[option for option in form.upload_option],
        form=form,
        **template_context)
def dashboard_hub(admin_client, uuid):
    template_context = base_template_context()
    template_context.update({
        'user': session['oauth_user'],
    })
    dashboard_dict = admin_client.get_dashboard(uuid)

    if dashboard_dict['status'] != 'unpublished':
        flash('In review or published dashboards cannot be edited', 'info')
        return redirect(url_for('dashboard_list'))

    Dashboard = namedtuple('Dashboard', dashboard_dict.keys())
    dashboard = Dashboard(**dashboard_dict)
    modules = []
    if "modules" in dashboard_dict.keys():
        modules = [module["data_type"] for module in dashboard_dict["modules"]
                   if 'data_type' in module]
    form = DashboardHubForm(obj=dashboard)
    if form.validate_on_submit():
        data = form.data
        data["slug"] = dashboard_dict["slug"]
        admin_client.update_dashboard(uuid, data)
        flash('Your dashboard has been updated', 'success')
        return redirect(url_for('dashboard_hub', uuid=uuid))
    if form.errors:
        flash(to_error_list(form.errors), 'danger')

    preview_url = "{0}/performance/{1}".format(
        app.config['GOVUK_SITE_URL'], dashboard_dict['slug'])
    return render_template(
        'builder/dashboard-hub.html',
        uuid=uuid,
        dashboard_title=dashboard.title,
        preview_url=preview_url,
        form=form,
        modules=modules,
        **template_context)