Exemplo n.º 1
0
class ShippingWorkflow(models.Shipment):
    checkout = tasks.StartView(fields=["shipping_address", "email"])

    ship = tasks.UpdateView(fields=["tracking_code"])

    def has_email(self, task):
        if self.email:
            return [self.send_tracking_code]

    def send_tracking_code(self, task):
        send_mail(
            subject="Your tracking code",
            message=self.tracking_code,
            from_email=None,
            recipient_list=[self.email],
        )

    def end(self, task):
        pass

    edges = [
        (checkout, ship),
        (ship, has_email),
        (has_email, send_tracking_code),
        (has_email, end),
        (send_tracking_code, end),
    ]

    class Meta:
        proxy = True
Exemplo n.º 2
0
class TestWorkflow(models.TestWorkflowState):
    a = tasks.Start()
    b = tasks.UpdateView()
    c = lambda s, t: s

    not_a_node = lambda s, t: s

    edges = [
        (a, b),
        (b, c),
    ]

    class Meta:
        proxy = True
Exemplo n.º 3
0
class SimpleWorkflow(models.SimpleWorkflowState):
    start_view = tasks.StartView(fields="__all__", path="custom/postfix/")
    start_method = tasks.Start()
    save_the_princess = tasks.UpdateView(fields="__all__")

    def end(self):
        pass

    edges = (
        (start_view, save_the_princess),
        (start_method, save_the_princess),
        (save_the_princess, end),
    )

    class Meta:
        proxy = True
Exemplo n.º 4
0
class GatewayWorkflow(models.GatewayWorkflowState):
    start = tasks.StartView(fields="__all__")

    save_the_princess = tasks.UpdateView()

    def is_princess_safe(self):
        return [self.happy_end]

    happy_end = lambda s, task: s.finish()
    bad_end = lambda s, task: s.finish()

    edges = (
        (start, is_princess_safe),
        (is_princess_safe, happy_end),
        (is_princess_safe, bad_end),
    )

    class Meta:
        proxy = True