Example #1
0
def indicator_data_report(request, id=0, program=0):
    """
    Show LIST of indicator based quantitative outputs with a filtered search view using django-tables2
    and django-filter
    """
    countries = getCountry(request.user)
    getPrograms = Program.objects.all().filter(
        funding_status="Funded", country__in=countries).distinct()
    getIndicators = Indicator.objects.select_related().filter(
        country__in=countries)
    indicator_name = None
    program_name = None
    q = None

    #Build query based on filters and search
    if int(id) != 0:
        getSiteProfile = Indicator.objects.all().filter(id=id).select_related()
        q = {'indicator__id': id}
        indicator_name = Indicator.objects.get(id=id).name
    else:
        getSiteProfile = SiteProfile.objects.all().select_related()
        q = {
            'indicator__country__in': countries,
        }

    if int(program) != 0:
        getSiteProfile = SiteProfile.objects.all().filter(
            projectagreement__program__id=program).select_related()
        program_name = Program.objects.get(id=program).name
        q = {
            'program__id': program,
            'agreement__program__id': program,
        }
        #redress the indicator list based on program
        getIndicators = Indicator.objects.select_related().filter(
            program=program)

    if request.method == "GET" and "search" in request.GET:
        """
         fields = ('targeted', 'achieved', 'description', 'indicator', 'agreement', 'complete')
        """
        queryset = CollectedData.objects.filter(**q).filter(
            Q(agreement__project_name__contains=request.GET["search"])
            | Q(description__icontains=request.GET["search"])
            | Q(indicator__name__contains=request.GET["search"])
        ).select_related()
    else:
        queryset = CollectedData.objects.all().filter(**q).select_related()

    #pass query to table and configure
    table = IndicatorDataTable(queryset)
    table.paginate(page=request.GET.get('page', 1), per_page=20)

    RequestConfig(request).configure(table)

    # send the keys and vars from the json data to the template along with submitted feed info and silos for new form
    return render(
        request, "indicators/data_report.html", {
            'getQuantitativeData': queryset,
            'countries': countries,
            'getSiteProfile': getSiteProfile,
            'table': table,
            'getPrograms': getPrograms,
            'getIndicators': getIndicators,
            'form': FilterForm(),
            'helper': FilterForm.helper,
            'id': id,
            'program': program,
            'indicator_name': indicator_name,
            'program_name': program_name
        })
Example #2
0
def indicator_data_report(request, id=0, program=0):
    """
    This is the Indicator Visual report for each indicator and program.  Displays a list collected data entries
    and sums it at the bottom.  Lives in the "Reports" navigation.
    URL: indicators/data/[indicator_id]/[program_id]/
    :param request:
    :param id: Indicator ID
    :param program:
    :return:
    """
    countries = getCountry(request.user)
    getPrograms = Program.objects.all().filter(
        funding_status="Funded", country__in=countries).distinct()
    getIndicators = Indicator.objects.select_related().filter(
        country__in=countries)
    indicator_name = None
    program_name = None
    q = None

    #Build query based on filters and search
    if int(id) != 0:
        getSiteProfile = Indicator.objects.all().filter(id=id).select_related()
        q = {'indicator__id': id}
        indicator_name = Indicator.objects.get(id=id).name
    else:
        getSiteProfile = SiteProfile.objects.all().select_related()
        q = {
            'indicator__country__in': countries,
        }

    if int(program) != 0:
        getSiteProfile = SiteProfile.objects.all().filter(
            projectagreement__program__id=program).select_related()
        program_name = Program.objects.get(id=program).name
        q = {
            'program__id': program,
            'agreement__program__id': program,
        }
        #redress the indicator list based on program
        getIndicators = Indicator.objects.select_related().filter(
            program=program)

    if request.method == "GET" and "search" in request.GET:
        queryset = CollectedData.objects.filter(**q).filter(
            Q(agreement__project_name__contains=request.GET["search"])
            | Q(description__icontains=request.GET["search"])
            | Q(indicator__name__contains=request.GET["search"])
        ).select_related()
    else:
        queryset = CollectedData.objects.all().filter(**q).select_related()

    #pass query to table and configure
    table = IndicatorDataTable(queryset)
    table.paginate(page=request.GET.get('page', 1), per_page=20)

    RequestConfig(request).configure(table)

    # send the keys and vars from the json data to the template along with submitted feed info and silos for new form
    return render(
        request, "indicators/data_report.html", {
            'getQuantitativeData': queryset,
            'countries': countries,
            'getSiteProfile': getSiteProfile,
            'table': table,
            'getPrograms': getPrograms,
            'getIndicators': getIndicators,
            'form': FilterForm(),
            'helper': FilterForm.helper,
            'id': id,
            'program': program,
            'indicator_name': indicator_name,
            'program_name': program_name
        })