Search code examples
django-viewflow

Django Viewflow - flow.If with custom views doesn't work for me


I have a flow like this:

    review_request = (
        flow.View(
            ReviewRequest,
        ).Permission(
            auto_create=True
        ).Next(this.check_response)
    )


    check_response = flow.If(cond=lambda act: True
        ).Then(
            this.approved_access_request
        ).Else(
            this.refused_access_request
        )


    approved_access_request = flow.View(
        AccessApproved,
    ).Assign(
        this.review_request.owner
    ).Permission(
        auto_create=True
    ).Next(this.end)

    refused_access_request = flow.View(
        AccessRefused,
    ).Assign(
        this.review_request.owner
    ).Permission(
        auto_create=True
    ).Next(this.end)

And a view:

class ReviewRequest(FlowMixin, generic.UpdateView):
    template_name = 'web/review-access-request.html'
    model = AccessRequest

    form_class = ReviewAccessRequestForm

    def get_object(self):
        return self.activation.process

    def request_details(self):
        return self.activation.process.access_request

    def form_valid(self, form):
        form.save()
        self.activation_done()
        next_view_url = self.get_success_url()
        return redirect(next_view_url)

The problem is the pages for AccessApproved and AccessRefused do not show. The assignment part works (shown by the admin material frontend), but the views are not executed. Instead there is a few second pause and the browser is send to the admin Inbox.


Solution

  • View task is not executed automatically but picked by a user. Generally after flow.If the new assigned tasks available the in a user inbox.

    If you press Save and Continue button in default frontend, your ReviewRequest view could decide where to go next, by calling viewflow.flow.utils.get_next_task_url