<s> import calendar <EOL> from datetime import datetime <EOL> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import ugettext_noop <EOL> from corehq . apps . products . models import SQLProduct <EOL> from corehq . apps . programs . models import Program <EOL> from corehq . apps . reports . filters . base import BaseDrilldownOptionFilter , BaseSingleOptionFilter , BaseReportFilter <EOL> from corehq . apps . reports . filters . fixtures import AsyncLocationFilter <EOL> from custom . common import ALL_OPTION <EOL> class ProductByProgramFilter ( BaseDrilldownOptionFilter ) : <EOL> slug = "<STR_LIT>" <EOL> single_option_select = <NUM_LIT:0> <EOL> template = "<STR_LIT>" <EOL> label = ugettext_noop ( "<STR_LIT>" ) <EOL> @ property <EOL> def drilldown_map ( self ) : <EOL> options = [ { "<STR_LIT>" : ALL_OPTION , "<STR_LIT:text>" : "<STR_LIT>" , "<STR_LIT>" : [ ] } ] <EOL> for program in Program . by_domain ( self . domain ) : <EOL> products = [ { "<STR_LIT>" : ALL_OPTION , "<STR_LIT:text>" : "<STR_LIT>" , "<STR_LIT>" : [ ] } ] <EOL> for product in SQLProduct . objects . filter ( domain = self . domain , program_id = program . get_id ) : <EOL> products . append ( { "<STR_LIT>" : product . id , "<STR_LIT:text>" : product . name } ) <EOL> options . append ( { "<STR_LIT>" : program . get_id , "<STR_LIT:text>" : program . name , "<STR_LIT>" : products } ) <EOL> return options <EOL> @ classmethod <EOL> def get_labels ( cls ) : <EOL> return [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> @ property <EOL> def filter_context ( self ) : <EOL> controls = [ ] <EOL> for level , label in enumerate ( self . rendered_labels ) : <EOL> controls . append ( { <EOL> '<STR_LIT:label>' : label [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : label [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : level , <EOL> } ) <EOL> return { <EOL> '<STR_LIT>' : self . drilldown_map , <EOL> '<STR_LIT>' : controls , <EOL> '<STR_LIT>' : self . selected , <EOL> '<STR_LIT>' : self . use_only_last , <EOL> '<STR_LIT>' : self . final_notifications , <EOL> '<STR_LIT>' : self . drilldown_empty_text , <EOL> '<STR_LIT>' : not self . drilldown_map , <EOL> '<STR_LIT>' : self . single_option_select <EOL> } <EOL> @ classmethod <EOL> def _get_label_value ( cls , request , label ) : <EOL> slug = str ( label [ <NUM_LIT:1> ] ) <EOL> val = request . GET . getlist ( '<STR_LIT>' % ( cls . slug , str ( label [ <NUM_LIT:1> ] ) ) ) <EOL> return { <EOL> '<STR_LIT>' : slug , <EOL> '<STR_LIT:value>' : val , <EOL> } <EOL> class ProgramFilter ( BaseSingleOptionFilter ) : <EOL> slug = '<STR_LIT>' <EOL> label = '<STR_LIT>' <EOL> @ property <EOL> def options ( self ) : <EOL> return [ ( p . _id , p . name ) for p in Program . by_domain ( self . domain ) ] <EOL> class ILSDateFilter ( BaseReportFilter ) : <EOL> slug = "<STR_LIT>" <EOL> label = "<STR_LIT>" <EOL> css_class = '<STR_LIT>' <EOL> template = '<STR_LIT>' <EOL> def selected ( self , type ) : <EOL> slug = '<STR_LIT>' . format ( self . slug , type ) <EOL> return self . request . GET . get ( slug ) <EOL> @ property <EOL> def select_options ( self ) : <EOL> start_year = getattr ( settings , '<STR_LIT>' , <NUM_LIT> ) <EOL> years = [ dict ( val = unicode ( y ) , text = y ) for y in range ( start_year , datetime . utcnow ( ) . year + <NUM_LIT:1> ) ] <EOL> years . reverse ( ) <EOL> months = [ dict ( val = "<STR_LIT>" % m , text = calendar . month_name [ m ] ) for m in range ( <NUM_LIT:1> , <NUM_LIT> ) ] <EOL> quarters = [ dict ( val = <NUM_LIT:1> , text = '<STR_LIT>' ) , <EOL> dict ( val = <NUM_LIT:2> , text = '<STR_LIT>' ) , <EOL> dict ( val = <NUM_LIT:3> , text = '<STR_LIT>' ) , <EOL> dict ( val = <NUM_LIT:4> , text = '<STR_LIT>' ) ] <EOL> return [ <EOL> { <EOL> '<STR_LIT:text>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : months , <EOL> '<STR_LIT>' : years <EOL> } , <EOL> { <EOL> '<STR_LIT:text>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : quarters , <EOL> '<STR_LIT>' : years <EOL> } , <EOL> { <EOL> '<STR_LIT:text>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : years <EOL> } ] <EOL> @ property <EOL> def filter_context ( self ) : <EOL> return dict ( <EOL> select_options = self . select_options , <EOL> selected_type = self . selected ( '<STR_LIT:type>' ) if self . selected ( '<STR_LIT:type>' ) else <NUM_LIT:1> , <EOL> selected_first = self . selected ( '<STR_LIT>' ) if self . selected ( '<STR_LIT>' ) else datetime . utcnow ( ) . month , <EOL> selected_second = self . selected ( '<STR_LIT>' ) if self . selected ( '<STR_LIT>' ) else datetime . utcnow ( ) . year <EOL> ) <EOL> class B3ILSDateFilter ( ILSDateFilter ) : <EOL> css_class = '<STR_LIT>' <EOL> template = '<STR_LIT>' <EOL> class ILSAsyncLocationFilter ( AsyncLocationFilter ) : <EOL> @ property <EOL> def api_root ( self ) : <EOL> return reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : self . domain , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> class B3ILSAsyncLocationFilter ( ILSAsyncLocationFilter ) : <EOL> css_class = '<STR_LIT>' <EOL> template = '<STR_LIT>' </s>
