def test_update_framework_with_formatted_dates():
    framework = {
        'clarificationsCloseAtUTC': '2000-01-01T12:00:00.000000Z',
        'clarificationsPublishAtUTC': '2000-01-02T12:00:00.000000Z',
        'applicationsCloseAtUTC': '2000-01-03T17:00:00.000000Z',
        'intentionToAwardAtUTC': '2000-01-04T12:00:00.000000Z',
        'frameworkLiveAtUTC': '2000-01-05T12:00:00.000000Z',
        'frameworkExpiresAtUTC': '2000-01-06T12:00:00.000000Z',
    }

    dates_package.update_framework_with_formatted_dates(framework)

    assert framework == {
        'clarificationsCloseAtUTC': '2000-01-01T12:00:00.000000Z',
        'clarificationsPublishAtUTC': '2000-01-02T12:00:00.000000Z',
        'applicationsCloseAtUTC': '2000-01-03T17:00:00.000000Z',
        'intentionToAwardAtUTC': '2000-01-04T12:00:00.000000Z',
        'frameworkLiveAtUTC': '2000-01-05T12:00:00.000000Z',
        'frameworkExpiresAtUTC': '2000-01-06T12:00:00.000000Z',
        'clarificationsCloseAt': '12pm GMT, Saturday 1 January 2000',
        'clarificationsPublishAt': '12pm GMT, Sunday 2 January 2000',
        'applicationsCloseAt': '5pm GMT, Monday 3 January 2000',
        'intentionToAwardAt': 'Tuesday 4 January 2000',
        'frameworkLiveAt': 'Wednesday 5 January 2000',
        'frameworkExpiresAt': 'Thursday 6 January 2000',
    }
Exemple #2
0
def view_service_submission(framework_slug, lot_slug, service_id):
    framework, lot = get_framework_and_lot_or_404(data_api_client,
                                                  framework_slug, lot_slug)
    update_framework_with_formatted_dates(framework)

    # check if g12 recovery supplier
    g12_recovery = None
    if (framework_slug == "g-cloud-12" and framework["status"] == "live"
            and is_g12_recovery_supplier(current_user.supplier_id)):
        # we want this page to appear as it would if g12 were open
        framework["status"] = "open"
        framework["applicationsCloseAt"] = utctoshorttimelongdateformat(
            G12_RECOVERY_DEADLINE)
        not_submitted_count, submitted_count = count_g12_recovery_drafts_by_status(
            data_api_client, current_user.supplier_id)
        g12_recovery = {
            'time_remaining': g12_recovery_time_remaining(),
            'not_submitted_drafts': not_submitted_count,
            'submitted_drafts': submitted_count
        }

    try:
        data = data_api_client.get_draft_service(service_id)
        draft, last_edit, validation_errors = data['services'], data[
            'auditEvents'], data['validationErrors']
    except HTTPError as e:
        abort(e.status_code)

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

    if not is_service_associated_with_supplier(draft):
        abort(404)

    sections = content_loader.get_manifest(
        framework['slug'],
        'edit_submission',
    ).filter(draft, inplace_allowed=True).summary(draft, inplace_allowed=True)

    unanswered_required, unanswered_optional = count_unanswered_questions(
        sections)
    delete_requested = True if request.args.get('delete_requested') else False

    return render_template(
        "services/service_submission.html",
        framework=framework,
        lot=lot,
        confirm_remove=request.args.get("confirm_remove", None),
        service_id=service_id,
        service_data=draft,
        last_edit=last_edit,
        sections=sections,
        unanswered_required=unanswered_required,
        unanswered_optional=unanswered_optional,
        can_mark_complete=not validation_errors,
        delete_requested=delete_requested,
        declaration_status=get_declaration_status(data_api_client,
                                                  framework['slug']),
        g12_recovery=g12_recovery,
    ), 200
Exemple #3
0
def dashboard():
    supplier = data_api_client.get_supplier(
        current_user.supplier_id)['suppliers']
    supplier['contact'] = supplier['contactInformation'][0]

    all_frameworks = sorted(data_api_client.find_frameworks()['frameworks'],
                            key=lambda framework: framework['slug'],
                            reverse=True)
    supplier_frameworks = {
        framework['frameworkSlug']: framework
        for framework in data_api_client.get_supplier_frameworks(
            current_user.supplier_id)['frameworkInterest']
    }

    for framework in all_frameworks:
        framework.update(supplier_frameworks.get(framework['slug'], {}))

        update_framework_with_formatted_dates(framework)
        framework.update({
            'deadline':
            Markup(f"Deadline: {framework['applicationsCloseAt']}"),
            'registered_interest': (framework['slug'] in supplier_frameworks),
            'made_application':
            (framework.get('declaration')
             and framework['declaration'].get('status') == 'complete'
             and framework.get('complete_drafts_count') > 0),
            'needs_to_complete_declaration':
            (framework.get('onFramework')
             and framework.get('agreementReturned') is False)
        })

    if "currently_applying_to" in session:
        del session["currently_applying_to"]

    # TODO remove the `dos3` key from the frameworks dict below. It's a temporary fix until a better designed solution
    # can be implemented.
    return render_template(
        "suppliers/dashboard.html",
        supplier=supplier,
        frameworks={
            'coming':
            get_frameworks_by_status(all_frameworks, 'coming'),
            'open':
            get_frameworks_by_status(all_frameworks, 'open'),
            'pending':
            get_frameworks_by_status(all_frameworks, 'pending'),
            'standstill':
            get_frameworks_by_status(all_frameworks, 'standstill',
                                     'made_application'),
            'live':
            get_frameworks_by_status(all_frameworks, 'live', 'services_count'),
            'dos3': [
                f for f in all_frameworks
                if f['slug'] == 'digital-outcomes-and-specialists-3'
                and f.get('onFramework')
            ],
        }), 200
