def update_domain_mapping(sender, instance, *args, **kwargs): case_id = unicode(instance.case_id) if not DocDomainMapping.objects.filter(doc_id=case_id).exists(): mapping = DocDomainMapping( doc_id=case_id, doc_type='CommCareCase', domain_name=CommCareCase.get(case_id).domain ) mapping.save()
def update_domain_mapping(sender, instance, *args, **kwargs): case_id = unicode(instance.case_id) try: domain_name = instance.domain if not domain_name: raise ValueError() except (AttributeError, ValueError): domain_name = CommCareCase.get(case_id).domain if not DocDomainMapping.objects.filter(doc_id=case_id).exists(): mapping = DocDomainMapping(doc_id=case_id, doc_type="CommCareCase", domain_name=domain_name) mapping.save()
def update_domain_mapping(sender, instance, *args, **kwargs): case_id = six.text_type(instance.case_id) try: domain_name = instance.__domain if not domain_name: raise ValueError() except (AttributeError, ValueError): domain_name = CommCareCase.get(case_id).domain if not DocDomainMapping.objects.filter(doc_id=case_id).exists(): mapping = DocDomainMapping( doc_id=case_id, doc_type='CommCareCase', domain_name=domain_name, ) mapping.save()