Esempio n. 1
0
    def create_flow(self,
                    name="Test Flow",
                    *,
                    flow_type=Flow.TYPE_MESSAGE,
                    nodes=None,
                    is_system=False,
                    org=None):
        org = org or self.org
        flow = Flow.create(org,
                           self.admin,
                           name,
                           flow_type=flow_type,
                           is_system=is_system)
        if not nodes:
            nodes = [{
                "uuid":
                "f3d5ccd0-fee0-4955-bcb7-21613f049eae",
                "actions": [{
                    "uuid": "f661e3f0-5148-4397-92ef-925629ad444d",
                    "type": "send_msg",
                    "text": "Hey everybody!"
                }],
                "exits": [{
                    "uuid": "72a3f1da-bde1-4549-a986-d35809807be8"
                }],
            }]
        definition = {
            "uuid": str(uuid4()),
            "name": name,
            "type": Flow.GOFLOW_TYPES[flow_type],
            "revision": 1,
            "spec_version": "13.1.0",
            "expire_after_minutes": Flow.DEFAULT_EXPIRES_AFTER,
            "language": "eng",
            "nodes": nodes,
        }

        flow.version_number = definition["spec_version"]
        flow.save()

        json_flow = Flow.migrate_definition(definition, flow)
        flow.save_revision(self.admin, json_flow)

        return flow
Esempio n. 2
0
    def migrate_flow(self, flow, to_version=None):

        if not to_version:
            to_version = Flow.FINAL_LEGACY_VERSION

        flow_json = flow.get_definition()
        if Version(flow.version_number) < Version("6"):
            revision = flow.revisions.all().order_by("-revision").first()
            flow_json = dict(
                definition=flow_json,
                flow_type=flow.flow_type,
                expires=flow.expires_after_minutes,
                id=flow.pk,
                revision=revision.revision if revision else 1,
            )

        flow_json = Flow.migrate_definition(flow_json, flow, to_version=to_version)
        if "definition" in flow_json:
            flow_json = flow_json["definition"]

        flow.update(flow_json)
        return Flow.objects.get(pk=flow.pk)