Пример #1
0
    def test_should_know_how_to_set_household_location_given_a_set_of_households(self):
        district = LocationType.objects.create(name="District", slug=slugify("district"))
        county = LocationType.objects.create(name="County", slug=slugify("county"))
        sub_county = LocationType.objects.create(name="Subcounty", slug=slugify("sub-county"))
        parish = LocationType.objects.create(name="Parish", slug=slugify("parish"))
        village = LocationType.objects.create(name="Village", slug=slugify("village"))

        uganda = Location.objects.create(name="Uganda", type=self.country)
        kampala_district = Location.objects.create(name="Kampala", type=district, tree_parent=uganda)
        bukoto_county = Location.objects.create(name="Bukoto", type=county, tree_parent=kampala_district)
        some_sub_county = Location.objects.create(name="Some sub county", type=sub_county, tree_parent=bukoto_county)
        some_parish = Location.objects.create(name="Some parish", type=parish, tree_parent=some_sub_county)
        some_village = Location.objects.create(name="Some village", type=village, tree_parent=some_parish)
        survey = Survey.objects.create(name="huhu")
        ea = EnumerationArea.objects.create(name="EA2", survey=survey)
        ea.locations.add(some_village)

        investigator1 = Interviewer.objects.create(name="Investigator", mobile_number="987654321",
                                                    ea=ea,
                                                    backend=Backend.objects.create(name='something1'))

        household1 = Household.objects.create(investigator=investigator1, ea=investigator1.ea, uid=0)
        household_location = {'District': 'Kampala', 'County': 'Bukoto', 'Subcounty': 'Some sub county',
                              'Parish': 'Some parish', 'Village': 'Some village'}

        households = Household.set_related_locations([household1])

        self.assertEqual(household_location, households[0].related_locations)
Пример #2
0
    def test_should_know_how_to_set_household_location_given_a_set_of_households(self):
        district = LocationType.objects.create(name="District", slug=slugify("district"))
        county = LocationType.objects.create(name="County", slug=slugify("county"))
        sub_county = LocationType.objects.create(name="Subcounty", slug=slugify("sub-county"))
        parish = LocationType.objects.create(name="Parish", slug=slugify("parish"))
        village = LocationType.objects.create(name="Village", slug=slugify("village"))

        uganda = Location.objects.create(name="Uganda", type=self.country)
        kampala_district = Location.objects.create(name="Kampala", type=district, tree_parent=uganda)
        bukoto_county = Location.objects.create(name="Bukoto", type=county, tree_parent=kampala_district)
        some_sub_county = Location.objects.create(name="Some sub county", type=sub_county, tree_parent=bukoto_county)
        some_parish = Location.objects.create(name="Some parish", type=parish, tree_parent=some_sub_county)
        some_village = Location.objects.create(name="Some village", type=village, tree_parent=some_parish)
        survey = Survey.objects.create(name="huhu")
        ea = EnumerationArea.objects.create(name="EA2", survey=survey)
        ea.locations.add(some_village)

        investigator1 = Investigator.objects.create(name="Investigator", mobile_number="987654321",
                                                    ea=ea,
                                                    backend=Backend.objects.create(name='something1'))

        household1 = Household.objects.create(investigator=investigator1, ea=investigator1.ea, uid=0)
        household_location = {'District': 'Kampala', 'County': 'Bukoto', 'Subcounty': 'Some sub county',
                              'Parish': 'Some parish', 'Village': 'Some village'}

        households = Household.set_related_locations([household1])

        self.assertEqual(household_location, households[0].related_locations)
Пример #3
0
def list_households(request):
    selected_location = None
    selected_ea = None
    all_households = Household.objects.order_by('household_member__householdhead__surname')

    params = request.GET
    if params.has_key('location') and params['location'].isdigit():
        selected_location = Location.objects.get(id=int(params['location']))
        corresponding_locations = selected_location.get_descendants(include_self=True)
        all_households = all_households.filter(ea__locations__in=corresponding_locations)

    if params.has_key('ea') and params['ea'].isdigit():
        selected_ea = EnumerationArea.objects.get(id=int(params['ea']))
        all_households = all_households.filter(ea=selected_ea)

    households = _remove_duplicates(all_households)
    households = Household.set_related_locations(households)
    if not households:
        location_type = selected_location.type.name.lower() if selected_location and selected_location.type else 'location'
        messages.error(request, "There are  no households currently registered  for this %s." % location_type)

    return render(request, 'households/index.html',
                  {'households': households, 'location_data': LocationWidget(selected_location, ea=selected_ea), 'request': request})