def get_data_sender(manager, submission):
    if submission.owner_uid:
        try:
            data_sender_entity = Contact.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
Exemple #2
0
    def test_get_associated_data_senders(self):
        contact = Contact(self.manager,
                          entity_type=["reporter"],
                          short_code="rep1")
        entity_id = contact.save()
        project = Project(dbm=self.manager,
                          name="TestDS",
                          goals="Testing",
                          devices=['web'],
                          form_code="ds_form",
                          fields=[])
        project.data_senders = ["rep1"]
        project.save()
        result = project.get_associated_datasenders(self.manager)

        self.assertEquals(result[0].short_code, contact.short_code)
        self.assertEquals(result[0].id, entity_id)
Exemple #3
0
def _find_reporter_name(dbm, row):
    try:
        if row.value["owner_uid"]:
            data_sender_entity = Contact.get(dbm, row.value["owner_uid"])
            name = data_sender_entity.value('name')
            return name
    except Exception:
        pass
    return ""
Exemple #4
0
 def get_associated_datasenders(self, dbm):
     keys = [([REPORTER], short_code) for short_code in self.data_senders]
     rows = dbm.view.by_short_codes(reduce=False,
                                    include_docs=True,
                                    keys=keys)
     return [
         Contact.new_from_doc(
             dbm, Contact.__document_class__.wrap(row.get('doc')))
         for row in rows
     ]
Exemple #5
0
def _lookup_contact_by_uid(dbm, uid):
    try:
        if uid:
            entity = Contact.get(dbm, uid)
            if entity.value('name'):
                return entity.value('name'), entity.short_code
            return entity.value('mobile_number'), entity.short_code
    except Exception:
        pass
    return UNKNOWN, UNKNOWN
Exemple #6
0
def _contact_dict(entity_doc, dbm, form_model):
    contact = Contact.get(dbm, entity_doc.id)
    fields, labels, codes = get_entity_type_fields(dbm, form_model.form_code)
    data = tabulate_data(contact, form_model, codes)
    dictionary = OrderedDict()
    for index in range(0, len(fields)):
        dictionary.update({fields[index]: data['cols'][index]})
    dictionary.update({"entity_type": REPORTER_ENTITY_TYPE})
    dictionary.update({"void": contact.is_void()})

    return dictionary
Exemple #7
0
def find_reporters_by_from_number(dbm, from_number):
    rows = dbm.view.datasender_by_mobile(start_key=[from_number],
                                         end_key=[from_number, {}],
                                         include_docs=True)
    if len(rows) == 0:
        raise NumberNotRegisteredException(from_number)
    return [
        Contact.new_from_doc(dbm=dbm,
                             doc=Contact.__document_class__.wrap(
                                 row.get('doc'))) for row in rows
    ]
 def _data_sender(self):
     try:
         data_sender = Contact.get(self.dbm, self.survey_response.owner_uid)
         #todo Do we need to store datasender question code information in enriched survey response?
         return self._get_data_sender_info_dict(data_sender, '')
     except:
         return {
             'id': self.ds_mobile_number,
             'last_name': None,
             'mobile_number': self.ds_mobile_number,
             'question_code': None,
             'deleted': None
         }
Exemple #9
0
def _lookup_contact_by_uid(dbm, uid):
    ds_dict = {}
    try:
        if uid:
            contact = Contact.get(dbm, uid)
            mobile_number = contact.value('mobile_number')
            name = contact.value('name')
            ds_dict['mobile_number'] = mobile_number
            ds_dict['name'] = name if name else mobile_number
            ds_dict['email'] = contact.value('email') if contact.value(
                'email') else UNKNOWN
            ds_dict['location'] = contact.value('location') if contact.value(
                'location') else []
            ds_dict['geo_code'] = contact.geometry.get(
                'coordinates') if contact.geometry.get('coordinates') else []
            ds_dict['id'] = contact.short_code
    except Exception:
        pass
    return ds_dict
Exemple #10
0
def _get_contact_from_json(dbm, doc):
    return Contact.new_from_doc(dbm, Contact.__document_class__.wrap(doc))