本文整理汇总了Python中corehq.apps.sms.models.CommConnectCase.get方法的典型用法代码示例。如果您正苦于以下问题:Python CommConnectCase.get方法的具体用法?Python CommConnectCase.get怎么用?Python CommConnectCase.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.sms.models.CommConnectCase
的用法示例。
在下文中一共展示了CommConnectCase.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recipient
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def recipient(self):
handler = self.handler
if handler.recipient == RECIPIENT_USER:
return self.user
elif handler.recipient == RECIPIENT_CASE:
return CommConnectCase.get(self.case_id)
elif handler.recipient == RECIPIENT_SURVEY_SAMPLE:
return SurveySample.get(self.sample_id)
elif handler.recipient == RECIPIENT_OWNER:
return get_wrapped_owner(get_owner_id(self.case))
elif handler.recipient == RECIPIENT_PARENT_CASE:
indices = self.case.indices
for index in indices:
# TODO: The data model allows for more than one parent.
# For now, send to the first parent, but need to decide how to handle multiple ones.
if index.identifier == "parent":
return CommConnectCase.get(index.referenced_id)
return None
elif handler.recipient == RECIPIENT_SUBCASE:
indices = self.case.reverse_indices
recipients = []
for index in indices:
if index.identifier == "parent":
subcase = CommConnectCase.get(index.referenced_id)
if case_matches_criteria(subcase, handler.recipient_case_match_type, handler.recipient_case_match_property, handler.recipient_case_match_value):
recipients.append(subcase)
return recipients
else:
return None
示例2: get_contact
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def get_contact(contact_id):
from corehq.apps.sms.models import CommConnectCase
contact = CommConnectCase.get(contact_id)
if contact.doc_type != "CommCareCase":
try:
contact = CouchUser.get_by_user_id(contact_id)
except CouchUser.AccountTypeError:
raise Exception("Unkown contact type for contact %s" % contact_id)
return contact
示例3: owner
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def owner(self):
if self.owner_doc_type == "CommCareCase":
# Circular import
from corehq.apps.sms.models import CommConnectCase
return CommConnectCase.get(self.owner_id)
elif self.owner_doc_type == "CommCareUser":
# Circular import
from corehq.apps.users.models import CommCareUser
return CommCareUser.get(self.owner_id)
else:
return None
示例4: fire
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def fire(self, reminder):
"""
Sends the message associated with the given CaseReminder's current event.
reminder The CaseReminder which to fire.
return True on success, False on failure
"""
# Prevent circular import
from .event_handlers import EVENT_HANDLER_MAP
# Retrieve the list of individual recipients
recipient = reminder.recipient
if isinstance(recipient, list) and len(recipient) > 0:
recipients = recipient
elif isinstance(recipient, CouchUser) or isinstance(recipient, CommCareCase):
recipients = [recipient]
elif isinstance(recipient, Group):
recipients = recipient.get_users(is_active=True, only_commcare=False)
elif isinstance(recipient, SurveySample):
recipients = [CommConnectCase.get(case_id) for case_id in recipient.contacts]
else:
return False
# Retrieve the corresponding verified number entries for all individual recipients
verified_numbers = {}
for r in recipients:
try:
contact_verified_numbers = r.get_verified_numbers(False)
if len(contact_verified_numbers) > 0:
verified_number = sorted(contact_verified_numbers.iteritems())[0][1]
else:
verified_number = None
except Exception:
verified_number = None
verified_numbers[r.get_id] = verified_number
# Set the event initiation timestamp if we're not on any timeouts
if reminder.callback_try_count == 0:
reminder.event_initiation_timestamp = self.get_now()
# Call the appropriate event handler
event_handler = EVENT_HANDLER_MAP.get(self.method)
last_fired = self.get_now() # Store the timestamp right before firing to ensure continuity in the callback lookups
result = event_handler(reminder, self, recipients, verified_numbers)
reminder.last_fired = last_fired
return result
示例5: spawn_reminder
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def spawn_reminder(self, case, now, recipient=None):
"""
Creates a CaseReminder.
case The CommCareCase for which to create the CaseReminder.
now The date and time to kick off the CaseReminder. This is the date and time from which all
offsets are calculated.
return The CaseReminder
"""
if recipient is None:
if self.recipient == RECIPIENT_USER:
recipient = CommCareUser.get_by_user_id(case.user_id)
elif self.recipient == RECIPIENT_CASE:
recipient = CommConnectCase.get(case._id)
local_now = CaseReminderHandler.utc_to_local(recipient, now)
case_id = case._id if case is not None else None
user_id = case.user_id if case is not None else None
sample_id = recipient._id if self.recipient == RECIPIENT_SURVEY_SAMPLE else None
reminder = CaseReminder(
domain=self.domain,
case_id=case_id,
handler_id=self._id,
user_id=user_id,
method=self.method,
active=True,
start_date=date(now.year, now.month, now.day) if (now.hour == 0 and now.minute == 0 and now.second == 0 and now.microsecond == 0) else date(local_now.year,local_now.month,local_now.day),
schedule_iteration_num=1,
current_event_sequence_num=0,
callback_try_count=0,
skip_remaining_timeouts=False,
sample_id=sample_id,
xforms_session_ids=[],
)
# Set the first fire time appropriately
if self.event_interpretation == EVENT_AS_OFFSET:
# EVENT_AS_OFFSET
day_offset = self.start_offset + self.events[0].day_num
time_offset = self.events[0].fire_time
reminder.next_fire = now + timedelta(days=day_offset, hours=time_offset.hour, minutes=time_offset.minute, seconds=time_offset.second)
else:
# EVENT_AS_SCHEDULE
reminder.next_fire = self.get_current_reminder_event_timestamp(reminder, recipient, case)
return reminder
示例6: get_contact
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def get_contact(contact_id):
from corehq.apps.sms.models import CommConnectCase
contact = None
try:
contact = CommConnectCase.get(contact_id)
except ResourceNotFound:
pass
if contact and contact.doc_type == 'CommCareCase':
return contact
contact = None
try:
contact = CouchUser.get_by_user_id(contact_id)
except CouchUser.AccountTypeError:
pass
if not contact:
raise ContactNotFoundException("Contact not found")
return contact
示例7: spawn_reminder
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def spawn_reminder(self, case, now):
"""
Creates a CaseReminder.
case The CommCareCase for which to create the CaseReminder.
now The date and time to kick off the CaseReminder. This is the date and time from which all
offsets are calculated.
return The CaseReminder
"""
if self.recipient == RECIPIENT_USER:
recipient = CommCareUser.get_by_user_id(case.user_id)
else:
recipient = CommConnectCase.get(case._id)
local_now = CaseReminderHandler.utc_to_local(recipient, now)
reminder = CaseReminder(
domain=self.domain,
case_id=case._id,
handler_id=self._id,
user_id=case.user_id,
method=self.method,
active=True,
start_date=date(now.year, now.month, now.day) if (now.hour == 0 and now.minute == 0 and now.second == 0 and now.microsecond == 0) else date(local_now.year,local_now.month,local_now.day),
schedule_iteration_num=1,
current_event_sequence_num=0,
callback_try_count=0,
callback_received=False
)
# Set the first fire time appropriately
if self.event_interpretation == EVENT_AS_OFFSET:
# EVENT_AS_OFFSET
day_offset = self.start_offset + self.events[0].day_num
time_offset = self.events[0].fire_time
reminder.next_fire = now + timedelta(days=day_offset, hours=time_offset.hour, minutes=time_offset.minute, seconds=time_offset.second)
else:
# EVENT_AS_SCHEDULE
local_tmsp = datetime.combine(reminder.start_date, self.events[0].fire_time) + timedelta(days = (self.start_offset + self.events[0].day_num))
reminder.next_fire = CaseReminderHandler.timestamp_to_utc(recipient, local_tmsp)
return reminder
示例8: recipient
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def recipient(self):
handler = self.handler
if handler.recipient == RECIPIENT_USER:
return self.user
elif handler.recipient == RECIPIENT_CASE:
return CommConnectCase.get(self.case_id)
elif handler.recipient == RECIPIENT_SURVEY_SAMPLE:
return SurveySample.get(self.sample_id)
elif handler.recipient == RECIPIENT_OWNER:
case = self.case
owner_id = case.owner_id
if owner_id is None:
owner_id = case.user_id
owner_doc = get_db().get(owner_id)
if owner_doc["doc_type"] == "CommCareUser":
return CommCareUser.get_by_user_id(owner_id)
elif owner_doc["doc_type"] == "Group":
return Group.get(owner_id)
else:
return None
else:
return None
示例9: recipient
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import get [as 别名]
def recipient(self):
if self.handler.recipient == RECIPIENT_USER:
return self.user
else:
return CommConnectCase.get(self.case_id)