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.forms.front.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('beacon_admin.edit', opportunity_id=opportunity.id)) form.display_cleanup() return render_template('beacon/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.forms.front.OpportunityForm` and redirect to the edit view of the created opportunity ''' form = OpportunityForm() if form.validate_on_submit(): opportunity_data = form.data_cleanup() _cls = Opportunity.get_opp_class(form.type.data) opportunity = _cls.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('beacon_admin.edit', opportunity_id=opportunity.id)) form.display_cleanup() return render_template( 'beacon/admin/opportunity.html', form=form, opportunity=None, subcategories=form.get_subcategories(), categories=form.get_categories(), help_blocks=Opportunity.get_help_blocks() )
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.forms.front.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('beacon_admin.edit', opportunity_id=opportunity.id)) form.display_cleanup(opportunity) return render_template('beacon/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('front.detail', opportunity_id=opportunity_id)) abort(404)
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.forms.front.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' ) opportunity.save() # expunge all to clear reference to the opportunity # and then re-query it db.session.expunge_all() opportunity = Opportunity.query.get(opportunity_id) opportunity.send_publish_email() opportunity.save() flash('Opportunity successfully updated!', 'alert-success') return redirect(url_for('beacon_admin.edit', opportunity_id=opportunity.id)) form.display_cleanup(opportunity) return render_template( 'beacon/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('front.detail', opportunity_id=opportunity_id)) abort(404)