def edit(contract_id):
    '''Update information about a contract
    '''
    contract = ContractBase.query.get(contract_id)

    if contract:
        spec_number = contract.get_spec_number()
        form = EditContractForm(obj=contract)
        form.spec_number.data = spec_number.value

        if form.validate_on_submit():
            data = form.data
            new_spec = data.pop('spec_number', None)

            if new_spec:
                spec_number.value = new_spec

            contract.update(**data)
            flash('Contract Successfully Updated!', 'alert-success')
            new_contract_autoupdate(contract, current_user.email)

            return redirect(url_for('conductor.edit', contract_id=contract.id))

        return render_template('conductor/edit.html', form=form, contract=contract)
    abort(404)
def edit(contract_id):
    '''Update information about a contract
    '''
    contract = ContractBase.query.get(contract_id)
    completed_last_stage = contract.completed_last_stage()

    # clear the contract/companies from our session
    session.pop('contract', None)
    session.pop('companies', None)

    extend = session.get('extend', None)

    if contract and completed_last_stage or extend:
        form = EditContractForm(obj=contract)
        if form.validate_on_submit():
            if not extend:
                session['contract'] = json.dumps(form.data, default=json_serial)
                return redirect(url_for('conductor.edit_company', contract_id=contract.id))
            else:
                # if there is no flow, that means that it is an extended contract
                # so we will save it and return back to the conductor home page
                contract.update_with_spec_number(form.data)
                current_app.logger.info('CONDUCTOR CONTRACT COMPLETE - contract metadata for "{}" updated'.format(
                    contract.description
                ))
                session.pop('extend')
                return redirect(url_for('conductor.index'))
        form.spec_number.data = contract.get_spec_number().value
        return render_template('conductor/edit/edit.html', form=form, contract=contract)
    elif not completed_last_stage:
        return redirect(url_for('conductor.detail', contract_id=contract.id))
    abort(404)
def edit(contract_id):
    '''Update information about a contract

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

    .. seealso::
        :py:class:`~purchasing.conductor.forms.EditContractForm`
        for the form to edit the contract information, and
        :py:meth:`~purchasing.data.contracts.ContractBase.update_with_spec_number`
        for information on how the contract is updated.

    :status 200: Render the edit contract form
    :status 302: Redirect to the conductor detail page if the contract was
        not completed, the edit company page if the edit form was filled
        and the contract isn't being extended, and back to the conductor
        detial view if the contract isn't finished yet
    :status 404: Could not find the contract
    '''
    contract = ContractBase.query.get(contract_id)
    completed_last_stage = contract.completed_last_stage()

    # clear the contract/companies from our session
    session.pop('contract-{}'.format(contract_id), None)
    session.pop('companies-{}'.format(contract_id), None)

    extend = session.get('extend-{}'.format(contract_id), None)

    if contract and completed_last_stage or extend:
        form = EditContractForm(obj=contract)
        if form.validate_on_submit():
            if not extend:
                session['contract-{}'.format(contract_id)] = json.dumps(
                    form.data, default=json_serial)
                return redirect(
                    url_for('conductor.edit_company', contract_id=contract.id))
            else:
                # if there is no flow, that means that it is an extended contract
                # so we will save it and return back to the conductor home page
                contract.update_with_spec_number(form.data)
                current_app.logger.info(
                    'CONDUCTOR CONTRACT COMPLETE - contract metadata for "{}" updated'
                    .format(contract.description))
                session.pop('extend-{}'.format(contract_id))
                return redirect(url_for('conductor.index'))
        form.spec_number.data = contract.get_spec_number().value
        return render_template('conductor/edit/edit.html',
                               form=form,
                               contract=contract)
    elif not completed_last_stage:
        return redirect(url_for('conductor.detail', contract_id=contract.id))
    abort(404)
def edit(contract_id):
    '''Update information about a contract

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

    .. seealso::
        :py:class:`~purchasing.conductor.forms.EditContractForm`
        for the form to edit the contract information, and
        :py:meth:`~purchasing.data.contracts.ContractBase.update_with_spec_number`
        for information on how the contract is updated.

    :status 200: Render the edit contract form
    :status 302: Redirect to the conductor detail page if the contract was
        not completed, the edit company page if the edit form was filled
        and the contract isn't being extended, and back to the conductor
        detial view if the contract isn't finished yet
    :status 404: Could not find the contract
    '''
    contract = ContractBase.query.get(contract_id)
    completed_last_stage = contract.completed_last_stage()

    # clear the contract/companies from our session
    session.pop('contract-{}'.format(contract_id), None)
    session.pop('companies-{}'.format(contract_id), None)

    extend = session.get('extend-{}'.format(contract_id), None)

    if contract and completed_last_stage or extend:
        form = EditContractForm(obj=contract)
        if form.validate_on_submit():
            if not extend:
                session['contract-{}'.format(contract_id)] = json.dumps(form.data, default=json_serial)
                return redirect(url_for('conductor.edit_company', contract_id=contract.id))
            else:
                # if there is no flow, that means that it is an extended contract
                # so we will save it and return back to the conductor home page
                contract.update_with_spec_number(form.data)
                current_app.logger.info('CONDUCTOR CONTRACT COMPLETE - contract metadata for "{}" updated'.format(
                    contract.description
                ))
                session.pop('extend-{}'.format(contract_id))
                return redirect(url_for('conductor.index'))
        form.spec_number.data = contract.get_spec_number().value
        return render_template('conductor/edit/edit.html', form=form, contract=contract)
    elif not completed_last_stage:
        return redirect(url_for('conductor.detail', contract_id=contract.id))
    abort(404)