def list_services(framework_slug):
    framework = get_framework_or_404(data_api_client,
                                     framework_slug,
                                     allowed_statuses=['live'])

    suppliers_services = data_api_client.find_services(
        supplier_id=current_user.supplier_id,
        framework=framework_slug,
    )["services"]

    return render_template(
        "services/list_services.html",
        services=suppliers_services,
        framework=framework,
    ), 200
Exemplo n.º 2
0
def reset_password(token):
    decoded = decode_password_reset_token(token, data_api_client)
    if 'error' in decoded:
        flash(EXPIRED_PASSWORD_RESET_TOKEN_MESSAGE, "error")
        return redirect(url_for('.request_password_reset'))

    email_address = decoded['email']
    form = PasswordResetForm()
    errors = get_errors_from_wtform(form)

    return render_template("auth/reset-password.html",
                           email_address=email_address,
                           form=form,
                           errors=errors,
                           token=token), 200
def question_and_answer_session(brief_id):
    brief = get_brief(data_api_client, brief_id, allowed_statuses=['live'])

    if brief['clarificationQuestionsAreClosed']:
        abort(404)

    if not is_supplier_eligible_for_brief(data_api_client,
                                          current_user.supplier_id, brief):
        return _render_not_eligible_for_brief_error_page(
            brief, clarification_question=True)

    return render_template(
        "briefs/question_and_answer_session.html",
        brief=brief,
    ), 200
def confirm_copy_all_previous_services(framework_slug, lot_slug):
    framework, lot = get_framework_and_lot_or_404(data_api_client,
                                                  framework_slug,
                                                  lot_slug,
                                                  allowed_statuses=['open'])
    source_framework_slug = content_loader.get_metadata(
        framework['slug'], 'copy_services', 'source_framework')
    source_framework = get_framework_or_500(data_api_client,
                                            source_framework_slug,
                                            logger=current_app.logger)

    return render_template("services/copy_all_services_warning.html",
                           framework=framework,
                           lot=lot,
                           source_framework=source_framework)
def find_supplier_users():

    if not request.args.get('supplier_id'):
        abort(404)

    supplier = data_api_client.get_supplier(request.args['supplier_id'])
    users = data_api_client.find_users_iter(request.args.get("supplier_id"))

    return render_template(
        "view_supplier_users.html",
        users=users,
        invite_form=EmailAddressForm(),
        move_user_form=MoveUserForm(),
        supplier=supplier["suppliers"]
    )
def find_supplier_services(supplier_id):
    remove_services_for_framework_slug = request.args.get('remove')
    publish_services_for_framework_slug = request.args.get('publish')

    frameworks = data_api_client.find_frameworks()['frameworks']
    supplier = data_api_client.get_supplier(supplier_id)["suppliers"]

    frameworks_services = {
        framework_slug: list(framework_services)
        for framework_slug, framework_services in
        groupby(sorted(data_api_client.find_services_iter(
            supplier_id=supplier_id,
            framework=','.join(f['slug'] for f in frameworks if f['status'] in ['live', 'expired'])
        ), key=itemgetter('frameworkSlug')), key=itemgetter('frameworkSlug'))
    }

    remove_services_for_framework, publish_services_for_framework = None, None

    if remove_services_for_framework_slug:
        if remove_services_for_framework_slug not in frameworks_services:
            abort(400, 'No services for framework')
        if not any(i['status'] == 'published' for i in frameworks_services[remove_services_for_framework_slug]):
            abort(400, 'No published services on framework')

        remove_services_for_framework = next(filter(
            lambda i: i['slug'] == remove_services_for_framework_slug,
            frameworks
        ))
    elif publish_services_for_framework_slug:
        if publish_services_for_framework_slug not in frameworks_services:
            abort(400, 'No services for framework')
        if not any(i['status'] == 'disabled' for i in frameworks_services[publish_services_for_framework_slug]):
            abort(400, 'No suspended services on framework')

        publish_services_for_framework = next(filter(
            lambda i: i['slug'] == publish_services_for_framework_slug,
            frameworks
        ))

    return render_template(
        'view_supplier_services.html',
        frameworks=frameworks,
        frameworks_services=frameworks_services,
        supplier=supplier,
        remove_services_for_framework=remove_services_for_framework,
        publish_services_for_framework=publish_services_for_framework,
    )
