Exemplo n.º 1
0
def make_user_as_a_datasender(manager,
                              organization,
                              current_user_name,
                              mobile_number,
                              email=None):
    total_entity = get_entity_count_for_type(manager, [REPORTER])
    reporter_id = None
    offset = 1
    location = [organization.country_name()]
    while not reporter_id:
        reporter_short_code = 'rep' + str(total_entity + offset)
        try:
            entity = create_contact(dbm=manager,
                                    short_code=reporter_short_code,
                                    location=location)
            reporter_id = entity.short_code
        except DataObjectAlreadyExists:
            offset += 1

    data = _create_entity_data(current_user_name, email, location,
                               mobile_number, reporter_id)
    entity.add_data(data=data, submission={"form_code": "reg"})
    entity.save()

    if organization.in_trial_mode:
        data_sender = DataSenderOnTrialAccount.objects.model(
            mobile_number=mobile_number, organization=organization)
        data_sender.save(force_insert=True)
    return entity.short_code
Exemplo n.º 2
0
 def create_or_update_entity(self, manager, entity_type, location, aggregation_paths, short_code, geometry=None):
     try:
         entity = get_by_short_code(manager, short_code, entity_type)
         entity.delete()
     except DataObjectNotFound:
         pass
     if entity_type == [REPORTER]:
         return create_contact(manager, short_code, location, aggregation_paths, geometry)
     return create_entity(manager, entity_type, short_code, location, aggregation_paths, geometry)
Exemplo n.º 3
0
 def create_entity(self, dbm):
     location_hierarchy, processed_geometry = Location(self.location_tree, self.form_model).process_entity_creation(
         self.cleaned_data)
     is_datasender = self._cleaned_data.pop('is_data_sender', True)
     return entity.create_contact(dbm=dbm,
                                  location=location_hierarchy,
                                  short_code=self.short_code,
                                  geometry=processed_geometry,
                                  is_datasender=is_datasender)
Exemplo n.º 4
0
def create_default_reporter(manager):
    try:
        entity = get_by_short_code_include_voided(manager, REPORTER_SHORT_CODE,
                                                  REPORTER_ENTITY_TYPE)
        entity.delete()
    except DataObjectNotFound:
        pass
    entity = create_contact(dbm=manager,
                            short_code=REPORTER_SHORT_CODE,
                            location=DEFAULT_LOCATION)

    data = [(MOBILE_NUMBER_FIELD, TEST_REPORTER_MOBILE_NUMBER),
            (NAME_FIELD, 'TEST')]
    entity.add_data(data=data)
Exemplo n.º 5
0
 def test_should_return_error_if_mobile_number_has_hyphens_from_excel_file(
         self):
     reporter1 = create_contact(self.manager, ut_reporter_id())
     reporter1.add_data(data=[("mobile_number", "266123321435")],
                        event_time=datetime.datetime(2010,
                                                     02,
                                                     01,
                                                     tzinfo=UTC),
                        submission=dict(submission_id='1', form_code='reg'))
     values = dict(t='reporter',
                   m='266-123321435',
                   s='rep_test2',
                   l='test_location',
                   g='1 1',
                   n='Test Reporter')
     cleaned_data, errors = self.reg_form.validate_submission(values)
     self.assertTrue('m' in errors)
Exemplo n.º 6
0
 def test_should_not_return_error_dict_if_reporter_with_mobile_number_deleted(
         self):
     values = dict(t='reporter',
                   m='99991',
                   s='rep_test2',
                   l='test_location',
                   g='1 1',
                   n='Test Reporter')
     id = ut_reporter_id()
     reporter1 = create_contact(self.manager, id)
     reporter1.add_data(data=[("mobile_number", "99991"),
                              ("name", "aname")],
                        event_time=datetime.datetime(2010,
                                                     02,
                                                     01,
                                                     tzinfo=UTC),
                        submission=dict(submission_id='1', form_code='reg'))
     void_entity(self.manager, [REPORTER], id)
     cleaned_data, errors = self.reg_form.validate_submission(values)
     self.assertNotIn('m', errors)
Exemplo n.º 7
0
    def test_should_allow_the_same_mobile_number_while_editing_a_reporter_details(
            self):
        reporter_id = ut_reporter_id()
        mobile_number = "99992"
        safe_delete_reporter_by_phone(self.manager, mobile_number)
        reporter1 = create_contact(self.manager, reporter_id)

        reporter1.add_data(data=[("mobile_number", ("%s" % mobile_number)),
                                 ("name", "aname")],
                           event_time=datetime.datetime(2010,
                                                        02,
                                                        01,
                                                        tzinfo=UTC),
                           submission=dict(submission_id='1', form_code='reg'))
        values = dict(t='reporter',
                      m=('%s' % mobile_number),
                      s=reporter_id,
                      l='test_location',
                      g='1 1')
        cleaned_data, errors = self.reg_form.validate_submission(values)
        self.assertNotIn('m', errors)
Exemplo n.º 8
0
    def setUpClass(cls):
        cls.dbm = create_db(uniq('mangrove-test'))
        initializer.initial_data_setup(cls.dbm)
        cls.entity_type = ["healthfacility", "clinic"]
        safe_define_type(cls.dbm, cls.entity_type)

        cls.entity_short_code = "cli" + str(int(random.random() * 10000))
        cls.entity = create_entity(
            cls.dbm,
            entity_type=cls.entity_type,
            location=["India", "Pune"],
            aggregation_paths=None,
            short_code=cls.entity_short_code,
        )
        cls.entity.save()
        cls.reporter_id = "rep" + str(int(random.random() * 10000))
        cls.reporter = create_contact(cls.dbm,
                                      location=["India", "Pune"],
                                      aggregation_paths=None,
                                      short_code=cls.reporter_id)
        cls.reporter.save()

        cls.phone_number = str(int(random.random() * 10000000))
        cls.reporter.add_data(data=[(MOBILE_NUMBER_FIELD, cls.phone_number),
                                    (NAME_FIELD, "Test_reporter")],
                              submission=dict(submission_id="2"))

        question1 = ShortCodeField(
            name="entity_question",
            code="EID",
            label="What is associated entity",
            constraints=[TextLengthConstraint(min=1, max=20)])
        question2 = TextField(name="Name",
                              code="NAME",
                              label="Clinic Name",
                              defaultValue="some default value",
                              constraints=[TextLengthConstraint(4, 15)],
                              required=False)
        question3 = IntegerField(
            name="Arv stock",
            code="ARV",
            label="ARV Stock",
            constraints=[NumericRangeConstraint(min=15, max=120)],
            required=False)
        question4 = SelectField(name="Color",
                                code="COL",
                                label="Color",
                                options=[("RED", 'a'), ("YELLOW", 'a')],
                                required=False)

        try:
            cls.form_model = get_form_model_by_code(cls.dbm, "clinic")
        except FormModelDoesNotExistsException:
            cls.form_model = EntityFormModel(
                cls.dbm,
                entity_type=cls.entity_type,
                name="aids",
                label="Aids form_model",
                form_code="clinic",
                fields=[question1, question2, question3],
                is_registration_model=True)
            cls.form_model.add_field(question4)
            cls.form_model.save()
        cls.sms_player = SMSPlayer(cls.dbm, LocationTree())
        cls.sms_ordered_message_player = SMSPlayer(cls.dbm, LocationTree())
Exemplo n.º 9
0
 def register(cls, manager, data, location, source, aggregation_paths=None, short_code=None):
     e = create_contact(manager, location=location, aggregation_paths=aggregation_paths,
         short_code=short_code)
     e.add_data(data=data)
     return e