(self, domain, recipient_doc_type, recipient_id, contact_cache)
return doc_info
We need to accept domain as an arg here for admin reports that extend this base.
We need to accept domain as an arg here for admin reports that extend this base.
We need to accept domain as an arg here for admin reports that extend this base .
def get_recipient_info(self, domain, recipient_doc_type, recipient_id, contact_cache):
        """
        We need to accept domain as an arg here for admin reports that extend this base.
        """

        if recipient_id in contact_cache:
            return contact_cache[recipient_id]

        couch_object = None
        sql_object = None

        if recipient_id and recipient_doc_type:
            try:
                if recipient_doc_type.startswith('CommCareCaseGroup'):
                    couch_object = CommCareCaseGroup.get(recipient_id)
                elif recipient_doc_type.startswith('CommCareCase'):
                    obj = CaseAccessors(domain).get_case(recipient_id)
                    if isinstance(obj, CommCareCase):
                        couch_object = obj
                    elif isinstance(obj, CommCareCaseSQL):
                        sql_object = obj
                elif recipient_doc_type in ('CommCareUser', 'WebUser'):
                    couch_object = CouchUser.get_by_user_id(recipient_id)
                elif recipient_doc_type.startswith('Group'):
                    couch_object = Group.get(recipient_id)
                elif recipient_doc_type == 'SQLLocation':
                    sql_object = SQLLocation.objects.get(location_id=recipient_id)
            except (ResourceNotFound, CaseNotFound, ObjectDoesNotExist):
                pass

        doc, doc_info = None, None
        if couch_object:
            doc = couch_object.to_json()
        elif sql_object:
            doc = sql_object

        if doc:
            try:
                doc_info = get_doc_info(doc, 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
def get_recipient_info ( self , domain , recipient_doc_type , recipient_id , contact_cache ) : if recipient_id in contact_cache : return contact_cache [ recipient_id ] couch_object = None sql_object = None if recipient_id and recipient_doc_type : try : if recipient_doc_type . startswith ( 'CommCareCaseGroup' ) : couch_object = CommCareCaseGroup . get ( recipient_id ) elif recipient_doc_type . startswith ( 'CommCareCase' ) : obj = CaseAccessors ( domain ) . get_case ( recipient_id ) if isinstance ( obj , CommCareCase ) : couch_object = obj elif isinstance ( obj , CommCareCaseSQL ) : sql_object = obj elif recipient_doc_type in ( 'CommCareUser' , 'WebUser' ) : couch_object = CouchUser . get_by_user_id ( recipient_id ) elif recipient_doc_type . startswith ( 'Group' ) : couch_object = Group . get ( recipient_id ) elif recipient_doc_type == 'SQLLocation' : sql_object = SQLLocation . objects . get ( location_id = recipient_id ) except ( ResourceNotFound , CaseNotFound , ObjectDoesNotExist ) : pass doc , doc_info = None , None if couch_object : doc = couch_object . to_json ( ) elif sql_object : doc = sql_object if doc : try : doc_info = get_doc_info ( doc , 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