def periodTypeFilter(queryset, querydict):
    try:
        period_type=querydict['period_type']
        if period_type.startswith('Q'):
            if period_type == 'Q1':
                queryset = queryset.filter(coverage_from_date__month=1, coverage_from_date__day=1, coverage_to_date__month=3, coverage_to_date__day=31)
            elif period_type == 'Q2':
                queryset = queryset.filter(coverage_from_date__month=4, coverage_from_date__day=1, coverage_to_date__month=6, coverage_to_date__day=30)
            elif period_type == 'Q3':
                queryset = queryset.filter(coverage_from_date__month=7, coverage_from_date__day=1, coverage_to_date__month=9, coverage_to_date__day=30)
            elif period_type == 'Q4':
                queryset = queryset.filter(coverage_from_date__month=10, coverage_from_date__day=1, coverage_to_date__month=12, coverage_to_date__day=31)

        elif period_type.startswith('M'):
                        
            if period_type == 'M1':
                queryset = queryset.filter(coverage_from_date__month=1, coverage_from_date__day=1, coverage_to_date__month=1, coverage_to_date__day=31)
            elif period_type == 'M2':
                # leap years! 
                queryset = queryset.filter(Q(coverage_from_date__month=2, coverage_from_date__day=1, coverage_to_date__month=2, coverage_to_date__day=28)|Q(coverage_from_date__month=2, coverage_from_date__day=1, coverage_to_date__month=2, coverage_to_date__day=29))
            elif period_type == 'M3':
                queryset = queryset.filter(coverage_from_date__month=3, coverage_from_date__day=1, coverage_to_date__month=3, coverage_to_date__day=31)
            elif period_type == 'M4':
                queryset = queryset.filter(coverage_from_date__month=4, coverage_from_date__day=1, coverage_to_date__month=4, coverage_to_date__day=30)
            elif period_type == 'M5':
                queryset = queryset.filter(coverage_from_date__month=5, coverage_from_date__day=1, coverage_to_date__month=5, coverage_to_date__day=31)
            elif period_type == 'M6':
                queryset = queryset.filter(coverage_from_date__month=6, coverage_from_date__day=1, coverage_to_date__month=6, coverage_to_date__day=30)
            elif period_type == 'M7':
                queryset = queryset.filter(coverage_from_date__month=7, coverage_from_date__day=1, coverage_to_date__month=7, coverage_to_date__day=31)
            elif period_type == 'M8':
                queryset = queryset.filter(coverage_from_date__month=8, coverage_from_date__day=1, coverage_to_date__month=8, coverage_to_date__day=31)
            elif period_type == 'M9':
                queryset = queryset.filter(coverage_from_date__month=9, coverage_from_date__day=1, coverage_to_date__month=9, coverage_to_date__day=30)
            elif period_type == 'M10':
                queryset = queryset.filter(coverage_from_date__month=10, coverage_from_date__day=1, coverage_to_date__month=10, coverage_to_date__day=31)
            elif period_type == 'M11':
                queryset = queryset.filter(coverage_from_date__month=11, coverage_from_date__day=1, coverage_to_date__month=11, coverage_to_date__day=30)
            elif period_type == 'M12':
                queryset = queryset.filter(coverage_from_date__month=12, coverage_from_date__day=1, coverage_to_date__month=12, coverage_to_date__day=31)
                
        elif period_type == 'PRE':
            queryset = queryset.filter(Q(coverage_from_date=date(2014,10,1), coverage_to_date=date(2014,10,15)))
        elif period_type == 'POS':
            queryset = queryset.filter(Q(coverage_from_date=date(2014,10,16), coverage_to_date=date(2014,11,24)))
        elif period_type == 'EOY':
            queryset = queryset.filter(coverage_to_date=date(2014,12,31))
        
        
        elif period_type.startswith('S'):
            if period_type == 'S1':
                queryset = queryset.filter(coverage_from_date__month=1, coverage_from_date__day=1, coverage_to_date__month=6, coverage_to_date__day=30)
            elif period_type == 'S2':
                queryset = queryset.filter(coverage_from_date__month=7, coverage_from_date__day=1, coverage_to_date__month=12, coverage_to_date__day=31)
        
    except __HOLE__:
        pass
    return queryset
dataset/ETHPy150Open sunlightlabs/read_FEC/fecreader/api/filters.py/periodTypeFilter