def find_reporter_entity(dbm, from_number): reporter_list = find_reporters_by_from_number(dbm, from_number) if len(reporter_list) > 1: raise MultipleReportersForANumberException(from_number) reporter_entity_id = reporter_list[0].keys()[0] reporter_name = reporter_list[0][reporter_entity_id].get(NAME_FIELD) return Entity.get(dbm, reporter_entity_id),reporter_name
def lookup_entity_by_uid(dbm, uid): try: if uid: entity = Entity.get(dbm, uid) return entity.value('name'), entity.short_code except Exception: pass return UNKNOWN, UNKNOWN
def get_data_sender(manager, submission): if submission.owner_uid: try: data_sender_entity = Entity.get(manager, submission.owner_uid) return data_sender_entity.value("name"), data_sender_entity.short_code, data_sender_entity.id except Exception as e: pass #ignore and sending unknown datasender for backward compatibility. return NOT_AVAILABLE_DS, NOT_AVAILABLE
def _find_reporter_name(dbm, row): try: if row.value["owner_uid"]: data_sender_entity = Entity.get(dbm, row.value["owner_uid"]) name = data_sender_entity.value('name') return name except Exception: pass return ""
def _entity_dict(entity_type, entity_doc, dbm, form_model): entity = Entity.get(dbm, entity_doc.id) fields, labels, codes = get_entity_type_fields(dbm, form_model.form_code) data = tabulate_data(entity, form_model, codes) dictionary = OrderedDict() for index in range(0, len(fields)): dictionary.update({fields[index]: data['cols'][index]}) dictionary.update({"entity_type": entity_type}) dictionary.update({"void": entity.is_void()}) return dictionary
def subject_dict(entity_type, entity_doc, dbm, form_model): entity = Entity.get(dbm, entity_doc.id) source_data = _subject_data(dbm, entity, form_model) source_data.update({"entity_type": entity_type}) source_data.update({"void": entity.is_void()}) return source_data