Exemplo n.º 7
0
def add_supplier_question(framework_slug, lot_slug, brief_id):
    get_framework_and_lot(framework_slug,
                          lot_slug,
                          data_api_client,
                          allowed_statuses=['live', 'expired'],
                          must_allow_brief=True)
    brief = data_api_client.get_brief(brief_id)["briefs"]

    if not is_brief_correct(brief,
                            framework_slug,
                            lot_slug,
                            current_user.id,
                            allowed_statuses=['live']):
        abort(404)

    content = content_loader.get_manifest(brief['frameworkSlug'],
                                          "clarification_question").filter({})
    section = content.get_section(content.get_next_editable_section_id())
    update_data = section.get_data(request.form)

    errors = {}
    status_code = 200

    if request.method == "POST":
        try:
            data_api_client.add_brief_clarification_question(
                brief_id, update_data['question'], update_data['answer'],
                current_user.email_address)

            return redirect(
                url_for('.supplier_questions',
                        framework_slug=brief['frameworkSlug'],
                        lot_slug=brief['lotSlug'],
                        brief_id=brief['id']))
        except HTTPError as e:
            if e.status_code != 400:
                raise
            brief.update(update_data)
            errors = govuk_errors(section.get_error_messages(e.message))
            status_code = 400

    return render_template("buyers/edit_brief_question.html",
                           brief=brief,
                           section=section,
                           question=section.questions[0],
                           button_label="Publish question and answer",
                           errors=errors), status_code
def edit_supplier_registered_address(supplier_id):
    supplier = data_api_client.get_supplier(supplier_id)['suppliers']
    contact = supplier["contactInformation"][0]

    company_details = get_company_details_from_supplier(supplier)

    prefill_data = {
        "street": company_details['address'].get('street_address_line_1'),
        "city": company_details['address'].get('locality'),
        "postcode": company_details['address'].get('postcode'),
        "country": company_details['address']['country']
    }
    form = EditSupplierRegisteredAddressForm(data=prefill_data)

    if form.validate_on_submit():
        # Will update declarations for open frameworks
        data_api_client.update_supplier(
            supplier_id,
            {'registrationCountry': form.country.data},
            current_user.email_address
        )
        # Will update declarations for open frameworks
        data_api_client.update_contact_information(
            supplier_id,
            contact['id'],
            {
                'country': form.country.data,
                'address1': form.street.data,
                'city': form.city.data,
                'postcode': form.postcode.data,
            },
            current_user.email_address
        )

        flash(SUPPLIER_DETAILS_UPDATED_MESSAGE.format(supplier_name=supplier['name']))
        return redirect(url_for('.supplier_details', supplier_id=supplier_id))

    errors = get_errors_from_wtform(form)

    return render_template(
        "suppliers/edit_registered_address.html",
        supplier=supplier,
        form=form,
        countries=COUNTRY_TUPLE,
        errors=errors,
    ), 200 if not errors else 400
Exemplo n.º 9
0
def find_user_by_email_address():
    users = None
    email_address = None
    response_code = 200

    if "email_address" in request.args:
        email_address = request.args.get("email_address")
        if email_address:
            users = data_api_client.get_user(email_address=email_address)
        if not users:
            flash("Sorry, we couldn't find an account with that email address",
                  'error')
            response_code = 404

    return render_template("view_users.html",
                           users=[users['users']] if users else list(),
                           email_address=email_address), response_code
def view_supplier_declaration(supplier_id, framework_slug):
    if framework_slug in DEPRECATED_FRAMEWORK_SLUGS:
        abort(404)

    supplier = data_api_client.get_supplier(supplier_id)['suppliers']
    framework = data_api_client.get_framework(framework_slug)['frameworks']
    if framework['status'] not in (
            'pending',
            'standstill',
            'live',
            'expired',
    ):
        abort(403)
    try:
        sf = data_api_client.get_supplier_framework_info(
            supplier_id, framework_slug)["frameworkInterest"]
    except APIError as e:
        if e.status_code != 404:
            raise
        sf = {}

    content = content_loader.get_manifest(
        framework_slug,
        'declaration',
    ).filter(sf.get("declaration", {}), inplace_allowed=True)
    declaration_sections = content.sections
    question_content = OrderedDict(
        (question.id, question)
        for question in sorted(chain.from_iterable(
            section.questions for section in declaration_sections),
                               key=lambda question: question.number))
    # Enhance question_content with any nested questions
    for question in chain.from_iterable(section.questions
                                        for section in declaration_sections):
        if question.type == 'multiquestion':
            for q in question.questions:
                question_content[q.id] = q

    return render_template("suppliers/view_declaration.html",
                           supplier=supplier,
                           framework=framework,
                           supplier_framework=sf,
                           declaration=sf.get("declaration", {}),
                           content=content,
                           question_content=question_content)
