Exemplo n.º 1
0
class PlayerScoreFilter(filters.SearchFilter):
    min_score = NumberFilter(field_name='score', lookup_expr='gte')
    max_score = NumberFilter(field_name='score', lookup_expr='lte')
    from_score_date = DateTimeFilter(field_name='score_date',
                                     lookup_expr='gte')
    to_scoreD_date = DateTimeFilter(field_name='scored_date',
                                    lookup_expr='lte')
    player_name = AllValuesFilter(field_name='player__name')
    game_name = AllValuesFilter(field_name='game__name')

    class Meta:
        model = PlayerScore
        fields = ('score', 'from_score_date', 'to_score_date', 'min_score',
                  'max_score', 'player_name', 'game_name')
Exemplo n.º 2
0
class ReportFilter(DojoFilter):
    name = CharFilter(lookup_type='icontains')
    type = MultipleChoiceFilter(choices=[])
    format = MultipleChoiceFilter(choices=[])
    requester = ModelMultipleChoiceFilter(queryset=Dojo_User.objects.all())
    datetime = DateTimeFilter()
    status = MultipleChoiceFilter(choices=[])

    class Meta:
        model = Report
        exclude = ['task_id', 'file']
        order_by = (('-datetime', 'Date Desc'), ('datetime', 'Date Asc'),
                    ('name', 'Name'), ('-name', 'Name Desc'), ('type', 'Type'),
                    ('-type', 'Type Desc'), ('format', 'Format'),
                    ('-format', 'Format Desc'), ('requester', 'Requester'),
                    ('-requester', 'Requester Desc'))

    def __init__(self, *args, **kwargs):
        super(ReportFilter, self).__init__(*args, **kwargs)
        type = dict()
        type = dict([report.type, report.type]
                    for report in self.queryset.distinct()
                    if report.type is not None)
        type = collections.OrderedDict(sorted(type.items()))
        self.form.fields['type'].choices = type.items()

        status = dict()
        status = dict([report.status, report.status]
                      for report in self.queryset.distinct()
                      if report.status is not None)
        status = collections.OrderedDict(sorted(status.items()))
        self.form.fields['status'].choices = status.items()
Exemplo n.º 3
0
class ReportFilter(DojoFilter):
    name = CharFilter(lookup_expr='icontains')
    type = MultipleChoiceFilter(choices=[])
    format = MultipleChoiceFilter(choices=[])
    requester = ModelMultipleChoiceFilter(queryset=Dojo_User.objects.all())
    datetime = DateTimeFilter()
    status = MultipleChoiceFilter(choices=[])

    o = OrderingFilter(
        # tuple-mapping retains order
        fields=(
            ('datetime', 'datetime'),
            ('name', 'name'),
            ('type', 'type'),
            ('format', 'format'),
            ('requester', 'requester'),
        ),
        field_labels={
            'datetime': 'Date',
        }

    )

    class Meta:
        model = Report
        exclude = ['task_id', 'file']

    def __init__(self, *args, **kwargs):
        super(ReportFilter, self).__init__(*args, **kwargs)
        type = dict()
        type = dict(
            [report.type, report.type] for report in self.queryset.distinct()
            if report.type is not None)
        type = collections.OrderedDict(sorted(type.items()))
        self.form.fields['type'].choices = list(type.items())

        status = dict()
        status = dict(
            [report.status, report.status] for report in
            self.queryset.distinct() if report.status is not None)
        status = collections.OrderedDict(sorted(status.items()))
        self.form.fields['status'].choices = list(status.items())
Exemplo n.º 4
0
 def test_default_field(self):
     f = DateTimeFilter()
     field = f.field
     self.assertIsInstance(field, forms.DateTimeField)
Exemplo n.º 5
0
        class F(FilterSet):
            published = DateTimeFilter(lookup_type=['gt', 'lt'])

            class Meta:
                model = Article
                fields = ['published']
Exemplo n.º 6
0
class DateRangeFilter(django_filters.FilterSet):
    max = DateTimeFilter(name='date', lookup_type='lte')
    min = DateTimeFilter(name='date', lookup_type='gte')