<commit_before># coding=utf-8

from itertools import chain

from flask import render_template, request, redirect, url_for, abort, session, Markup
from flask_login import current_user, current_app
import six

from dmapiclient import APIError
from dmapiclient.audit import AuditTypes
from dmutils.email import send_email, generate_token
from dmutils.email.exceptions import EmailError
from dmcontent.content_loader import ContentNotFoundError

from ...main import main, content_loader
from ... import data_api_client
from ..forms.suppliers import (
    EditSupplierForm, EditContactInformationForm, DunsNumberForm, CompaniesHouseNumberForm,
    CompanyContactDetailsForm, CompanyNameForm, EmailAddressForm
)
from ..helpers.frameworks import get_frameworks_by_status
from ..helpers import hash_email, login_required
from .users import get_current_suppliers_users


@main.route('')
@login_required
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'], {})
        )
        dates = {}
        try:
            dates = content_loader.get_message(framework['slug'], 'dates')
        except ContentNotFoundError:
            pass
        framework.update({
            'dates': dates,
            'deadline': Markup("Deadline: {}".format(dates.get('framework_close_date', ''))),
            '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
            )
        })
    return render_template(
        "suppliers/dashboard.html",
        supplier=supplier,
        users=get_current_suppliers_users(),
        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')
        }
    ), 200


@main.route('/details', methods=['GET'])
@login_required
def supplier_details():
    try:
        supplier = data_api_client.get_supplier(
            current_user.supplier_id
        )['suppliers']
    except APIError as e:
        abort(e.status_code)
    supplier['contact'] = supplier['contactInformation'][0]

    return render_template(
        "suppliers/details.html",
        supplier=supplier,
    ), 200


@main.route('/details/edit', methods=['GET'])
@login_required
def edit_supplier(supplier_form=None, contact_form=None, error=None):
    try:
        supplier = data_api_client.get_supplier(
            current_user.supplier_id
        )['suppliers']
    except APIError as e:
        abort(e.status_code)

    if supplier_form is None:
        supplier_form = EditSupplierForm(
            description=supplier.get('description', None),
            clients=supplier.get('clients', None)
        )
        contact_form = EditContactInformationForm(
            prefix='contact_',
            **supplier['contactInformation'][0]
        )

    return render_template(
        "suppliers/edit_supplier.html",
        error=error,
        supplier_form=supplier_form,
        contact_form=contact_form<commit_msg>supplier details editing: redirect old route for this view<commit_after># coding=utf-8

from itertools import chain

from flask import render_template, request, redirect, url_for, abort, session, Markup
from flask_login import current_user, current_app
import six

from dmapiclient import APIError
from dmapiclient.audit import AuditTypes
from dmutils.email import send_email, generate_token
from dmutils.email.exceptions import EmailError
from dmcontent.content_loader import ContentNotFoundError

from ...main import main, content_loader
from ... import data_api_client
from ..forms.suppliers import (
    EditSupplierForm, EditContactInformationForm, DunsNumberForm, CompaniesHouseNumberForm,
    CompanyContactDetailsForm, CompanyNameForm, EmailAddressForm
)
from ..helpers.frameworks import get_frameworks_by_status
from ..helpers import hash_email, login_required
from .users import get_current_suppliers_users


@main.route('')
@login_required
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'], {})
        )
        dates = {}
        try:
            dates = content_loader.get_message(framework['slug'], 'dates')
        except ContentNotFoundError:
            pass
        framework.update({
            'dates': dates,
            'deadline': Markup("Deadline: {}".format(dates.get('framework_close_date', ''))),
            '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
            )
        })
    return render_template(
        "suppliers/dashboard.html",
        supplier=supplier,
        users=get_current_suppliers_users(),
        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')
        }
    ), 200


@main.route('/details', methods=['GET'])
@login_required
def supplier_details():
    try:
        supplier = data_api_client.get_supplier(
            current_user.supplier_id
        )['suppliers']
    except APIError as e:
        abort(e.status_code)
    supplier['contact'] = supplier['contactInformation'][0]

    return render_template(
        "suppliers/details.html",
        supplier=supplier,
    ), 200


@main.route('/edit', methods=['GET'])
@login_required
def edit_supplier_redirect():
    # redirect old route for this view
    return redirect(url_for('.edit_supplier'), 302)


@main.route('/details/edit', methods=['GET'])
@login_required
def edit_supplier(supplier_form=None, contact_form=None, error=None):
    try:
        supplier = data_api_client.get_supplier(
            current_user.supplier_id
        )['suppliers']
    except APIError as e:
        abort(e.status_code)

    if supplier_form is None:
        supplier_form = EditSupplierForm(
            description=supplier.get('description', None),
            clients=supplier.get('clients', None)
        )
        contact_form = EditContactInformationForm(
            prefix='contact_',
            **supplier['contactInformation'][0]
        )

    return render_template(
        "suppliers/edit_supplier.html",
        error=error,
        supplier_form=supplier_form,
        contact_form=contact_form
{'fraction_non_alphanumeric': 0.1030239099859353, 'fraction_numerical': 0.0029301453352086264, 'mean_word_length': 3.2055199605717104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6509946', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2389, 'n_words': 461}