def edit_what_buyers_will_see():

    supplier = data_api_client.get_supplier(
        current_user.supplier_id
    )['suppliers']

    contact = supplier["contactInformation"][0]

    prefill_data = {
        "contactName": contact.get("contactName"),
        "phoneNumber": contact.get("phoneNumber"),
        "email": contact.get("email"),
        "description": supplier.get("description"),
    }

    form = EditSupplierInformationForm(data=prefill_data)

    if form.validate_on_submit():
        data_api_client.update_supplier(
            current_user.supplier_id,
            {
                "description": form.description.data,
            },
            current_user.email_address
        )

        data_api_client.update_contact_information(
            current_user.supplier_id,
            contact["id"],
            {
                "contactName": form.contactName.data,
                "phoneNumber": form.phoneNumber.data,
                "email": form.email.data,
            },
            current_user.email_address
        )
        return redirect(url_for(".supplier_details"))

    errors = get_errors_from_wtform(form)

    return render_template(
        "suppliers/edit_what_buyers_will_see.html",
        form=form,
        errors=errors,
    ), 200 if not errors else 400
def view_service(service_id):
    try:
        service = data_api_client.get_service(service_id)
        if service is None:
            flash(NO_SERVICE_MESSAGE.format(service_id=service_id), 'error')
            return redirect(url_for('.search_suppliers_and_services'))
        service_data = service['services']
    except HTTPError:
        flash(API_ERROR_MESSAGE.format(service_id=service_id), 'error')
        return redirect(url_for('.search_suppliers_and_services'))

    framework = get_framework_or_404(data_api_client,
                                     service_data['frameworkSlug'],
                                     allowed_statuses=['live', 'expired'])

    removed_by = removed_at = None
    if service_data['status'] != 'published':
        most_recent_audit_events = data_api_client.find_audit_events(
            latest_first="true",
            object_id=service_id,
            object_type="services",
            audit_type=AuditTypes.update_service_status)
        if most_recent_audit_events.get('auditEvents'):
            removed_by = most_recent_audit_events['auditEvents'][0]['user']
            removed_at = most_recent_audit_events['auditEvents'][0][
                'createdAt']

    service_data['priceString'] = format_service_price(service_data)
    sections = content_loader.get_manifest(
        service_data['frameworkSlug'],
        'edit_service_as_admin',
    ).filter(service_data, inplace_allowed=True).summary(service_data,
                                                         inplace_allowed=True)

    return render_template(
        "view_service.html",
        framework=framework,
        sections=sections,
        service_data=service_data,
        service_id=service_id,
        removed_by=removed_by,
        removed_at=removed_at,
        remove=request.args.get('remove', None),
        publish=request.args.get('publish', None),
    )
def invite_user(supplier_id):
    invite_form = EmailAddressForm()

    try:
        suppliers = data_api_client.get_supplier(supplier_id)
        users = data_api_client.find_users_iter(supplier_id)
    except HTTPError as e:
        current_app.logger.error(str(e), supplier_id)
        if e.status_code != 404:
            raise
        else:
            abort(404, "Supplier not found")

    if invite_form.validate_on_submit():
        send_user_account_email(
            'supplier',
            invite_form.email_address.data,
            current_app.config['NOTIFY_TEMPLATES']['invite_contributor'],
            extra_token_data={
                'supplier_id': supplier_id,
                'supplier_name': suppliers['suppliers']['name']
            },
            personalisation={
                'user': '******',
                'supplier': suppliers['suppliers']['name']
            }
        )

        data_api_client.create_audit_event(
            audit_type=AuditTypes.invite_user,
            user=current_user.email_address,
            object_type='suppliers',
            object_id=supplier_id,
            data={'invitedEmail': invite_form.email_address.data})

        flash(SUPPLIER_USER_MESSAGES['user_invited'])
        return redirect(url_for('.find_supplier_users', supplier_id=supplier_id))
    else:
        return render_template(
            "view_supplier_users.html",
            invite_form=invite_form,
            move_user_form=MoveUserForm(),
            users=users,
            supplier=suppliers["suppliers"]
        ), 400
