# Path: hyperadmin/filters.py
# class BaseChoicesFilter(BaseFilter):
#     def get_links(self, **link_kwargs):
#         links = list()
#         for choice in self.choices():
#             kwargs = dict(link_kwargs)
#             classes = kwargs.get('classes', [])
#             kwargs['group'] = self.title
#             kwargs['classes'] = classes
#             if choice.get('selected', False):
#                 classes.append('selected')
#             #CONSIDER prompt may want to include group if not supported
#             kwargs['prompt'] = force_unicode(choice['display'])
#             kwargs['url'] = u'./' + choice['query_string']
#             links.append(self.make_link(**kwargs))
#         return links
#     
#     def choices(self):
#         return []
# 
# class BaseFilter(object):
#     title = None  # Human-readable title to appear in the right sidebar.
#     
#     def __init__(self, index):
#         self.index = index
#         self.resource = index.resource
#         if self.title is None:
#             raise ImproperlyConfigured(
#                 "The filter '%s' does not specify "
#                 "a 'title'." % self.__class__.__name__)
#     
#     @property
#     def state(self):
#         return self.resource.state
#     
#     def make_link(self, **kwargs):
#         return self.index.get_link(**kwargs)
#     
#     def populate_state(self):
#         pass
#     
#     def get_links(self, **link_kwargs):
#         """
#         Returns links representing the filterable actions.
#         """
#         return []
#     
#     def filter_index(self, active_index):
#         """
#         Returns the filtered queryset.
#         """
#         raise NotImplementedError
#     
#     def expected_parameters(self):
#         """
#         Returns the list of parameter names that are expected from the
#         request's query string and that will be used by this filter.
#         """
#         raise NotImplementedError
#     
#     def is_active(self):
#         return False
#     
#     def values(self):
#         vals = list()
#         filter_params = self.state.params
#         for param in self.expected_parameters():
#             vals.append(filter_params.get(param, None))
#         return vals


import datetime
import operator
    import pytz as timezone
from django.db import models
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
    from django.utils import timezone
from django.contrib.admin.util import (get_model_from_relation,
    reverse_field_path, get_limit_choices_to_from_path, )
    from django.contrib.admin.util import lookup_needs_distinct, prepare_lookup_value
    from hyperadmin.resources.models.util import lookup_needs_distinct, prepare_lookup_value
from hyperadmin.filters import BaseChoicesFilter, BaseFilter
        from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
        from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
        for title, param_dict in self.links:
            yield {
                'selected': self.date_params == param_dict,
                'query_string': self.state.get_query_string(
                                    param_dict, [self.field_generic]),
                'display': title,
            }

FieldFilter.register(
    lambda f: isinstance(f, models.DateField), DateFieldFilter)


# This should be registered last, because it's a last resort. For example,
# if a field is eligible to use the BooleanFieldFilter, that'd be much
# more appropriate, and the AllValuesFieldFilter won't get used for it.
class AllValuesFieldFilter(FieldFilter):
    def __init__(self, field, field_path, index):
        super(AllValuesFieldFilter, self).__init__(
            field, field_path, index)
        
        model = self.resource.model
        
        self.lookup_kwarg = field_path
        self.lookup_kwarg_isnull = '%s__isnull' % field_path
        parent_model, reverse_path = reverse_field_path(model, field_path)
        queryset = parent_model._default_manager.all()
        # optional feature: limit choices base on existing relationships
        # queryset = queryset.complex_filter(
        #    {'%s__isnull' % reverse_path: False})
        limit_choices_to = get_limit_choices_to_from_path(model, field_path)

# Path: hyperadmin/filters.py
# class BaseChoicesFilter(BaseFilter):
#     def get_links(self, **link_kwargs):
#         links = list()
#         for choice in self.choices():
#             kwargs = dict(link_kwargs)
#             classes = kwargs.get('classes', [])
#             kwargs['group'] = self.title
#             kwargs['classes'] = classes
#             if choice.get('selected', False):
#                 classes.append('selected')
#             #CONSIDER prompt may want to include group if not supported
#             kwargs['prompt'] = force_unicode(choice['display'])
#             kwargs['url'] = u'./' + choice['query_string']
#             links.append(self.make_link(**kwargs))
#         return links
#     
#     def choices(self):
#         return []
# 
# class BaseFilter(object):
#     title = None  # Human-readable title to appear in the right sidebar.
#     
#     def __init__(self, index):
#         self.index = index
#         self.resource = index.resource
#         if self.title is None:
#             raise ImproperlyConfigured(
#                 "The filter '%s' does not specify "
#                 "a 'title'." % self.__class__.__name__)
#     
#     @property
#     def state(self):
#         return self.resource.state
#     
#     def make_link(self, **kwargs):
#         return self.index.get_link(**kwargs)
#     
#     def populate_state(self):
#         pass
#     
#     def get_links(self, **link_kwargs):
#         """
#         Returns links representing the filterable actions.
#         """
#         return []
#     
#     def filter_index(self, active_index):
#         """
#         Returns the filtered queryset.
#         """
#         raise NotImplementedError
#     
#     def expected_parameters(self):
#         """
#         Returns the list of parameter names that are expected from the
#         request's query string and that will be used by this filter.
#         """
#         raise NotImplementedError
#     
#     def is_active(self):
#         return False
#     
#     def values(self):
#         vals = list()
#         filter_params = self.state.params
#         for param in self.expected_parameters():
#             vals.append(filter_params.get(param, None))
#         return vals


# Path: hyperadmin/resources/models/filters.py
import datetime
import operator
    import pytz as timezone
from django.db import models
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
    from django.utils import timezone
from django.contrib.admin.util import (get_model_from_relation,
    reverse_field_path, get_limit_choices_to_from_path, )
    from django.contrib.admin.util import lookup_needs_distinct, prepare_lookup_value
    from hyperadmin.resources.models.util import lookup_needs_distinct, prepare_lookup_value
from hyperadmin.filters import BaseChoicesFilter, BaseFilter
        from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
        from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE

        for title, param_dict in self.links:
            yield {
                'selected': self.date_params == param_dict,
                'query_string': self.state.get_query_string(
                                    param_dict, [self.field_generic]),
                'display': title,
            }

FieldFilter.register(
    lambda f: isinstance(f, models.DateField), DateFieldFilter)


# This should be registered last, because it's a last resort. For example,
# if a field is eligible to use the BooleanFieldFilter, that'd be much
# more appropriate, and the AllValuesFieldFilter won't get used for it.
class AllValuesFieldFilter(FieldFilter):
    def __init__(self, field, field_path, index):
        super(AllValuesFieldFilter, self).__init__(
            field, field_path, index)
        
        model = self.resource.model
        
        self.lookup_kwarg = field_path
        self.lookup_kwarg_isnull = '%s__isnull' % field_path
        parent_model, reverse_path = reverse_field_path(model, field_path)
        queryset = parent_model._default_manager.all()
        # optional feature: limit choices base on existing relationships
        # queryset = queryset.complex_filter(
        #    {'%s__isnull' % reverse_path: False})
        limit_choices_to = get_limit_choices_to_from_path(model, field_path)

        queryset = queryset.filter(limit_choices_to)