def get(self, *args, **kwargs): if int(kwargs['indicator']) == 0: del kwargs['indicator'] if int(kwargs['program']) == 0: del kwargs['program'] print kwargs queryset = CollectedData.objects.filter(**kwargs) dataset = CollectedDataResource().export(queryset) response = HttpResponse(dataset.csv, content_type='application/ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=indicator_data.csv' return response
def get(self, request, *args, **kwargs): countries = getCountry(request.user) getPrograms = WorkflowLevel1.objects.all().filter( country__in=countries).distinct() getIndicators = Indicator.objects.all()\ .filter(workflowlevel1__country__in=countries)\ .exclude(collecteddata__isnull=True) workflowlevel1 = self.kwargs['workflowlevel1'] indicator = self.kwargs['indicator'] type = self.kwargs['type'] indicator_name = "" type_name = "" workflowlevel1_name = "" if self.request.GET.get('export'): dataset = CollectedDataResource().export(indicators) response = HttpResponse(dataset.csv, content_type='application/ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=indicator_data.csv' return response return render( request, self.template_name, { 'getPrograms': getPrograms, 'getIndicators': getIndicators, 'workflowlevel1': workflowlevel1, 'indicator': indicator, 'type': type, 'filter_workflowlevel1': workflowlevel1_name, 'filter_indicator': indicator_name, 'indicator': indicator, 'workflowlevel1': workflowlevel1, 'indicator_name': indicator_name, 'workflowlevel1_name': workflowlevel1_name, 'type_name': type_name })
def get(self, request, *args, **kwargs): if int(kwargs['indicator']) == 0: del kwargs['indicator'] if int(kwargs['workflowlevel1']) == 0: del kwargs['workflowlevel1'] if int(kwargs['type']) == 0: del kwargs['type'] else: kwargs['indicator__indicator_type__id'] = kwargs['type'] del kwargs['type'] countries = getCountry(request.user) queryset = CollectedData.objects.filter(**kwargs).filter( indicator__workflowlevel1__country__in=countries) dataset = CollectedDataResource().export(queryset) response = HttpResponse(dataset.csv, content_type='application/ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=indicator_data.csv' return response
def get(self, *args, **kwargs): #filter by program or indicator print int(self.kwargs['program']) print int(self.kwargs['indicator']) if int(self.kwargs['program']) != 0 and int( self.kwargs['indicator']) == 0: print "Program" queryset = CollectedData.objects.all().filter( indicator__program__id=self.kwargs['program']) elif int(self.kwargs['program']) == 0 and int( self.kwargs['indicator']) != 0: print "Indicator" queryset = CollectedData.objects.all().filter( indicator__id=self.kwargs['indicator']) else: countries = getCountry(self.request.user) queryset = CollectedData.objects.all().filter( indicator__country__in=countries) dataset = CollectedDataResource().export(queryset) response = HttpResponse(dataset, content_type='text/csv') response[ 'Content-Disposition'] = 'attachment; filename=indicator_data.csv' return response
def get(self, request, *args, **kwargs): countries = getCountry(request.user) getPrograms = Program.objects.all().filter( funding_status="Funded", country__in=countries).distinct() getIndicators = Indicator.objects.all().filter( country__in=countries).exclude(collecteddata__isnull=True) getCollectedData = None collected_sum = None #filter by program or inidcator or both if int(self.kwargs['indicator']) != 0: getCollectedData = CollectedData.objects.all().prefetch_related( 'evidence', 'indicator', 'program', 'indicator__objectives', 'indicator__strategic_objectives').filter( indicator__id=self.kwargs['indicator']).order_by( 'program', 'indicator__number') collected_sum = CollectedData.objects.filter( indicator__id=self.kwargs['indicator']).aggregate( Sum('targeted'), Sum('achieved')) elif int(self.kwargs['indicator']) == 0 and int( self.kwargs['program']) != 0: getCollectedData = CollectedData.objects.all().prefetch_related( 'evidence', 'indicator', 'program', 'indicator__objectives', 'indicator__strategic_objectives').filter( program=self.kwargs['program']).order_by( 'program', 'indicator__number') collected_sum = CollectedData.objects.filter( program=self.kwargs['program']).aggregate( Sum('targeted'), Sum('achieved')) #redress indicator query based on submitted program getIndicators = Indicator.objects.select_related().filter( program=self.kwargs['program']).exclude( collecteddata__isnull=True) elif int(self.kwargs['indicator']) != 0 and int( self.kwargs['program']) != 0: getCollectedData = CollectedData.objects.all().prefetch_related( 'evidence', 'indicator', 'program', 'indicator__objectives', 'indicator__strategic_objectives').filter( program=self.kwargs['program'], indicator__id=self.kwargs['indicator']).order_by( 'program', 'indicator__number') collected_sum = CollectedData.objects.filter( program=self.kwargs['program'], indicator__id=self.kwargs['indicator']).aggregate( Sum('targeted'), Sum('achieved')) #redress indicator query based on submitted program getIndicators = Indicator.objects.select_related().filter( program=self.kwargs['program']).exclude( collecteddata__isnull=True) elif int(self.kwargs['indicator']) == 0 and int( self.kwargs['program']) == 0: getCollectedData = CollectedData.objects.all().prefetch_related( 'evidence', 'indicator', 'program', 'indicator__objectives', 'indicator__strategic_objectives').filter( indicator__country__in=countries).order_by( 'program', 'indicator__number') collected_sum = CollectedData.objects.filter( indicator__country__in=countries).aggregate( Sum('targeted'), Sum('achieved')) #get details about the filtered indicator or program try: filter_indicator = Indicator.objects.get( id=self.kwargs['indicator']) except Indicator.DoesNotExist: filter_indicator = None try: filter_program = Program.objects.get(id=self.kwargs['program']) except Program.DoesNotExist: filter_program = None if self.request.GET.get('export'): dataset = CollectedDataResource().export(getCollectedData) response = HttpResponse(dataset.csv, content_type='application/ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=indicator_data.csv' return response return render( request, self.template_name, { 'getCollectedData': getCollectedData, 'getPrograms': getPrograms, 'getIndicators': getIndicators, 'filter_program': filter_program, 'filter_indicator': filter_indicator, 'collected_sum': collected_sum })
def get(self, request, *args, **kwargs): countries = getCountry(request.user) getPrograms = Program.objects.all().filter( funding_status="Funded", country__in=countries).distinct() getIndicators = Indicator.objects.all().filter( program__country__in=countries).exclude(collecteddata__isnull=True) getIndicatorTypes = IndicatorType.objects.all() program = self.kwargs['program'] indicator = self.kwargs['indicator'] type = self.kwargs['type'] indicator_name = "" type_name = "" program_name = "" q = {'program__id__isnull': False} # if we have a program filter active if int(program) != 0: q = { 'program__id': program, } # redress the indicator list based on program getIndicators = Indicator.objects.select_related().filter( program=program) program_name = Program.objects.get(id=program) # if we have an indicator type active if int(type) != 0: r = { 'indicator__indicator_type__id': type, } q.update(r) # redress the indicator list based on type getIndicators = Indicator.objects.select_related().filter( indicator_type__id=type) type_name = IndicatorType.objects.get(id=type).indicator_type # if we have an indicator id append it to the query filter if int(indicator) != 0: s = { 'indicator': indicator, } q.update(s) indicator_name = Indicator.objects.get(id=indicator) indicators = CollectedData.objects.all().prefetch_related( 'evidence', 'indicator', 'program', 'indicator__objectives', 'indicator__strategic_objectives' ).filter(program__country__in=countries).filter(**q).order_by( 'indicator__program__name', 'indicator__number').values( 'indicator__id', 'indicator__name', 'indicator__program__name', 'indicator__indicator_type__indicator_type', 'indicator__level__name', 'indicator__sector__sector', 'date_collected', 'indicator__baseline', 'indicator__lop_target', 'indicator__key_performance_indicator', 'indicator__external_service_record__external_service__name', 'evidence', 'tola_table', 'targeted', 'achieved') if self.request.GET.get('export'): dataset = CollectedDataResource().export(indicators) response = HttpResponse(dataset.csv, content_type='application/ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=indicator_data.csv' return response return render( request, self.template_name, { 'indicators': indicators, 'getPrograms': getPrograms, 'getIndicatorTypes': getIndicatorTypes, 'getIndicators': getIndicators, 'program': program, 'indicator': indicator, 'type': type, 'filter_program': program_name, 'filter_indicator': indicator_name, 'indicator': indicator, 'program': program, 'type': type, 'indicator_name': indicator_name, 'program_name': program_name, 'type_name': type_name })