def delete_a_brief_warning(framework_slug, lot_slug, brief_id):
    framework, lot = get_framework_and_lot(
        framework_slug,
        lot_slug,
        data_api_client,
        allowed_statuses=['live', 'expired'],
        must_allow_brief=True)
    brief = data_api_client.get_brief(brief_id)["briefs"]

    if not is_brief_correct(brief, framework_slug, lot_slug,
                            current_user.id) or not brief_can_be_edited(brief):
        abort(404)

    return render_template(
        "buyers/delete_brief.html",
        framework=framework,
        brief=brief,
    ), 200
Exemplo n.º 15
0
def create_your_account():
    current_app.logger.info(
        "suppliercreate: {} create-your-account supplier_id:{}".format(
            request.method, session.get('email_supplier_id', 'unknown')))

    form = EmailAddressForm()
    if form.validate_on_submit():
        session['account_email_address'] = form.email_address.data
        return redirect(url_for(".company_summary"))

    errors = get_errors_from_wtform(form)

    return render_template(
        "suppliers/create_your_account.html",
        form=form,
        errors=errors,
        email_address=form.email_address.data if form.email_address.data else
        session.get('account_email_address', '')), 200 if not errors else 400
def view_brief_timeline(framework_slug, lot_slug, brief_id):
    get_framework_and_lot(framework_slug,
                          lot_slug,
                          data_api_client,
                          allowed_statuses=['live', 'expired'],
                          must_allow_brief=True)
    brief = data_api_client.get_brief(brief_id)["briefs"]
    if not is_brief_correct(brief, framework_slug, lot_slug,
                            current_user.id) or brief.get('status') != 'live':
        abort(404)

    dates = get_publishing_dates(brief)

    return render_template("buyers/brief_publish_confirmation.html",
                           email_address=brief['users'][0]['emailAddress'],
                           published=True,
                           brief=brief,
                           dates=dates), 200
def start_brief_response(brief_id):
    brief = get_brief(data_api_client, brief_id, allowed_statuses=['live'])

    if not is_supplier_eligible_for_brief(data_api_client,
                                          current_user.supplier_id, brief):
        return _render_not_eligible_for_brief_error_page(brief)

    brief_response = data_api_client.find_brief_responses(
        brief_id=brief_id,
        supplier_id=current_user.supplier_id,
        status='draft,submitted')['briefResponses']

    if brief_response and brief_response[0]['status'] == 'submitted':
        return redirect(
            url_for(".check_brief_response_answers",
                    brief_id=brief_id,
                    brief_response_id=brief_response[0]['id']))

    if request.method == 'POST':
        if brief_response and brief_response[0]['status'] == 'draft':
            return redirect(
                url_for('.edit_brief_response',
                        brief_id=brief_id,
                        brief_response_id=brief_response[0]['id']))
        else:
            brief_response = data_api_client.create_brief_response(
                brief_id,
                current_user.supplier_id,
                {},
                current_user.email_address,
            )['briefResponses']
            brief_response_id = brief_response['id']
            return redirect(
                url_for('.edit_brief_response',
                        brief_id=brief_id,
                        brief_response_id=brief_response_id))

    existing_draft_response = False
    if brief_response and brief_response[0]['status'] == 'draft':
        existing_draft_response = brief_response[0]

    return render_template("briefs/start_brief_response.html",
                           brief=brief,
                           existing_draft_response=existing_draft_response)
def edit_registered_address():
    supplier = data_api_client.get_supplier(current_user.supplier_id)["suppliers"]
    contact = supplier["contactInformation"][0]

    prefill_data = {
        "street": contact.get("address1"),
        "city": contact.get("city"),
        "postcode": contact.get("postcode"),
        "country": supplier.get("registrationCountry"),
    }

    registered_address_form = EditRegisteredAddressForm(data=prefill_data)

    if registered_address_form.validate_on_submit():
        data_api_client.update_supplier(
            current_user.supplier_id,
            {
                "registrationCountry": registered_address_form.country.data,
            },
            current_user.email_address,
        )

        data_api_client.update_contact_information(
            current_user.supplier_id,
            contact["id"],
            {
                "address1": registered_address_form.street.data,
                "city": registered_address_form.city.data,
                "postcode": registered_address_form.postcode.data,
            },
            current_user.email_address
        )

        return redirect(url_for(".supplier_details"))

    errors = get_errors_from_wtform(registered_address_form)

    return render_template(
        "suppliers/registered_address.html",
        supplier=supplier,
        countries=COUNTRY_TUPLE,
        form=registered_address_form,
        errors=errors,
    ), 200 if not errors else 400
