Esempio n. 1
0
 def assert_invalid_if_field_is_non_sense(self, field_key):
     form_data = self.data.copy()
     form_data[field_key] = 'non_sense_hohoho_&^%$#'
     location_filter_form = LocationFilterForm(form_data)
     self.assertFalse(location_filter_form.is_valid())
     message = "Select a valid choice. That choice is not one of the available choices."
     self.assertEqual([message], location_filter_form.errors[field_key])
Esempio n. 2
0
 def assert_invalid_if_field_is_non_sense(self, field_key):
     form_data = self.data.copy()
     form_data[field_key] = 'non_sense_hohoho_&^%$#'
     location_filter_form = LocationFilterForm(form_data)
     self.assertFalse(location_filter_form.is_valid())
     message = "Select a valid choice. That choice is not one of the available choices."
     self.assertEqual([message], location_filter_form.errors[field_key])
Esempio n. 3
0
 def test_invalid_if_batch_is_not_under_survey(self):
     form_data = self.data.copy()
     form_data['survey'] = self.survey.id
     form_data['batch'] = self.batch_1.id
     location_filter_form = LocationFilterForm(form_data)
     self.assertFalse(location_filter_form.is_valid())
     message = "Select a valid choice. That choice is not one of the available choices."
     self.assertEqual([message], location_filter_form.errors['batch'])
Esempio n. 4
0
 def assert_invalid_if_field_does_not_exist(self, field_key):
     form_data = self.data.copy()
     non_existing_survey_id = 666
     form_data[field_key] = non_existing_survey_id
     location_filter_form = LocationFilterForm(form_data)
     self.assertFalse(location_filter_form.is_valid())
     message = "Select a valid choice. That choice is not one of the available choices."
     self.assertEqual([message], location_filter_form.errors[field_key])
Esempio n. 5
0
 def test_invalid_if_ea_is_not_under_survey(self):
     another_ea = EnumerationArea.objects.create(name="another ea not in survey")
     form_data = self.data.copy()
     form_data['ea'] = another_ea.id
     location_filter_form = LocationFilterForm(form_data)
     self.assertFalse(location_filter_form.is_valid())
     message = "Select a valid choice. That choice is not one of the available choices."
     self.assertEqual([message], location_filter_form.errors['ea'])
Esempio n. 6
0
 def test_invalid_if_batch_is_not_under_survey(self):
     form_data = self.data.copy()
     form_data['survey'] = self.survey.id
     form_data['batch'] = self.batch_1.id
     location_filter_form = LocationFilterForm(form_data)
     self.assertFalse(location_filter_form.is_valid())
     message = "Select a valid choice. That choice is not one of the available choices."
     self.assertEqual([message], location_filter_form.errors['batch'])
Esempio n. 7
0
 def assert_invalid_if_field_does_not_exist(self, field_key):
     form_data = self.data.copy()
     non_existing_survey_id = 666
     form_data[field_key] = non_existing_survey_id
     location_filter_form = LocationFilterForm(form_data)
     self.assertFalse(location_filter_form.is_valid())
     message = "Select a valid choice. That choice is not one of the available choices."
     self.assertEqual([message], location_filter_form.errors[field_key])
Esempio n. 8
0
 def test_invalid_if_ea_is_not_under_survey(self):
     another_ea = EnumerationArea.objects.create(
         name="another ea not in survey")
     form_data = self.data.copy()
     form_data['ea'] = another_ea.id
     location_filter_form = LocationFilterForm(form_data)
     self.assertFalse(location_filter_form.is_valid())
     message = "Select a valid choice. That choice is not one of the available choices."
     self.assertEqual([message], location_filter_form.errors['ea'])
Esempio n. 9
0
def show(request):
    selected_location = None
    location_filter_form = LocationFilterForm()
    content = {'action': 'survey_completion_rates',
               'request': request}
    if request.method == 'POST':
        location_filter_form = LocationFilterForm(request.POST)
        if location_filter_form.is_valid():
            batch = location_filter_form.cleaned_data.get('batch', None)
            selected_location = location_filter_form.cleaned_data.get('location', None)
            selected_ea = location_filter_form.cleaned_data.get('ea', None)
            if selected_ea:
                return render_household_details(request, selected_ea, batch)
            if selected_location:
                high_level_locations = selected_location.get_children().order_by('name')
            else:
                high_level_locations = __get_parent_level_locations()
            content['completion_rates'] = BatchHighLevelLocationsCompletionRates(batch, high_level_locations)
    content['locations'] = LocationWidget(selected_location)
    content['filter'] = location_filter_form
    return render(request, 'aggregates/completion_status.html', content)
