def new_flow(): '''Create a new flow :status 200: Render the new flow template :status 302: Try to create a new flow using the :py:class:`~purchasing.conductor.forms.NewFlowForm`, redirect to the flows list view if successful ''' stages = Stage.choices_factory() form = NewFlowForm(stages=stages) if form.validate_on_submit(): stage_order = [] for entry in form.stage_order.entries: # try to evaluate the return value as an ID try: stage_id = int(entry.data) # otherwise it's a new stage except ValueError: new_stage = Stage.create(name=entry.data) stage_id = new_stage.id stage_order.append(stage_id) Flow.create(flow_name=form.flow_name.data, stage_order=stage_order) flash('Flow created successfully!', 'alert-success') return redirect(url_for('conductor.flows_list')) return render_template('conductor/flows/new.html', stages=stages, form=form)
def new_flow(): """Create a new flow :status 200: Render the new flow template :status 302: Try to create a new flow using the :py:class:`~purchasing.conductor.forms.NewFlowForm`, redirect to the flows list view if successful """ stages = Stage.choices_factory() form = NewFlowForm(stages=stages) if form.validate_on_submit(): stage_order = [] for entry in form.stage_order.entries: # try to evaluate the return value as an ID try: stage_id = int(entry.data) # otherwise it's a new stage except ValueError: new_stage = Stage.create(name=entry.data) stage_id = new_stage.id stage_order.append(stage_id) Flow.create(flow_name=form.flow_name.data, stage_order=stage_order) flash("Flow created successfully!", "alert-success") return redirect(url_for("conductor.flows_list")) return render_template("conductor/flows/new.html", stages=stages, form=form)
def seed_stages_and_flows(): '''Seed one flow with three stages named "one", "two", and "three" ''' stage1 = Stage.create( name='one', post_opportunities=True, default_message='This is a default message for stage one!') stage2 = Stage.create( name='two', post_opportunities=True, ) stage3 = Stage.create(name='three', post_opportunities=True) Flow.create(flow_name='Default Flow', stage_order=[stage1.id, stage2.id, stage3.id]) db.session.commit()
def new_flow(): stages = Stage.choices_factory() form = NewFlowForm(stages=stages) if form.validate_on_submit(): stage_order = [] for entry in form.stage_order.entries: # try to evaluate the return value as an ID try: stage_id = int(entry.data) # otherwise it's a new stage except ValueError: new_stage = Stage.create(name=entry.data) stage_id = new_stage.id stage_order.append(stage_id) Flow.create(flow_name=form.flow_name.data, stage_order=stage_order) flash('Flow created successfully!', 'alert-success') return redirect(url_for('conductor.flows_list')) return render_template('conductor/flows/new.html', stages=stages, form=form)
def seed_stages_and_flows(): '''Seed one flow with three stages named "one", "two", and "three" ''' stage1 = Stage.create( name='one', post_opportunities=True, default_message='This is a default message for stage one!' ) stage2 = Stage.create( name='two', post_opportunities=True, ) stage3 = Stage.create( name='three', post_opportunities=True ) Flow.create( flow_name='Default Flow', stage_order=[stage1.id, stage2.id, stage3.id] ) db.session.commit()