本文整理汇总了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)