Esempio n. 10
0
def show(request):
    selected_location = None
    location_filter_form = LocationFilterForm()
    content = {'action': 'survey_completion_rates',
               'request': request}
    locations_filter = LocFilterForm(data=request.POST, include_ea=True)
    if request.method == 'POST':
        location_filter_form = LocationFilterForm(request.POST)
        if location_filter_form.is_valid():
            batch = location_filter_form.cleaned_data.get('batch', None)
            content['selected_batch'] = batch
            selected_location = locations_filter.last_location_selected
            selected_ea = request.POST.get('enumeration_area', None)
            if selected_ea:
                return render_household_details(request, selected_location, batch, selected_ea)
            if selected_location:
                high_level_locations = selected_location.get_children().order_by('name')
                content['selection_location_type'] = LocationType.objects.get(parent=selected_location.type)
            else:
                high_level_locations = __get_parent_level_locations()
            content['completion_rates'] = BatchHighLevelLocationsCompletionRates(batch, high_level_locations)
    content['locations_filter'] = locations_filter
    content['filter'] = location_filter_form
    return render(request, 'aggregates/completion_status.html', content)
Esempio n. 11
0
def show(request):
    selected_location = None
    location_filter_form = LocationFilterForm()
    content = {'action': 'survey_completion_rates',
               'request': request}
    locations_filter = LocFilterForm(data=request.POST, include_ea=True)
    if request.method == 'POST':
        location_filter_form = LocationFilterForm(request.POST)
        if location_filter_form.is_valid():
            batch = location_filter_form.cleaned_data.get('batch', None)
            content['selected_batch'] = batch
            selected_location = locations_filter.last_location_selected
            selected_ea = request.POST.get('enumeration_area', None)
            if selected_ea:
                return render_household_details(request, selected_location, batch, selected_ea)
            if selected_location:
                high_level_locations = selected_location.get_children().order_by('name')
                content['selection_location_type'] = LocationType.objects.get(parent=selected_location.type)
            else:
                high_level_locations = __get_parent_level_locations()
            content['completion_rates'] = BatchHighLevelLocationsCompletionRates(batch, high_level_locations)
    content['locations_filter'] = locations_filter
    content['filter'] = location_filter_form
    return render(request, 'aggregates/completion_status.html', content)
Esempio n. 12
0
def show(request):
    selected_location = None
    location_filter_form = LocationFilterForm()
    content = {'action': 'survey_completion_rates', 'request': request}
    if request.method == 'POST':
        location_filter_form = LocationFilterForm(request.POST)
        if location_filter_form.is_valid():
            batch = location_filter_form.cleaned_data.get('batch', None)
            selected_location = location_filter_form.cleaned_data.get(
                'location', None)
            selected_ea = location_filter_form.cleaned_data.get('ea', None)
            if selected_ea:
                return render_household_details(request, selected_ea, batch)
            if selected_location:
                high_level_locations = selected_location.get_children(
                ).order_by('name')
            else:
                high_level_locations = __get_parent_level_locations()
            content[
                'completion_rates'] = BatchHighLevelLocationsCompletionRates(
                    batch, high_level_locations)
    content['locations'] = LocationWidget(selected_location)
    content['filter'] = location_filter_form
    return render(request, 'aggregates/completion_status.html', content)
Esempio n. 13
0
 def test_valid_even_if_ea_is_empty(self):
     form_data = self.data.copy()
     form_data['ea'] = ''
     location_filter_form = LocationFilterForm(form_data)
     self.assertTrue(location_filter_form.is_valid())
Esempio n. 14
0
 def test_valid(self):
     location_filter_form = LocationFilterForm(self.data)
     self.assertTrue(location_filter_form.is_valid())
Esempio n. 15
0
 def test_valid_even_if_ea_is_empty(self):
     form_data = self.data.copy()
     form_data['ea'] = ''
     location_filter_form = LocationFilterForm(form_data)
     self.assertTrue(location_filter_form.is_valid())
Esempio n. 16
0
 def test_valid(self):
     location_filter_form = LocationFilterForm(self.data)
     self.assertTrue(location_filter_form.is_valid())