本文整理汇总了Python中corehq.apps.sms.models.CommConnectCase.view方法的典型用法代码示例。如果您正苦于以下问题:Python CommConnectCase.view方法的具体用法?Python CommConnectCase.view怎么用?Python CommConnectCase.view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.sms.models.CommConnectCase
的用法示例。
在下文中一共展示了CommConnectCase.view方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: device_data
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import view [as 别名]
def device_data(request):
if "data" not in request.POST:
return HttpResponseBadRequest("Missing 'data' POST parameter.")
data = request.POST.get("data")
data = data.strip()
data_points = data.split(",")
device_id = None
for data_point in data_points:
key_value = data_point.partition("=")
key = key_value[0].strip().upper()
value = key_value[2].strip()
if key == "SN":
device_id = value
break
if device_id is None:
return HttpResponseBadRequest("Missing 'SN' in data string.")
# This view lookup is an implicit assert that either one device exists
# with the given device_id, or no devices exist with this device_id.
case = CommConnectCase.view("wisepill/device", key=[device_id], include_docs=True).one()
event = WisePillDeviceEvent(
domain=case.domain if case is not None else None,
data=data,
received_on=datetime.utcnow(),
case_id=case._id if case is not None else None,
processed=False,
)
event.save()
if case is not None:
survey_keywords = SurveyKeyword.get_all(case.domain)
for survey_keyword in survey_keywords:
if survey_keyword.keyword.upper() == "DEVICE_EVENT":
for survey_keyword_action in survey_keyword.actions:
if survey_keyword_action.action == METHOD_STRUCTURED_SMS:
handle_structured_sms(
survey_keyword,
survey_keyword_action,
case,
None,
"DEVICE_EVENT,%s" % data,
send_response=False,
)
event.processed = True
event.save()
break
return HttpResponse("")