def find_supplier_draft_services(supplier_id):
    supplier = data_api_client.get_supplier(supplier_id)["suppliers"]
    frameworks = data_api_client.find_frameworks()['frameworks']

    if current_user.has_role('admin-ccs-sourcing'):
        visible_framework_statuses = [
            "pending", "standstill", "live", "expired"
        ]
    elif current_user.has_role('admin-framework-manager'):
        visible_framework_statuses = [
            "open", "pending", "standstill", "live", "expired"
        ]
    else:
        # No other roles can access this page yet, but we might want to add them later
        visible_framework_statuses = []

    frameworks = (fw for fw in frameworks
                  if fw['status'] in visible_framework_statuses)

    frameworks_draft_services = {
        framework_slug: draft_services
        for framework_slug, draft_services in (
            (
                framework_slug,
                _draft_services_annotated_unanswered_counts(
                    framework_slug, draft_services),
            ) for framework_slug, draft_services in groupby(
                sorted(
                    data_api_client.find_draft_services_iter(supplier_id),
                    key=lambda draft_service: (draft_service["frameworkSlug"],
                                               draft_service["createdAt"]),
                ),
                key=lambda draft_service: draft_service["frameworkSlug"]))
        if draft_services is
        not None  # omit frameworks for which we couldn't retrieve the manifest
    }

    return render_template(
        'view_supplier_draft_services.html',
        frameworks=frameworks,
        frameworks_draft_services=frameworks_draft_services,
        supplier=supplier,
    )
def buyer_dashboard():
    user_projects_awaiting_outcomes_total = data_api_client.find_direct_award_projects(
        current_user.id,
        locked=True,
        having_outcome=False,
    )["meta"]["total"]

    return render_template(
        'buyers/index.html',
        user_briefs_total=data_api_client.find_briefs(
            current_user.id)["meta"]["total"],
        user_projects_awaiting_outcomes_total=
        user_projects_awaiting_outcomes_total,
        # calculating it this way allows us to avoid the extra api call if we already know the user has projects
        # from user_projects_awaiting_outcomes_total
        user_has_projects=bool(user_projects_awaiting_outcomes_total
                               or data_api_client.find_direct_award_projects(
                                   current_user.id)["meta"]["total"]),
    )
def list_all_services(framework_slug):
    if not (is_g12_recovery_supplier(current_user.supplier_id)
            and framework_slug == "g-cloud-12"):
        abort(404)

    framework = get_framework_or_404(data_api_client,
                                     framework_slug,
                                     allowed_statuses=['live'])

    suppliers_services = data_api_client.find_services(
        supplier_id=current_user.supplier_id,
        framework=framework_slug,
    )["services"]

    drafts, complete_drafts = get_drafts(data_api_client, framework_slug)

    service_sections = content_loader.get_manifest(
        framework_slug,
        'edit_submission',
    )

    for draft in drafts:
        sections = service_sections.filter(context={
            'lot': draft["lotSlug"]
        }).summary(draft, inplace_allowed=True)

        unanswered_required, unanswered_optional = count_unanswered_questions(
            sections)
        draft.update({
            'unanswered_required': unanswered_required,
            'unanswered_optional': unanswered_optional,
        })

    # Only G12 recovery suppliers can access this route, so always show the banner
    g12_recovery = {'time_remaining': g12_recovery_time_remaining()}

    return render_template("services/list_all_services.html",
                           framework=framework,
                           drafts=drafts,
                           complete_drafts=complete_drafts,
                           services=suppliers_services,
                           g12_recovery=g12_recovery), 200
