本文整理汇总了Python中corehq.apps.casegroups.models.CommCareCaseGroup.get方法的典型用法代码示例。如果您正苦于以下问题:Python CommCareCaseGroup.get方法的具体用法?Python CommCareCaseGroup.get怎么用?Python CommCareCaseGroup.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.casegroups.models.CommCareCaseGroup
的用法示例。
在下文中一共展示了CommCareCaseGroup.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_cases_to_case_group
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def add_cases_to_case_group(domain, case_group_id, uploaded_data):
response = {"errors": [], "success": []}
try:
case_group = CommCareCaseGroup.get(case_group_id)
except ResourceNotFound:
response["errors"].append(_("The case group was not found."))
return response
for row in uploaded_data:
identifier = row.get("case_identifier")
case = None
if identifier is not None:
case = get_case_by_identifier(domain, str(identifier))
if not case:
response["errors"].append(_("Could not find case with identifier '%s'." % identifier))
elif case.doc_type != "CommCareCase":
response["errors"].append(_("It looks like the case with identifier '%s' is deleted" % identifier))
elif case._id in case_group.cases:
response["errors"].append(_("A case with identifier %s already exists in this group." % identifier))
else:
case_group.cases.append(case._id)
response["success"].append(_("Case with identifier '%s' has been added to this group." % identifier))
if response["success"]:
case_group.save()
return response
示例2: get_recipient_info
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def get_recipient_info(self, recipient_doc_type, recipient_id, contact_cache):
if recipient_doc_type in ['SQLLocation']:
return self.get_orm_recipient_info(recipient_doc_type, recipient_id, contact_cache)
if recipient_id in contact_cache:
return contact_cache[recipient_id]
doc = None
if recipient_id not in [None, ""]:
try:
if recipient_doc_type.startswith('CommCareCaseGroup'):
doc = CommCareCaseGroup.get(recipient_id)
elif recipient_doc_type.startswith('CommCareCase'):
doc = CommCareCase.get(recipient_id)
elif recipient_doc_type in ('CommCareUser', 'WebUser'):
doc = CouchUser.get_by_user_id(recipient_id)
elif recipient_doc_type.startswith('Group'):
doc = Group.get(recipient_id)
except Exception:
pass
doc_info = None
if doc:
try:
doc_info = get_doc_info(doc.to_json(), self.domain)
except DomainMismatchException:
# This can happen, for example, if a WebUser was sent an SMS
# and then they unsubscribed from the domain. If that's the
# case, we'll just leave doc_info as None and no contact link
# will be displayed.
pass
contact_cache[recipient_id] = doc_info
return doc_info
示例3: get_recipient_info
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def get_recipient_info(self, recipient_doc_type, recipient_id, contact_cache):
if recipient_doc_type in ['SQLLocation']:
return self.get_orm_recipient_info(recipient_doc_type, recipient_id, contact_cache)
if recipient_id in contact_cache:
return contact_cache[recipient_id]
doc = None
if recipient_id not in [None, ""]:
try:
if recipient_doc_type.startswith('CommCareCaseGroup'):
doc = CommCareCaseGroup.get(recipient_id)
elif recipient_doc_type.startswith('CommCareCase'):
doc = CommCareCase.get(recipient_id)
elif recipient_doc_type in ('CommCareUser', 'WebUser'):
doc = CouchUser.get_by_user_id(recipient_id)
elif recipient_doc_type.startswith('Group'):
doc = Group.get(recipient_id)
except Exception:
pass
if doc:
doc_info = get_doc_info(doc.to_json(), self.domain)
else:
doc_info = None
contact_cache[recipient_id] = doc_info
return doc_info
示例4: get_deleted_item_data
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def get_deleted_item_data(self, item_id):
case_group = CommCareCaseGroup.get(item_id)
item_data = self._get_item_data(case_group)
case_group.soft_delete()
return {
'itemData': item_data,
'template': 'deleted-group-template',
}
示例5: clean
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def clean(self):
cleaned_data = super(UpdateCaseGroupForm, self).clean()
try:
self.current_group = CommCareCaseGroup.get(self.cleaned_data.get('item_id'))
except AttributeError:
raise forms.ValidationError("You're not passing in the group's id!")
except ResourceNotFound:
raise forms.ValidationError("This case group was not found in our database!")
return cleaned_data
示例6: clean
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def clean(self):
cleaned_data = super(UpdateCaseGroupForm, self).clean()
try:
self.current_group = CommCareCaseGroup.get(self.cleaned_data.get('item_id'))
except AttributeError:
raise forms.ValidationError(_("Please include the case group ID."))
except ResourceNotFound:
raise forms.ValidationError(_("A case group was not found with that ID."))
return cleaned_data
示例7: recipient
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def recipient(self):
if self.recipient_type == self.RECIPIENT_TYPE_CASE:
try:
case = CaseAccessors(self.domain).get_case(self.recipient_id)
except CaseNotFound:
return None
if case.domain != self.domain:
return None
return case
elif self.recipient_type == self.RECIPIENT_TYPE_MOBILE_WORKER:
user = CouchUser.get_by_user_id(self.recipient_id, domain=self.domain)
if not isinstance(user, CommCareUser):
return None
return user
elif self.recipient_type == self.RECIPIENT_TYPE_WEB_USER:
user = CouchUser.get_by_user_id(self.recipient_id, domain=self.domain)
if not isinstance(user, WebUser):
return None
return user
elif self.recipient_type == self.RECIPIENT_TYPE_CASE_GROUP:
try:
group = CommCareCaseGroup.get(self.recipient_id)
except ResourceNotFound:
return None
if group.domain != self.domain:
return None
return group
elif self.recipient_type == self.RECIPIENT_TYPE_USER_GROUP:
try:
group = Group.get(self.recipient_id)
except ResourceNotFound:
return None
if group.domain != self.domain:
return None
return group
elif self.recipient_type == self.RECIPIENT_TYPE_LOCATION:
location = SQLLocation.by_location_id(self.recipient_id)
if location is None:
return None
if location.domain != self.domain:
return None
return location
else:
raise UnknownRecipientType(self.recipient_type)
示例8: case_groups
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def case_groups(self):
return [CommCareCaseGroup.get(g) for g in self.case_group_ids]
示例9: case_group
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import get [as 别名]
def case_group(self):
try:
return CommCareCaseGroup.get(self.group_id)
except ResourceNotFound:
raise Http404()