def simple_indicator(request, indicator_id): hierarchy_limit = 2 selected_location = None params = request.GET or request.POST locations_filter = LocationsFilterForm(data=params) first_level_location_analyzed = Location.objects.filter( type__name__iexact="country")[0] indicator = Indicator.objects.get(id=indicator_id) formula = indicator.formula.all() if not formula: messages.error(request, "No formula was found in this indicator") return HttpResponseRedirect(reverse("list_indicator_page")) request.breadcrumbs([ ('Indicator List', reverse('list_indicator_page')), ]) if locations_filter.last_location_selected: first_level_location_analyzed = locations_filter.last_location_selected selected_location = first_level_location_analyzed formula = formula[0] indicator_service = SimpleIndicatorService(formula, first_level_location_analyzed) data_series, locations = indicator_service.get_location_names_and_data_series( ) context = { 'request': request, 'data_series': data_series, 'tabulated_data': indicator_service.tabulated_data_series(), 'location_names': locations, 'indicator': indicator, 'locations_filter': locations_filter } return render(request, 'formula/simple_indicator.html', context)
def simple_indicator(request, indicator_id): hierarchy_limit = 2 selected_location = None first_level_location_analyzed = Location.objects.filter(type__name__iexact="country")[0] indicator = Indicator.objects.get(id=indicator_id) formula = indicator.formula.all() if not formula: messages.error(request, "No formula was found in this indicator") return HttpResponseRedirect(reverse("list_indicator_page")) params = request.GET if contains_key(params, "location"): first_level_location_analyzed = Location.objects.get(id=params["location"]) selected_location = first_level_location_analyzed formula = formula[0] indicator_service = SimpleIndicatorService(formula, first_level_location_analyzed) data_series, locations = indicator_service.get_location_names_and_data_series() context = { "request": request, "data_series": data_series, "tabulated_data": indicator_service.tabulated_data_series(), "location_names": locations, "indicator": indicator, "locations": LocationWidget(selected_location, level=hierarchy_limit), } return render(request, "formula/simple_indicator.html", context)
def simple_indicator(request, indicator_id): hierarchy_limit = 2 selected_location = None first_level_location_analyzed = Location.objects.filter( type__name__iexact="country")[0] indicator = Indicator.objects.get(id=indicator_id) formula = indicator.formula.all() if not formula: messages.error(request, "No formula was found in this indicator") return HttpResponseRedirect(reverse("list_indicator_page")) params = request.GET if contains_key(params, 'location'): first_level_location_analyzed = Location.objects.get( id=params['location']) selected_location = first_level_location_analyzed formula = formula[0] indicator_service = SimpleIndicatorService(formula, first_level_location_analyzed) data_series, locations = indicator_service.get_location_names_and_data_series( ) context = { 'request': request, 'data_series': data_series, 'tabulated_data': indicator_service.tabulated_data_series(), 'location_names': locations, 'indicator': indicator, 'locations': LocationWidget(selected_location, level=hierarchy_limit) } return render(request, 'formula/simple_indicator.html', context)
def simple_indicator(request, indicator_id): hierarchy_limit = 2 selected_location = None params = request.GET or request.POST locations_filter = LocationsFilterForm(data=params) first_level_location_analyzed = Location.objects.filter(type__name__iexact="country")[0] indicator = Indicator.objects.get(id=indicator_id) formula = indicator.formula.all() if not formula: messages.error(request, "No formula was found in this indicator") return HttpResponseRedirect(reverse("list_indicator_page")) request.breadcrumbs([ ('Indicator List', reverse('list_indicator_page')), ]) if locations_filter.last_location_selected: first_level_location_analyzed = locations_filter.last_location_selected selected_location = first_level_location_analyzed formula = formula[0] indicator_service = SimpleIndicatorService(formula, first_level_location_analyzed) data_series, locations = indicator_service.get_location_names_and_data_series() context = {'request': request, 'data_series': data_series, 'tabulated_data': indicator_service.tabulated_data_series(), 'location_names': locations, 'indicator': indicator, 'locations_filter': locations_filter} return render(request, 'formula/simple_indicator.html', context)
def test_gets_location_names_and_data_series_for_a_parent_location_and_formula( self): simple_indicator_service = SimpleIndicatorService( self.formula, self.uganda) region_responses = [{'data': [0, 0], 'name': 'This is an option1'}] data_series, location = simple_indicator_service.get_location_names_and_data_series( ) self.assertEquals([self.central.name, self.west.name], location) self.assertEquals(region_responses, data_series)
def test_gets_location_names_and_data_series_for_a_parent_location_and_formula(self): self.investigator.member_answered(self.question_3, self.household_head_1, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_3, self.household_head_2, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_3, self.household_head_3, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_3, self.household_head_4, self.no_option.order, self.batch) self.investigator.member_answered(self.question_3, self.household_head_5, self.no_option.order, self.batch) self.investigator_2.member_answered(self.question_3, self.household_head_6, self.yes_option.order, self.batch) self.investigator_2.member_answered(self.question_3, self.household_head_7, self.yes_option.order, self.batch) self.investigator_2.member_answered(self.question_3, self.household_head_8, self.no_option.order, self.batch) self.investigator_2.member_answered(self.question_3, self.household_head_9, self.no_option.order, self.batch) simple_indicator_service = SimpleIndicatorService(self.formula, self.uganda) region_responses = [{'data': [3, 2], 'name': self.yes_option.text}, {'data': [2, 2], 'name': self.no_option.text}] data_series, location = simple_indicator_service.get_location_names_and_data_series() self.assertEquals([self.central.name, self.west.name], location) self.assertEquals(region_responses, data_series)
def test_gets_location_names_and_data_series_for_a_parent_location_and_formula(self): simple_indicator_service = SimpleIndicatorService(self.formula, self.uganda) region_responses = [{'data': [5, 4], 'name': self.general_group.name}] data_series, location = simple_indicator_service.get_location_names_and_data_series() self.assertEquals([self.central.name, self.west.name], location) self.assertEquals(region_responses, data_series)