def view_brief_section_summary(framework_slug, lot_slug, brief_id,
                               section_slug):
    get_framework_and_lot(framework_slug,
                          lot_slug,
                          data_api_client,
                          allowed_statuses=['live', 'expired'],
                          must_allow_brief=True)
    brief = data_api_client.get_brief(brief_id)["briefs"]

    if not is_brief_correct(brief, framework_slug, lot_slug,
                            current_user.id) or not brief_can_be_edited(brief):
        abort(404)

    content = content_loader.get_manifest(
        brief['frameworkSlug'], 'edit_brief').filter({'lot': brief['lotSlug']})
    sections = content.summary(brief)
    section = sections.get_section(section_slug)

    if not section:
        abort(404)

    section.summary_list = []
    for question in section.questions:
        section.summary_list.append(
            to_summary_list_row(question,
                                action_link=url_for(
                                    'buyers.edit_brief_question',
                                    framework_slug=framework_slug,
                                    lot_slug=lot_slug,
                                    brief_id=brief_id,
                                    section_slug=section_slug,
                                    question_id=question.id)))

    # Show preview link if all mandatory questions have been answered
    unanswered_required, unanswered_optional = count_unanswered_questions(
        sections)
    show_dos_preview_link = (unanswered_required == 0)

    return render_template("buyers/section_summary.html",
                           brief=brief,
                           section=section,
                           show_dos_preview_link=show_dos_preview_link), 200
Exemplo n.º 23
0
def user_list_page_for_framework(framework_slug):
    framework = data_api_client.get_framework(framework_slug).get("frameworks")
    if framework is None or framework['status'] == 'coming' or (
            framework['status'] == 'expired'
            and framework['family'] != 'digital-outcomes-and-specialists'):
        abort(404)

    supplier_csv_url = url_for('.download_supplier_user_list_report',
                               framework_slug=framework_slug,
                               report_type='official')
    user_csv_url = url_for('.download_supplier_user_list_report',
                           framework_slug=framework_slug,
                           report_type='accounts')

    return render_template(
        "download_framework_users.html",
        framework=framework,
        supplier_csv_url=supplier_csv_url,
        user_csv_url=user_csv_url,
    ), 200
Exemplo n.º 24
0
def supplier_user_research_participants_by_framework():
    frameworks = data_api_client.find_frameworks().get("frameworks")
    frameworks = sorted(
        (fw for fw in frameworks
         if not (fw['status'] == 'coming' or
                 (fw['status'] == 'expired'
                  and fw['family'] != 'digital-outcomes-and-specialists'))),
        key=lambda i: i['name'],
    )

    items = [{
        "title":
        "User research participants on {}".format(framework['name']),
        "link":
        url_for('.download_supplier_user_research_report',
                framework_slug=framework['slug']),
        "file_type":
        "CSV"
    } for framework in frameworks]
    return render_template("user_research_participants.html", items=items), 200
def create_new_brief(framework_slug, lot_slug):

    framework, lot = get_framework_and_lot(framework_slug,
                                           lot_slug,
                                           data_api_client,
                                           allowed_statuses=['live'],
                                           must_allow_brief=True)

    content = content_loader.get_manifest(framework_slug, 'edit_brief').filter(
        {'lot': lot['slug']})

    section = content.get_section(content.get_next_editable_section_id())

    update_data = section.get_data(request.form)

    try:
        brief = data_api_client.create_brief(
            framework_slug,
            lot_slug,
            current_user.id,
            update_data,
            updated_by=current_user.email_address,
            page_questions=section.get_field_names())["briefs"]
    except HTTPError as e:
        update_data = section.unformat_data(update_data)
        errors = govuk_errors(section.get_error_messages(e.message))

        return render_template("buyers/create_brief_question.html",
                               data=update_data,
                               brief={},
                               framework=framework,
                               lot=lot,
                               section=section,
                               question=section.questions[0],
                               errors=errors), 400

    return redirect(
        url_for(".view_brief_overview",
                framework_slug=framework_slug,
                lot_slug=lot_slug,
                brief_id=brief['id']))
