<s> from corehq . apps . es import filters as esfilters <EOL> from corehq . apps . es . cases import ( <EOL> owner , <EOL> is_closed , <EOL> opened_range , <EOL> modified_range , <EOL> user , <EOL> closed_range , <EOL> opened_by , <EOL> owner_type ) <EOL> from corehq . apps . es . forms import app , submitted , user_id , user_type <EOL> from corehq . apps . export . esaccessors import get_group_user_ids <EOL> from corehq . pillows . utils import USER_TYPES <EOL> def _assert_user_types ( user_types ) : <EOL> if isinstance ( user_types , basestring ) : <EOL> user_types = [ user_types ] <EOL> for type_ in user_types : <EOL> assert type_ in USER_TYPES , "<STR_LIT>" . format ( USER_TYPES , type_ ) <EOL> class ExportFilter ( object ) : <EOL> """<STR_LIT>""" <EOL> def to_es_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class OR ( ExportFilter ) : <EOL> def __init__ ( self , * args ) : <EOL> self . operand_filters = args <EOL> def to_es_filter ( self ) : <EOL> return esfilters . OR ( * [ f . to_es_filter ( ) for f in self . operand_filters ] ) <EOL> class AppFilter ( ExportFilter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app_id ) : <EOL> self . app_id = app_id <EOL> def to_es_filter ( self ) : <EOL> return app ( self . app_id ) <EOL> class RangeExportFilter ( ExportFilter ) : <EOL> def __init__ ( self , gt = None , gte = None , lt = None , lte = None ) : <EOL> self . gt = gt <EOL> self . gte = gte <EOL> self . lt = lt <EOL> self . lte = lte <EOL> class OwnerFilter ( ExportFilter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , owner_id ) : <EOL> self . owner_id = owner_id <EOL> def to_es_filter ( self ) : <EOL> return owner ( self . owner_id ) <EOL> class OwnerTypeFilter ( ExportFilter ) : <EOL> def __init__ ( self , owner_type ) : <EOL> _assert_user_types ( owner_type ) <EOL> self . owner_types = owner_type <EOL> def to_es_filter ( self ) : <EOL> return owner_type ( self . owner_types ) <EOL> class IsClosedFilter ( ExportFilter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , is_closed ) : <EOL> self . is_closed = is_closed <EOL> def to_es_filter ( self ) : <EOL> return is_closed ( self . is_closed ) <EOL> class NameFilter ( ExportFilter ) : <EOL> def __init__ ( self , case_name ) : <EOL> self . case_name = case_name <EOL> def to_es_filter ( self ) : <EOL> return esfilters . term ( '<STR_LIT:name>' , self . case_name ) <EOL> class OpenedOnRangeFilter ( RangeExportFilter ) : <EOL> def to_es_filter ( self ) : <EOL> return opened_range ( self . gt , self . gte , self . lt , self . lte ) <EOL> class OpenedByFilter ( ExportFilter ) : <EOL> def __init__ ( self , opened_by ) : <EOL> self . opened_by = opened_by <EOL> def to_es_filter ( self ) : <EOL> return opened_by ( self . opened_by ) <EOL> class ModifiedOnRangeFilter ( RangeExportFilter ) : <EOL> def to_es_filter ( self ) : <EOL> return modified_range ( self . gt , self . gte , self . lt , self . lte ) <EOL> class LastModifiedByFilter ( ExportFilter ) : <EOL> def __init__ ( self , last_modified_by ) : <EOL> self . last_modified_by = last_modified_by <EOL> def to_es_filter ( self ) : <EOL> return user ( self . last_modified_by ) <EOL> class ClosedOnRangeFilter ( RangeExportFilter ) : <EOL> def to_es_filter ( self ) : <EOL> return closed_range ( self . gt , self . gte , self . lt , self . lte ) <EOL> class ClosedByFilter ( ExportFilter ) : <EOL> def __init__ ( self , closed_by ) : <EOL> self . closed_by = closed_by <EOL> def to_es_filter ( self ) : <EOL> return esfilters . term ( "<STR_LIT>" , self . closed_by ) <EOL> class GroupFilter ( ExportFilter ) : <EOL> base_filter = None <EOL> def __init__ ( self , group_id ) : <EOL> self . group_id = group_id <EOL> def to_es_filter ( self ) : <EOL> user_ids = get_group_user_ids ( self . group_id ) <EOL> return self . base_filter ( user_ids ) . to_es_filter ( ) <EOL> class GroupOwnerFilter ( GroupFilter ) : <EOL> base_filter = OwnerFilter <EOL> class GroupLastModifiedByFilter ( GroupFilter ) : <EOL> base_filter = LastModifiedByFilter <EOL> class GroupClosedByFilter ( GroupFilter ) : <EOL> base_filter = ClosedByFilter <EOL> class ReceivedOnRangeFilter ( RangeExportFilter ) : <EOL> def to_es_filter ( self ) : <EOL> return submitted ( self . gt , self . gte , self . lt , self . lte ) <EOL> class FormSubmittedByFilter ( ExportFilter ) : <EOL> def __init__ ( self , submitted_by ) : <EOL> self . submitted_by = submitted_by <EOL> def to_es_filter ( self ) : <EOL> return user_id ( self . submitted_by ) <EOL> class UserTypeFilter ( ExportFilter ) : <EOL> def __init__ ( self , user_types ) : <EOL> _assert_user_types ( user_types ) <EOL> self . user_types = user_types <EOL> def to_es_filter ( self ) : <EOL> return user_type ( self . user_types ) <EOL> class GroupFormSubmittedByFilter ( GroupFilter ) : <EOL> base_filter = FormSubmittedByFilter </s>
