def build_filters(self, **filter_kwargs):
        """
        Returns a dictionary of Q objects that will be used to limit the 
        mapper querysets.

        This allows for translating arguments from upstream code to the
        filter format used by the underlying data store abstraction.

        This will build a set of filters common to all querysets and will call
        any build_filters_COLLECTION_NAME methods that have been implemented
        on this class.

        Arguments:

        * state: Required. Postal code for a state.  For example, "md".
        * datefilter: Date specified in "YYYY" or "YYYY-MM-DD" used to filter
          elections before they are baked.
        * election_type: Election type. For example, general, primary, etc. 
        * reporting_level: Reporting level of the election results.  For example, "state",
          "county", "precinct", etc. Value must be one of the options specified
          in openelex.models.Result.REPORTING_LEVEL_CHOICES.
          
        """
        # TODO: Implement filtering by office, district and party after the 
        # the data is standardized

        # By default, should filter to all state/contest-wide results for all 
        # races when no filters are specified.
        filters= {}
        q_kwargs = {}
        
        q_kwargs['state'] = filter_kwargs['state'].upper()

        try:
            q_kwargs['election_id__contains'] = filter_kwargs['election_type']
        except KeyError:
            pass

        common_q = Q(**q_kwargs)

        # Merge in the date filters
        try:
            common_q &= self.build_date_filters(filter_kwargs['datefilter'])
        except __HOLE__:
            pass

        for collection_name in self._querysets.keys():
            filters[collection_name] = common_q
            try:
                fn = getattr(self, 'build_filters_' + collection_name)
                collection_q = fn(**filter_kwargs) 
                if collection_q:
                    filters[collection_name] &= collection_q 
            except AttributeError:
                pass

        return filters
dataset/ETHPy150Open openelections/openelections-core/openelex/base/bake.py/Roller.build_filters