当前位置: 首页>>代码示例>>Python>>正文


Python Flow.is_before_version方法代码示例

本文整理汇总了Python中temba.flows.models.Flow.is_before_version方法的典型用法代码示例。如果您正苦于以下问题:Python Flow.is_before_version方法的具体用法?Python Flow.is_before_version怎么用?Python Flow.is_before_version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在temba.flows.models.Flow的用法示例。


在下文中一共展示了Flow.is_before_version方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_campaigns

# 需要导入模块: from temba.flows.models import Flow [as 别名]
# 或者: from temba.flows.models.Flow import is_before_version [as 别名]
    def import_campaigns(cls, exported_json, org, user, same_site=False):
        """
        Import campaigns from our export file
        """
        from temba.orgs.models import EARLIEST_IMPORT_VERSION

        if Flow.is_before_version(exported_json.get("version", "0"), EARLIEST_IMPORT_VERSION):  # pragma: needs cover
            raise ValueError(_("Unknown version (%s)" % exported_json.get("version", 0)))

        if "campaigns" in exported_json:
            for campaign_spec in exported_json["campaigns"]:
                name = campaign_spec["name"]
                campaign = None
                group = None

                # first check if we have the objects by id
                if same_site:
                    group = ContactGroup.user_groups.filter(uuid=campaign_spec["group"]["uuid"], org=org).first()
                    if group:  # pragma: needs cover
                        group.name = campaign_spec["group"]["name"]
                        group.save()

                    campaign = Campaign.objects.filter(org=org, uuid=campaign_spec["uuid"]).first()
                    if campaign:  # pragma: needs cover
                        campaign.name = Campaign.get_unique_name(org, name, ignore=campaign)
                        campaign.save()

                # fall back to lookups by name
                if not group:
                    group = ContactGroup.get_user_group(org, campaign_spec["group"]["name"])

                if not campaign:
                    campaign = Campaign.objects.filter(org=org, name=name).first()

                # all else fails, create the objects from scratch
                if not group:
                    group = ContactGroup.create_static(org, user, campaign_spec["group"]["name"])

                if not campaign:
                    campaign_name = Campaign.get_unique_name(org, name)
                    campaign = Campaign.create(org, user, campaign_name, group)
                else:
                    campaign.group = group
                    campaign.save()

                # deactivate all of our events, we'll recreate these
                for event in campaign.events.all():
                    event.release()

                # fill our campaign with events
                for event_spec in campaign_spec["events"]:
                    field_key = event_spec["relative_to"]["key"]

                    if field_key == "created_on":
                        relative_to = ContactField.system_fields.filter(org=org, key=field_key).first()
                    else:
                        relative_to = ContactField.get_or_create(
                            org, user, key=field_key, label=event_spec["relative_to"]["label"], value_type="D"
                        )

                    start_mode = event_spec.get("start_mode", CampaignEvent.MODE_INTERRUPT)

                    # create our message flow for message events
                    if event_spec["event_type"] == CampaignEvent.TYPE_MESSAGE:

                        message = event_spec["message"]
                        base_language = event_spec.get("base_language")

                        if not isinstance(message, dict):
                            try:
                                message = json.loads(message)
                            except ValueError:
                                # if it's not a language dict, turn it into one
                                message = dict(base=message)
                                base_language = "base"

                        event = CampaignEvent.create_message_event(
                            org,
                            user,
                            campaign,
                            relative_to,
                            event_spec["offset"],
                            event_spec["unit"],
                            message,
                            event_spec["delivery_hour"],
                            base_language=base_language,
                            start_mode=start_mode,
                        )
                        event.update_flow_name()
                    else:
                        flow = Flow.objects.filter(
                            org=org, is_active=True, is_system=False, uuid=event_spec["flow"]["uuid"]
                        ).first()
                        if flow:
                            CampaignEvent.create_flow_event(
                                org,
                                user,
                                campaign,
                                relative_to,
                                event_spec["offset"],
#.........这里部分代码省略.........
开发者ID:teehamaral,项目名称:rapidpro,代码行数:103,代码来源:models.py

示例2: import_triggers

# 需要导入模块: from temba.flows.models import Flow [as 别名]
# 或者: from temba.flows.models.Flow import is_before_version [as 别名]
    def import_triggers(cls, exported_json, org, user, same_site=False):
        """
        Import triggers from our export file
        """
        from temba.orgs.models import EARLIEST_IMPORT_VERSION

        if Flow.is_before_version(exported_json.get("version", 0), EARLIEST_IMPORT_VERSION):  # pragma: needs cover
            raise ValueError(_("Unknown version (%s)" % exported_json.get("version", 0)))

        # first things first, let's create our groups if necesary and map their ids accordingly
        if "triggers" in exported_json:
            for trigger_spec in exported_json["triggers"]:

                # resolve our groups
                groups = []
                for group_spec in trigger_spec["groups"]:

                    group = None

                    if same_site:  # pragma: needs cover
                        group = ContactGroup.user_groups.filter(org=org, uuid=group_spec["uuid"]).first()

                    if not group:
                        group = ContactGroup.get_user_group(org, group_spec["name"])

                    if not group:
                        group = ContactGroup.create_static(org, user, group_spec["name"])

                    if not group.is_active:  # pragma: needs cover
                        group.is_active = True
                        group.save()

                    groups.append(group)

                flow = Flow.objects.get(org=org, uuid=trigger_spec["flow"]["uuid"], is_active=True)

                # see if that trigger already exists
                trigger = Trigger.objects.filter(org=org, trigger_type=trigger_spec["trigger_type"])

                if trigger_spec["keyword"]:
                    trigger = trigger.filter(keyword__iexact=trigger_spec["keyword"])

                if groups:
                    trigger = trigger.filter(groups__in=groups)

                trigger = trigger.first()
                if trigger:
                    trigger.is_archived = False
                    trigger.flow = flow
                    trigger.save()
                else:

                    # if we have a channel resolve it
                    channel = trigger_spec.get("channel", None)  # older exports won't have a channel
                    if channel:
                        channel = Channel.objects.filter(uuid=channel, org=org).first()

                    trigger = Trigger.objects.create(
                        org=org,
                        trigger_type=trigger_spec["trigger_type"],
                        keyword=trigger_spec["keyword"],
                        flow=flow,
                        created_by=user,
                        modified_by=user,
                        channel=channel,
                    )

                    for group in groups:
                        trigger.groups.add(group)
开发者ID:teehamaral,项目名称:rapidpro,代码行数:71,代码来源:models.py


注:本文中的temba.flows.models.Flow.is_before_version方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。