2

I'm using ViewFlow/Django and I've defined Flow which includes 10 steps.

Suppose I have all the relevant data for the first 5 steps.

How can I programatically start my flow, save the data for these steps and jump directly to step 6?

The problem is that I have the flow working with the frontend but now I want to do the first 5 steps from the API. I added this to my flow:

class MyFlow(Flow):

@method_decorator(flow_start_func)
def create_request(self, activation, **kwargs):
    activation.prepare()
    activation.done()
    return activation

start_from_code = StartFunction(this.create_request). \
    Next(this.my_first_step_in_a_flow)

but I'm doing something wrong, since when I try to run with:

MainOnBoardingFlow.start_from_code.run()

i get NotImplementedError

alexarsh
  • 5,123
  • 12
  • 42
  • 51
  • See [the bit about processing task state](https://stackoverflow.com/a/28736975/9043116), but watch out for [exception handling issues](https://stackoverflow.com/questions/50243607/configure-viewflow-io-error-handling-model). – Shaheed Haque May 14 '18 at 17:15

2 Answers2

0

You don't need to skip. Just add second start node connected to the middle of yours flow. It could be StartFunction where you would pass prepared data

enter image description here

kmmbvnr
  • 5,863
  • 4
  • 35
  • 44
  • Thanks. And if I want to move on my flow step by step programatically, with giving the relevant data each time, how can I do that? – alexarsh May 09 '18 at 04:57
0

The question, as phrased, can be interpreted in two ways:

  1. When the idea is to start a brand new Viewflow process. This is the interpretation answered by @kmmbvnr using the StartFunction node. A fuller answer is at How to create a django ViewFlow process programmatically.
  2. When the idea is to continue an existing Viewflow process at a given Task (presumably at a View node Task). In the latter case, the key is to use the Function node. In my case, I had the following View and the corresponding Function:
class MyFlow(Flow):
    approve_run_as_payroll_approver = flow.View(
        ProcessApproval, form_class=ProcessApproval.Form). \
        Permission(). \
        Assign(). \
        Next(this.check_pay_run_approved)
    approve_run_as_payroll_approver_fn = flow.Function(process_approve). \
        Next(this.check_pay_run_approved)

The process_approve handler is decorated like this:

@flow_func
def process_approve(activation: FuncActivation, *, approved, **kwargs):
   ...

The process is resumed as follows:

   MyFlow.approve_run_as_payroll_approver_fn.run(...)

see the documentation for the arguments.

Shaheed Haque
  • 644
  • 5
  • 14