def find_suppliers():
    if request.args.get("supplier_id"):
        suppliers = [data_api_client.get_supplier(request.args.get("supplier_id"))['suppliers']]
        links = {}
    else:
        duns_number = request.args.get("supplier_duns_number").strip() \
            if request.args.get("supplier_duns_number") else None
        suppliers_response = data_api_client.find_suppliers(
            name=request.args.get("supplier_name"),
            duns_number=duns_number,
            company_registration_number=request.args.get("supplier_company_registration_number"),
            page=request.args.get("page", 1)  # API will validate page number values
        )
        suppliers = suppliers_response['suppliers']
        links = suppliers_response["links"]

    frameworks = data_api_client.find_frameworks()['frameworks']
    try:
        oldest_interesting_framework_id = [
            fw for fw in frameworks if fw['slug'] == OLDEST_INTERESTING_FRAMEWORK_SLUG
        ][0]['id']
    except IndexError:
        current_app.logger.error(f'No framework found with slug: "{OLDEST_INTERESTING_FRAMEWORK_SLUG}"')
        abort(500)

    interesting_frameworks = sorted(
        [framework for framework in frameworks if framework['id'] >= oldest_interesting_framework_id
            and framework['status'] != 'coming'],
        key=lambda fw: fw['id'],
        reverse=True,
    )

    return render_template(
        "view_suppliers.html",
        suppliers=suppliers,
        agreement_filename=AGREEMENT_FILENAME,
        interesting_frameworks=interesting_frameworks,
        old_flow_slugs=OLD_SIGNING_FLOW_SLUGS,
        prev_link=get_nav_args_from_api_response_links(links, 'prev', request.args, ['supplier_name']),
        next_link=get_nav_args_from_api_response_links(links, 'next', request.args, ['supplier_name']),
    )
def confirm_draft_service_delete(framework_slug, lot_slug, service_id):
    framework, lot = get_framework_and_lot_or_404(data_api_client,
                                                  framework_slug,
                                                  lot_slug,
                                                  allowed_statuses=['open'])

    draft = get_draft_service_or_404(data_api_client, service_id,
                                     framework_slug, lot_slug)

    if draft['lotSlug'] != lot_slug or draft['frameworkSlug'] != framework_slug:
        abort(404)

    if not is_service_associated_with_supplier(draft):
        abort(404)

    return render_template("services/delete_draft_service.html",
                           framework=framework,
                           service_id=service_id,
                           service_data=draft,
                           lot_slug=lot_slug,
                           lot=lot)
def start_new_brief(framework_slug, lot_slug):

    framework, lot = get_framework_and_lot(framework_slug,
                                           lot_slug,
                                           data_api_client,
                                           allowed_statuses=['live'],
                                           must_allow_brief=True)

    content = content_loader.get_manifest(framework_slug, 'edit_brief').filter(
        {'lot': lot['slug']})

    section = content.get_section(content.get_next_editable_section_id())

    return render_template(
        "buyers/create_brief_question.html",
        brief={},
        framework=framework,
        lot=lot,
        section=section,
        question=section.questions[0],
    ), 200
def supplier_details(supplier_id):
    frameworks = data_api_client.find_frameworks()["frameworks"]
    supplier = data_api_client.get_supplier(supplier_id)["suppliers"]
    supplier_frameworks = data_api_client.get_supplier_frameworks(supplier_id)["frameworkInterest"]

    # Get SupplierFrameworks for frameworks the role is interested in, sorted by oldest frameworkLiveAtUTC first
    visible_supplier_frameworks = get_supplier_frameworks_visible_for_role(
        supplier_frameworks, current_user, frameworks
    )

    # Get the company details
    company_details = get_company_details_from_supplier(supplier)

    return render_template(
        "supplier_details.html",
        company_details=company_details,
        supplier=supplier,
        supplier_id=supplier_id,
        supplier_frameworks=visible_supplier_frameworks,
        old_interesting_framework_slugs=OLD_SIGNING_FLOW_SLUGS,
    )
Exemplo n.º 30
0
def company_details():
    form = CompanyPublicContactInformationForm()

    if request.method == "POST":
        if form.validate_on_submit():
            session[form.company_name.name] = form.company_name.data
            session[form.email_address.name] = form.email_address.data
            session[form.phone_number.name] = form.phone_number.data
            session[form.contact_name.name] = form.contact_name.data
            return redirect(url_for(".create_your_account"))
        else:
            current_app.logger.warning(
                "suppliercreate.fail: duns:{duns} {form_errors}",
                extra={
                    'duns':
                    session.get('duns_number'),
                    'form_errors':
                    ",".join(chain.from_iterable(form.errors.values()))
                })

    else:
        if form.company_name.name in session:
            form.company_name.data = session[form.company_name.name]

        if form.contact_name.name in session:
            form.contact_name.data = session[form.contact_name.name]

        if form.email_address.name in session:
            form.email_address.data = session[form.email_address.name]

        if form.phone_number.name in session:
            form.phone_number.data = session[form.phone_number.name]

    errors = get_errors_from_wtform(form)

    return render_template(
        "suppliers/create_company_details.html",
        form=form,
        errors=errors,
    ), 200 if not errors else 400