Beispiel #1
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.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()
    )
Beispiel #2
0
 def validate(self):
     '''Validate the submission_data
     '''
     initial_validate = super(OpportunityForm, self).validate()
     if initial_validate is False:
         return False
     self._cls = Opportunity.get_opp_class(self.type.data)
     return self._cls.validate(self)