def test_filter_with_none(self): """ filter should not call filter on the queryset if None is passed as the value. """ mdrf = MyDateRangeFilter() qs = Mock() value = None mdrf.filter(qs, value) ok_(not qs.filter.called)
def test_filter_with_start(self): """ filter should apply a range test using the start value and the current date if only a start is passed. """ mdrf = MyDateRangeFilter() mdrf.name = 'test_field' qs = Mock() value = slice(1, None) with patch('oneanddone.base.filters.timezone.now') as now: now.return_value = aware_datetime(2013, 12, 1) mdrf.filter(qs, value) qs.filter.assert_called_with(test_field__range=(1, now.return_value))
def test_filter_with_end(self): """ filter should apply a range test using 2013, 1, 1 and the stop value if only a stop is passed. """ mdrf = MyDateRangeFilter() mdrf.name = 'test_field' qs = Mock() value = slice(None, 2) mdrf.filter(qs, value) qs.filter.assert_called_with( test_field__range=( timezone.make_aware(datetime(2013, 1, 1), timezone.utc), 2))
class ActivityFilterSet(django_filters.FilterSet): task__owner = django_filters.ModelChoiceFilter( label=_lazy(u'Task Owner'), queryset=User.objects.filter(is_staff=True).order_by('profile__name')) task__team = django_filters.ModelChoiceFilter( label=_lazy(u'Team'), queryset=TaskTeam.objects.all()) user = MultiFieldFilter( ['user__profile__name', 'user__profile__username', 'user__email'], label=_lazy(u'Task User')) modified = MyDateRangeFilter(label=_lazy(u'Date')) class Meta: model = TaskAttempt fields = ('task__owner', 'task__team', 'user', 'modified')
class ActivityFilterSet(django_filters.FilterSet): task__creator = django_filters.ModelChoiceFilter( label=_lazy(u'Task Owner'), queryset=User.objects.filter(task__isnull=False).distinct()) task__team = django_filters.ModelChoiceFilter( label=_lazy(u'Team'), queryset=TaskTeam.objects.all()) user = MultiFieldFilter( ['user__profile__name', 'user__profile__username', 'user__email'], label=_lazy(u'Task User') ) modified = MyDateRangeFilter( label=_lazy(u'Date') ) class Meta: model = TaskAttempt fields = ('task__creator', 'task__team', 'user', 'modified')