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


Python ContactGroup.create_group方法代码示例

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


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

示例1: import_triggers

# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_group [as 别名]
    def import_triggers(cls, exported_json, org, user, site=None):
        """
        Import triggers from our export file
        """
        from temba.orgs.models import EARLIEST_IMPORT_VERSION
        if exported_json.get('version', 0) < EARLIEST_IMPORT_VERSION:
            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 site and site == exported_json.get('site', None):
                        group = ContactGroup.objects.filter(org=org, pk=group_spec['id']).first()

                    if not group:
                        group = ContactGroup.objects.filter(org=org, name=group_spec['name']).first()

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

                    if not group.is_active:
                        group.is_active = True
                        group.save()

                    groups.append(group)

                flow = Flow.objects.get(org=org, pk=trigger_spec['flow']['id'])

                # 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()

                channel = trigger_spec.get('channel', None)  # older exports won't have a channel

                if trigger:
                    trigger.is_archived = False
                    trigger.flow = flow
                    trigger.save()
                else:
                    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:TextoCMR,项目名称:TexTo.cm,代码行数:62,代码来源:models.py


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