Example #1
0
File: views.py Project: flaxter/gbd
def covariate_data_count_show(request, id):
    """ Show amount of data for each country of the selected covariate type

    Parameters:
    -----------
      id : int
        the id of the covariate type to display
    """
    ct = get_object_or_404(CovariateType, id=id)
    
    if ct.region_only:
        pm = ct.covariate_set.all().distinct().values('region')

        for c in pm:
            c['clean_region'] = clean(c['region'])
            c['count'] = ct.covariate_set.filter(region=c['region']).count()
            if c['count'] < (ct.year_end - ct.year_start + 1) * 3:
                c['color'] = 'class=highlight'
            else:
                c['color'] = ''
        
        if len(pm) != 21:
            error = 'Total number of regions are wrong.  Found ' + str(len(pm)) + '.  Should be 21.'
        else:
            error = ''

        return render_to_response('covariate_data_count_show.html',
                                  {'ct': ct, 'level': 'region', 'error': error,
                                   'paginated_models': view_utils.paginated_models(request, pm)})
    else:
        pm = ct.covariate_set.all().distinct().values('iso3')

        for c in pm:
            c['count'] = ct.covariate_set.filter(iso3=c['iso3']).count()
            if c['count'] < (ct.year_end - ct.year_start + 1) * 3:
                c['color'] = 'class=highlight'
            else:
                c['color'] = ''

        return render_to_response('covariate_data_count_show.html',
                                  {'ct': ct, 'level': 'country',
                                   'paginated_models': view_utils.paginated_models(request, pm)})
Example #2
0
File: views.py Project: flaxter/gbd
def covariate_type_show(request, id):
    """ Show an index page for the selected covariate type

    Parameters:
    -----------
      id : int
        the id of the covariate type to display
    """
    ct = get_object_or_404(CovariateType, id=id)

    if ct.region_only:
        pm = ct.covariate_set.all().distinct().values('region', 'sex')

        for c in pm:
            c['clean_region'] = clean(c['region'])
            c['count'] = ct.covariate_set.filter(region=c['region'], sex=c['sex']).count()
            if c['count'] < ct.year_end - ct.year_start + 1:
                c['color'] = 'class=highlight'
            else:
                c['color'] = ''

        return render_to_response('covariate_type_show.html',
                                  {'ct': ct, 'level': 'region',
                                   'paginated_models': view_utils.paginated_models(request, pm)})
    else:
        pm = ct.covariate_set.all().distinct().values('iso3', 'sex')

        for c in pm:
            c['count'] = ct.covariate_set.filter(iso3=c['iso3'], sex=c['sex']).count()
            if c['count'] < ct.year_end - ct.year_start + 1:
                c['color'] = 'class=highlight'
            else:
                c['color'] = ''

        return render_to_response('covariate_type_show.html',
                                  {'ct': ct, 'level': 'country',
                                   'paginated_models': view_utils.paginated_models(request, pm)})