Exemple #4
0
def dashboard():
    supplier = data_api_client.get_supplier(
        current_user.supplier_id)['suppliers']
    supplier['contact'] = supplier['contactInformation'][0]

    all_frameworks = sorted(data_api_client.find_frameworks()['frameworks'],
                            key=lambda framework: framework['slug'],
                            reverse=True)
    supplier_frameworks = {
        framework['frameworkSlug']: framework
        for framework in data_api_client.get_supplier_frameworks(
            current_user.supplier_id)['frameworkInterest']
    }

    for framework in all_frameworks:
        framework.update(supplier_frameworks.get(framework['slug'], {}))

        update_framework_with_formatted_dates(framework)
        framework.update({
            'deadline':
            Markup(f"Deadline: {framework['applicationsCloseAt']}"),
            'registered_interest': (framework['slug'] in supplier_frameworks),
            'made_application':
            (framework.get('declaration')
             and framework['declaration'].get('status') == 'complete'
             and framework.get('complete_drafts_count') > 0),
            'needs_to_return_agreement':
            (framework.get('onFramework')
             and framework.get('agreementReturned') is False),
            'contract_title':
            get_framework_contract_title(framework)
        })

    if "currently_applying_to" in session:
        del session["currently_applying_to"]

    return render_template(
        "suppliers/dashboard.html",
        supplier=supplier,
        frameworks={
            'coming':
            get_frameworks_by_status(all_frameworks, 'coming'),
            'open':
            get_frameworks_by_status(all_frameworks, 'open'),
            'pending':
            get_frameworks_by_status(all_frameworks, 'pending'),
            'standstill':
            get_frameworks_by_status(all_frameworks, 'standstill',
                                     'made_application'),
            'live':
            get_frameworks_by_status(all_frameworks, 'live', 'onFramework'),
            'last_dos':
            get_most_recent_expired_dos_framework(all_frameworks),
        }), 200
def view_service_submission(framework_slug, lot_slug, service_id):
    framework, lot = get_framework_and_lot_or_404(data_api_client, framework_slug, lot_slug)
    update_framework_with_formatted_dates(framework)

    try:
        data = data_api_client.get_draft_service(service_id)
        draft, last_edit, validation_errors = data['services'], data['auditEvents'], data['validationErrors']
    except HTTPError as e:
        abort(e.status_code)

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

    if not is_service_associated_with_supplier(draft):
        abort(404)

    sections = content_loader.get_manifest(
        framework['slug'],
        'edit_submission',
    ).filter(draft, inplace_allowed=True).summary(draft, inplace_allowed=True)

    unanswered_required, unanswered_optional = count_unanswered_questions(sections)
    delete_requested = True if request.args.get('delete_requested') else False

    return render_template(
        "services/service_submission.html",
        framework=framework,
        lot=lot,
        confirm_remove=request.args.get("confirm_remove", None),
        service_id=service_id,
        service_data=draft,
        last_edit=last_edit,
        sections=sections,
        unanswered_required=unanswered_required,
        unanswered_optional=unanswered_optional,
        can_mark_complete=not validation_errors,
        delete_requested=delete_requested,
        declaration_status=get_declaration_status(data_api_client, framework['slug'])
    ), 200
        def decorated_view(*args, **kwargs):
            data_api_client = data_api_client_callable()
            if 'framework_slug' not in kwargs:
                current_app.logger.error(
                    "Required parameter `framework_slug` is undefined for the calling view."
                )
                abort(500)

            framework_slug = kwargs['framework_slug']
            framework = get_framework_or_404(data_api_client, framework_slug)

            if not (framework['status'] == 'open' or
                    (is_g12_recovery_supplier(current_user.supplier_id)
                     and framework_slug == "g-cloud-12")):
                current_app.logger.info(
                    'Supplier {supplier_id} requested "{method} {path}" after {framework_slug} applications closed.',
                    extra={
                        'supplier_id': current_user.supplier_id,
                        'method': request.method,
                        'path': request.path,
                        'framework_slug': framework_slug
                    })

                update_framework_with_formatted_dates(framework)

                try:
                    following_framework_content = content_loader.get_metadata(
                        framework_slug, 'following_framework', 'framework')
                except ContentNotFoundError:
                    following_framework_content = None

                return render_template(
                    'errors/applications_closed.html',
                    framework=framework,
                    following_framework_content=following_framework_content,
                ), 404
            else:
                return func(*args, **kwargs)
