Ejemplo n.º 1
0
    def __init__(self, is_edit=False, uid=None, survey=None, *args, **kwargs):
        super(HouseholdForm, self).__init__(*args, **kwargs)
        self.is_editing = is_edit

        if not self.is_editing:
            self.fields["uid"].initial = Household.next_uid(survey)
        else:
            self.fields["uid"].initial = self.instance.uid
            self.fields["uid"].widget.attrs["disabled"] = "disabled"
Ejemplo n.º 2
0
    def test_knows_next_uid_for_households_if_survey_is_open_is_survey_dependent(self):
        open_survey = Survey.objects.create(name="open survey", description="open survey", has_sampling=True)
        with patch.object(Survey, "currently_open_survey", return_value=open_survey):
            investigator = Interviewer.objects.create(name="Investigator", mobile_number="987654321",
                                                       backend=Backend.objects.create(name='something1'))
            Household.objects.create(investigator=investigator, survey=open_survey, uid=101)
            Household.objects.create(investigator=investigator, survey=open_survey, uid=102)
            Household.objects.create(investigator=investigator, uid=103)

            self.assertEqual(103, Household.next_uid(open_survey))
Ejemplo n.º 3
0
    def test_knows_next_uid_for_households_if_survey_is_open_is_survey_dependent(self):
        open_survey = Survey.objects.create(name="open survey", description="open survey", has_sampling=True)
        with patch.object(Survey, "currently_open_survey", return_value=open_survey):
            investigator = Investigator.objects.create(name="Investigator", mobile_number="987654321",
                                                       backend=Backend.objects.create(name='something1'))
            Household.objects.create(investigator=investigator, survey=open_survey, uid=101)
            Household.objects.create(investigator=investigator, survey=open_survey, uid=102)
            Household.objects.create(investigator=investigator, uid=103)

            self.assertEqual(103, Household.next_uid(open_survey))
Ejemplo n.º 4
0
    def test_create_households(self):
        country = LocationType.objects.create(name='country', slug='country')
        uganda = Location.objects.create(name="Uganda", type=country)
        burundi = Location.objects.create(name="Burundi", type=country)
        ea = EnumerationArea.objects.create(name="EA2")
        ea.locations.add(uganda)

        investigator = Interviewer.objects.create(name="inv", mobile_number='987654321', ea=ea,
                                                   backend=Backend.objects.create(name='something'))
        form_data = {
            'ea': investigator.ea.id,
            'investigator': investigator.id,
            'surname': 'Rajini',
            'first_name': 'Kant',
            'male': 'False',
            'date_of_birth': date(1980, 9, 01),
            'occupation': 'Student',
            'level_of_education': 'Nursery',
            'resident_since_year': '2013',
            'resident_since_month': '5',
            'time_measure': 'Years',
            'uid': '2',
        }

        household_code = LocationCode.get_household_code(investigator) + str(Household.next_uid())

        hHead = HouseholdHead.objects.filter(surname=form_data['surname'])
        household = Household.objects.filter(uid=form_data['uid'])
        self.failIf(hHead)
        self.failIf(household)
        response = self.client.post('/households/new/', data=form_data)
        self.failUnlessEqual(response.status_code, 302) # ensure redirection to list investigator page

        hHead = HouseholdHead.objects.get(surname=form_data['surname'])
        household = Household.objects.get(uid=form_data['uid'])
        self.failUnless(hHead.id)
        self.failUnless(household.id)
        for key in ['surname', 'first_name', 'date_of_birth', 'occupation',
                    'level_of_education', 'resident_since_year', 'resident_since_month']:
            value = getattr(hHead, key)
            self.assertEqual(str(form_data[key]), str(value))

        self.assertEqual(hHead.male, False)
        self.assertEqual(household.investigator, investigator)
        self.assertEqual(household.location, investigator.location)
        self.assertEqual(household.household_code, household_code)
        self.assertEqual(hHead.household, household)

        investigator.ea = ea
        investigator.save()
        self.assertEqual(household.location, uganda)
Ejemplo n.º 5
0
def create_household(householdform, investigator, valid, uid):
    is_valid_household = householdform['household'].is_valid()

    if investigator and is_valid_household:
        household = householdform['household'].save(commit=False)
        household.investigator = investigator
        household.ea = investigator.ea
        open_survey = Survey.currently_open_survey(investigator.location)
        household.household_code = LocationCode.get_household_code(investigator) + str(Household.next_uid(open_survey))
        if uid:
            household.uid = uid
            household.household_code = LocationCode.get_household_code(investigator) + str(uid)

        household.survey = open_survey
        household.save()
        valid['household'] = True
    return valid
Ejemplo n.º 6
0
            'ea': investigator.ea.id,
            'investigator': investigator.id,
            'surname': 'Rajini',
            'first_name': 'Kant',
            'male': 'False',
            'date_of_birth': date(1980, 9, 01),
            'occupation': 'Student',
            'level_of_education': 'Nursery',
            'resident_since_year': '2013',
            'resident_since_month': '5',
            'time_measure': 'Years',
            'uid': '2',
        }

        household_code = LocationCode.get_household_code(investigator) + str(
            Household.next_uid())

        hHead = HouseholdHead.objects.filter(surname=form_data['surname'])
        household = Household.objects.filter(uid=form_data['uid'])
        self.failIf(hHead)
        self.failIf(household)
        response = self.client.post('/households/new/', data=form_data)
        self.failUnlessEqual(
            response.status_code,
            302)  # ensure redirection to list investigator page

        hHead = HouseholdHead.objects.get(surname=form_data['surname'])
        household = Household.objects.get(uid=form_data['uid'])
        self.failUnless(hHead.id)
        self.failUnless(household.id)
        for key in [
Ejemplo n.º 7
0
 def test_knows_next_uid_for_households(self):
     investigator = Interviewer.objects.create(name="Investigator", mobile_number="987654321",
                                                backend=Backend.objects.create(name='something1'))
     Household.objects.create(investigator=investigator, uid=101)
     self.assertEqual(102, Household.next_uid())
Ejemplo n.º 8
0
 def test_knows_next_uid_for_households(self):
     investigator = Investigator.objects.create(name="Investigator", mobile_number="987654321",
                                                backend=Backend.objects.create(name='something1'))
     Household.objects.create(investigator=investigator, uid=101)
     self.assertEqual(102, Household.next_uid())