def edit(opportunity_id):
    '''Edit an opportunity
    '''
    opportunity = Opportunity.query.get(opportunity_id)

    if opportunity:

        if opportunity.can_edit(current_user):
            form = OpportunityForm(obj=opportunity)

            if form.validate_on_submit():
                opportunity_data = form.data_cleanup()
                opportunity.update(
                    opportunity_data, current_user,
                    form.documents, request.form.get('save_type') == 'publish'
                )
                db.session.commit()
                opportunity.send_publish_email()
                db.session.commit()
                flash('Opportunity successfully updated!', 'alert-success')

                return redirect(url_for('opportunities_admin.edit', opportunity_id=opportunity.id))

            form.display_cleanup(opportunity)

            return render_template(
                'opportunities/admin/opportunity.html', form=form,
                opportunity=opportunity,
                subcategories=form.get_subcategories(),
                categories=form.get_categories()
            )

        flash('This opportunity has been locked for editing by OMB.', 'alert-warning')
        return redirect(url_for('opportunities.detail', opportunity_id=opportunity_id))
    abort(404)
def new():
    '''Create a new opportunity
    '''
    form = OpportunityForm()

    if form.validate_on_submit():
        opportunity_data = form.data_cleanup()
        opportunity = Opportunity.create(
            opportunity_data, current_user,
            form.documents, request.form.get('save_type') == 'publish'
        )
        db.session.add(opportunity)
        db.session.commit()

        opportunity.send_publish_email()
        db.session.commit()
        flash('Opportunity post submitted to OMB!', 'alert-success')
        return redirect(url_for('opportunities_admin.edit', opportunity_id=opportunity.id))

    form.display_cleanup()

    return render_template(
        'opportunities/admin/opportunity.html', form=form, opportunity=None,
        subcategories=form.get_subcategories(),
        categories=form.get_categories()
    )
def new():
    '''Create a new opportunity

    :status 200: Render the opportunity create/edit template
    :status 302: Post data for a new opportunity via the
        :py:class:`~purchasing.opportunities.forms.OpportunityForm`
        and redirect to the edit view of the created opportunity
    '''
    form = OpportunityForm()

    if form.validate_on_submit():
        opportunity_data = form.data_cleanup()
        opportunity = Opportunity.create(
            opportunity_data, current_user,
            form.documents, request.form.get('save_type') == 'publish'
        )
        db.session.add(opportunity)
        db.session.commit()

        opportunity.send_publish_email()
        db.session.commit()
        flash('Opportunity post submitted to OMB!', 'alert-success')
        return redirect(url_for('opportunities_admin.edit', opportunity_id=opportunity.id))

    form.display_cleanup()

    return render_template(
        'opportunities/admin/opportunity.html', form=form, opportunity=None,
        subcategories=form.get_subcategories(),
        categories=form.get_categories()
    )
Exemplo n.º 4
0
def new():
    '''Create a new opportunity

    :status 200: Render the opportunity create/edit template
    :status 302: Post data for a new opportunity via the
        :py:class:`~purchasing.opportunities.forms.OpportunityForm`
        and redirect to the edit view of the created opportunity
    '''
    form = OpportunityForm()

    if form.validate_on_submit():
        opportunity_data = form.data_cleanup()
        opportunity = Opportunity.create(
            opportunity_data, current_user, form.documents,
            request.form.get('save_type') == 'publish')
        db.session.add(opportunity)
        db.session.commit()

        opportunity.send_publish_email()
        db.session.commit()
        flash('Opportunity post submitted to OMB!', 'alert-success')
        return redirect(
            url_for('opportunities_admin.edit', opportunity_id=opportunity.id))

    form.display_cleanup()

    return render_template('opportunities/admin/opportunity.html',
                           form=form,
                           opportunity=None,
                           subcategories=form.get_subcategories(),
                           categories=form.get_categories())
Exemplo n.º 5
0
def edit(opportunity_id):
    '''Edit an opportunity

    :status 200: Render the opportunity create/edit template
    :status 302: Post data for the relevant opportunity to edit via the
        :py:class:`~purchasing.opportunities.forms.OpportunityForm`
        and redirect to the edit view of the opportunity
    '''
    opportunity = Opportunity.query.get(opportunity_id)

    if opportunity:

        if opportunity.can_edit(current_user):
            form = OpportunityForm(obj=opportunity)

            if form.validate_on_submit():
                opportunity_data = form.data_cleanup()
                opportunity.update(opportunity_data, current_user,
                                   form.documents,
                                   request.form.get('save_type') == 'publish')
                db.session.commit()
                opportunity.send_publish_email()
                db.session.commit()
                flash('Opportunity successfully updated!', 'alert-success')

                return redirect(
                    url_for('opportunities_admin.edit',
                            opportunity_id=opportunity.id))

            form.display_cleanup(opportunity)

            return render_template('opportunities/admin/opportunity.html',
                                   form=form,
                                   opportunity=opportunity,
                                   subcategories=form.get_subcategories(),
                                   categories=form.get_categories())

        flash('This opportunity has been locked for editing by OMB.',
              'alert-warning')
        return redirect(
            url_for('opportunities.detail', opportunity_id=opportunity_id))
    abort(404)