def edit_company(contract_id):
    '''Update information about companies

    :param contract_id: Primary key ID for a
        :py:class:`~purchasing.data.contracts.ContractBase`

    .. seealso::
        :py:func:`~purchasing.conductor.util.parse_companies` for information
        on how the companies are cleaned and normalized, and
        :py:class:`~purchasing.conductor.forms.CompanyListForm` for
        more on the form used in this view

    :status 200: Render the company/controller number view
    :status 302: Redirect to the company contact view if the
        company form is submitted correctly, and the edit
        contract view if that form hasn't been completed
        yet
    :status 404: Contract not found
    '''
    contract = ContractBase.query.get(contract_id)

    if contract and session.get('contract-{}'.format(contract_id)) is not None:
        form = CompanyListForm()
        if form.validate_on_submit():
            cleaned = parse_companies(form.data)
            session['companies-{}'.format(contract_id)] = json.dumps(cleaned, default=json_serial)
            current_app.logger.info('CONDUCTOR CONTRACT COMPLETE - awarded companies for contract "{}" assigned'.format(
                contract.description
            ))
            return redirect(url_for('conductor.edit_company_contacts', contract_id=contract.id))
        return render_template('conductor/edit/edit_company.html', form=form, contract=contract)
    elif session.get('contract-{}'.format(contract_id)) is None:
        return redirect(url_for('conductor.edit', contract_id=contract_id))
    abort(404)
def edit_company(contract_id):
    contract = ContractBase.query.get(contract_id)

    if contract and session.get('contract') is not None:
        form = CompanyListForm()
        if form.validate_on_submit():
            cleaned = parse_companies(form.data)
            session['companies'] = json.dumps(cleaned, default=json_serial)
            current_app.logger.info('CONDUCTOR CONTRACT COMPLETE - awarded companies for contract "{}" assigned'.format(
                contract.description
            ))
            return redirect(url_for('conductor.edit_company_contacts', contract_id=contract.id))
        return render_template('conductor/edit/edit_company.html', form=form, contract=contract)
    elif session.get('contract') is None:
        return redirect(url_for('conductor.edit', contract_id=contract_id))
    abort(404)
def edit_company(contract_id):
    '''Update information about companies

    :param contract_id: Primary key ID for a
        :py:class:`~purchasing.data.contracts.ContractBase`

    .. seealso::
        :py:func:`~purchasing.conductor.util.parse_companies` for information
        on how the companies are cleaned and normalized, and
        :py:class:`~purchasing.conductor.forms.CompanyListForm` for
        more on the form used in this view

    :status 200: Render the company/controller number view
    :status 302: Redirect to the company contact view if the
        company form is submitted correctly, and the edit
        contract view if that form hasn't been completed
        yet
    :status 404: Contract not found
    '''
    contract = ContractBase.query.get(contract_id)

    if contract and session.get('contract-{}'.format(contract_id)) is not None:
        form = CompanyListForm()
        if form.validate_on_submit():
            cleaned = parse_companies(form.data)
            session['companies-{}'.format(contract_id)] = json.dumps(
                cleaned, default=json_serial)
            current_app.logger.info(
                'CONDUCTOR CONTRACT COMPLETE - awarded companies for contract "{}" assigned'
                .format(contract.description))
            return redirect(
                url_for('conductor.edit_company_contacts',
                        contract_id=contract.id))
        return render_template('conductor/edit/edit_company.html',
                               form=form,
                               contract=contract)
    elif session.get('contract-{}'.format(contract_id)) is None:
        return redirect(url_for('conductor.edit', contract_id=contract_id))
    abort(404)