本文整理汇总了Python中temba.contacts.models.ContactGroup.create_static方法的典型用法代码示例。如果您正苦于以下问题:Python ContactGroup.create_static方法的具体用法?Python ContactGroup.create_static怎么用?Python ContactGroup.create_static使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类temba.contacts.models.ContactGroup
的用法示例。
在下文中一共展示了ContactGroup.create_static方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [as 别名]
def clean(self, value):
if value.startswith("[_NEW_]"):
value = value[7:]
# we must get groups for this org only
group = ContactGroup.get_user_group(self.user.get_org(), value)
if not group:
group = ContactGroup.create_static(self.user.get_org(), self.user, name=value)
return group
return super(RegisterTriggerForm.AddNewGroupChoiceField, self).clean(value)
示例2: clean
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [as 别名]
def clean(self, value):
if value.startswith("[_NEW_]"): # pragma: needs cover
value = value[7:]
# we must get groups for this org only
group = ContactGroup.get_user_group(self.user.get_org(), value)
if not group:
group = ContactGroup.create_static(self.user.get_org(), self.user, name=value)
return group
return super().clean(value)
示例3: create_group
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [as 别名]
def create_group(self, name, contacts=(), query=None):
if contacts and query:
raise ValueError("Can't provide contact list for a dynamic group")
if query:
return ContactGroup.create_dynamic(self.org, self.user, name, query=query)
else:
group = ContactGroup.create_static(self.org, self.user, name)
if contacts:
group.contacts.add(*contacts)
return group
示例4: _create_groups
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [as 别名]
def _create_groups(self, count, base_names, contacts):
"""
Creates the given number of groups and fills them with contacts
"""
groups = []
num_bases = len(base_names)
for g in range(0, count):
name = '%s %d' % (base_names[g % num_bases], g + 1)
group = ContactGroup.create_static(self.org, self.user, name)
group.contacts.add(*contacts[(g % num_bases)::num_bases])
groups.append(ContactGroup.user_groups.get(pk=group.pk))
return groups
示例5: create_groups
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [as 别名]
def create_groups(self, orgs):
"""
Creates the contact groups for each org
"""
self._log("Creating %d groups... " % (len(orgs) * len(GROUPS)))
for org in orgs:
user = org.cache["users"][0]
for g in GROUPS:
if g["query"]:
group = ContactGroup.create_dynamic(org, user, g["name"], g["query"], evaluate=False)
else:
group = ContactGroup.create_static(org, user, g["name"])
group.member = g["member"]
group.count = 0
org.cache["groups"].append(group)
self._log(self.style.SUCCESS("OK") + "\n")
示例6: import_campaigns
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [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"],
#.........这里部分代码省略.........
示例7: import_triggers
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [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 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 same_site:
group = ContactGroup.user_groups.filter(org=org, pk=group_spec['id']).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:
group.is_active = True
group.save()
groups.append(group)
flow = Flow.objects.get(org=org, pk=trigger_spec['flow']['id'], 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(pk=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)
示例8: import_campaigns
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [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 exported_json.get('version', 0) < EARLIEST_IMPORT_VERSION:
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:
group.name = campaign_spec['group']['name']
group.save()
campaign = Campaign.objects.filter(org=org, uuid=campaign_spec['uuid']).first()
if campaign:
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()
# we want to nuke old single message flows
for event in campaign.events.all():
if event.flow.flow_type == Flow.MESSAGE:
event.flow.release()
# and all of the events, we'll recreate these
campaign.events.all().delete()
# fill our campaign with events
for event_spec in campaign_spec['events']:
relative_to = ContactField.get_or_create(org, user,
key=event_spec['relative_to']['key'],
label=event_spec['relative_to']['label'])
# create our message flow for message events
if event_spec['event_type'] == CampaignEvent.TYPE_MESSAGE:
event = CampaignEvent.create_message_event(org, user, campaign, relative_to,
event_spec['offset'],
event_spec['unit'],
event_spec['message'],
event_spec['delivery_hour'])
event.update_flow_name()
else:
flow = Flow.objects.filter(org=org, is_active=True, uuid=event_spec['flow']['uuid']).first()
if flow:
CampaignEvent.create_flow_event(org, user, campaign, relative_to,
event_spec['offset'],
event_spec['unit'],
flow,
event_spec['delivery_hour'])
# update our scheduled events for this campaign
EventFire.update_campaign_events(campaign)
示例9: import_triggers
# 需要导入模块: from temba.contacts.models import ContactGroup [as 别名]
# 或者: from temba.contacts.models.ContactGroup import create_static [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)