Exemple #7
0
    def __init__(self,
                 client,
                 target_framework_slug,
                 *,
                 intention_to_award_at=None,
                 supplier_ids=None):
        """Get the target framework to operate on and list the lots.

        :param client: Instantiated api client
        :param target_framework_slug str: Framework to fetch data for
        :param intention_to_award_at: Date at which framework agreements will be awarded
        :param supplier_ids: List of supplier IDs to fetch data for
        """
        super().__init__(client,
                         target_framework_slug,
                         supplier_ids=supplier_ids)

        self.framework = self.client.get_framework(
            self.target_framework_slug)["frameworks"]
        update_framework_with_formatted_dates(self.framework)
        if intention_to_award_at is None:
            self.intention_to_award_at = self.framework["intentionToAwardAt"]
        else:
            self.intention_to_award_at = intention_to_award_at
NOTIFY_TEMPLATE_NO_APPLICATION = '87a126b4-7909-4b63-b981-d3c3d6a558ff'

if __name__ == '__main__':
    arguments = docopt(__doc__)

    STAGE = arguments['<stage>']
    FRAMEWORK_SLUG = arguments['<framework_slug>']
    GOVUK_NOTIFY_API_KEY = arguments['<govuk_notify_api_key>']
    DRY_RUN = arguments['--dry-run']

    mail_client = scripts_notify_client(GOVUK_NOTIFY_API_KEY, logger=logger)
    api_client = DataAPIClient(base_url=get_api_endpoint_from_stage(STAGE),
                               auth_token=get_auth_token('api', STAGE))

    framework_data = api_client.get_framework(FRAMEWORK_SLUG)['frameworks']
    update_framework_with_formatted_dates(framework_data)

    context_helper = AppliedToFrameworkSupplierContextForNotify(
        api_client, FRAMEWORK_SLUG, framework_data['intentionToAwardAt'])
    context_helper.populate_data()
    context_data = context_helper.get_users_personalisations()
    error_count = 0
    for user_email, personalisation in context_data.items():
        logger.info(user_email)
        template_id = (NOTIFY_TEMPLATE_APPLICATION_MADE
                       if personalisation['applied'] else
                       NOTIFY_TEMPLATE_NO_APPLICATION)
        if DRY_RUN:
            logger.info("[Dry Run] Sending email {} to {}".format(
                template_id, user_email))
        else:
Exemple #9
0
def dashboard():
    supplier = data_api_client.get_supplier(
        current_user.supplier_id
    )['suppliers']
    supplier['contact'] = supplier['contactInformation'][0]

    supplier['g12_recovery'] = is_g12_recovery_supplier(supplier['id'])

    all_frameworks = list(sorted(
        data_api_client.find_frameworks()['frameworks'],
        key=lambda framework: framework['slug'],
        reverse=True
    ))
    supplier_frameworks = {
        framework['frameworkSlug']: framework
        for framework in data_api_client.get_supplier_frameworks(current_user.supplier_id)['frameworkInterest']
    }

    # g12 should always be in frameworks.live for recovery suppliers
    if supplier["g12_recovery"]:
        if "g-cloud-12" not in supplier_frameworks:
            g12 = next(filter(lambda f: f["slug"] == "g-cloud-12", all_frameworks), None)
            if g12:
                supplier_frameworks["g-cloud-12"] = g12
            del g12

    for framework in all_frameworks:
        framework.update(
            supplier_frameworks.get(framework['slug'], {})
        )

        update_framework_with_formatted_dates(framework)
        framework.update({
            'deadline': Markup(f"Deadline: {framework['applicationsCloseAt']}"),
            'registered_interest': (framework['slug'] in supplier_frameworks),
            'made_application': (
                framework.get('declaration')
                and framework['declaration'].get('status') == 'complete'
                and framework.get('complete_drafts_count') > 0
            ),
            'needs_to_return_agreement': (
                framework.get('onFramework') and framework.get('agreementReturned') is False
            ),
            'is_e_signature_supported': is_e_signature_supported_framework(framework['slug']),
        })
        if framework['slug'] == 'g-cloud-12' and supplier["g12_recovery"]:
            framework['onFramework'] = True

    if "currently_applying_to" in session:
        del session["currently_applying_to"]

    g12_recovery = None
    if supplier['g12_recovery']:
        g12_recovery = {'time_remaining': g12_recovery_time_remaining()}

    return render_template(
        "suppliers/dashboard.html",
        supplier=supplier,
        frameworks={
            'coming': get_frameworks_by_status(all_frameworks, 'coming'),
            'open': get_frameworks_by_status(all_frameworks, 'open'),
            'pending': get_frameworks_by_status(all_frameworks, 'pending'),
            'standstill': get_frameworks_by_status(all_frameworks, 'standstill', 'made_application'),
            'live': get_frameworks_by_status(all_frameworks, 'live', 'onFramework'),
            'last_dos': get_most_recent_expired_dos_framework(all_frameworks),
        },
        g12_recovery=g12_recovery,
    ), 200