Пример #1
0
class ContractFilter(django_filters.FilterSet):
    total_price__gte = django_filters.NumberFilter(field_name='total_price',
                                                   lookup_expr='gte')
    total_price__lte = django_filters.NumberFilter(field_name='total_price',
                                                   lookup_expr='lte')
    created_at_time__gte = django_filters.TimeFilter(
        widget=forms.TimeInput(format='%H:%M', attrs={'class': 'timepicker'}),
        field_name='created_at_time',
        lookup_expr='gte')
    created_at_time__lte = django_filters.TimeFilter(
        widget=forms.TimeInput(format='%H:%M', attrs={'class': 'timepicker'}),
        field_name='created_at_time',
        lookup_expr='lte')
    numbers__gte = django_filters.NumberFilter(field_name='numbers',
                                               lookup_expr='gte')
    numbers__lte = django_filters.NumberFilter(field_name='numbers',
                                               lookup_expr='lte')
    str_created_at_date = django_filters.CharFilter(
        widget=forms.TextInput(attrs={'class': 'mp-datepicker'}),
        field_name='str_created_at_date')

    class Meta:
        model = ContractModel
        fields = [
            'str_created_at_date',
        ]
Пример #2
0
class TransporteFilter(django_filters.FilterSet):
    tipo_transporte = django_filters.CharFilter(field_name="tipo_transporte",
                                                lookup_expr="icontains")
    origem = django_filters.CharFilter(field_name="rota__origem",
                                       lookup_expr="icontains",
                                       distinct=True)
    destino = django_filters.CharFilter(field_name="rota__destino",
                                        lookup_expr="icontains",
                                        distinct=True)
    hora_gte = django_filters.TimeFilter(
        field_name="rota__horarioid__hora_de_partida",
        lookup_expr="gte",
        distinct=True)
    hora_lte = django_filters.TimeFilter(
        field_name="rota__horarioid__hora_de_chegada",
        lookup_expr="lte",
        distinct=True)
    data = django_filters.DateFilter(field_name="rota__data", distinct=True)

    class Meta:
        model = Transporte
        fields = [
            'tipo_transporte', 'rota__origem', 'rota__destino',
            'rota__horarioid__hora_de_partida',
            'rota__horarioid__hora_de_chegada', 'rota__data'
        ]
Пример #3
0
class ServiceFilter(django_filters.FilterSet):
    start_gte = django_filters.TimeFilter('time_start', lookup_expr='gte')
    start_lte = django_filters.TimeFilter('time_start', lookup_expr='lte')

    class Meta:
        model = ServiceModel
        fields = ('name', 'time_start', 'time_end')
Пример #4
0
class MeetingFilter(filters.FilterSet):
    start_date__lt = django_filters.DateFilter(name="start_date",
                                               lookup_expr='lt')
    start_date__lte = django_filters.DateFilter(name="start_date",
                                                lookup_expr='lte')
    start_date__gt = django_filters.DateFilter(name="start_date",
                                               lookup_expr='gt')
    start_date__gte = django_filters.DateFilter(name="start_date",
                                                lookup_expr='gte')

    start_time__lt = django_filters.TimeFilter(name="start_time",
                                               lookup_expr='lt')
    start_time__lte = django_filters.TimeFilter(name="start_time",
                                                lookup_expr='lte')
    start_time__gt = django_filters.TimeFilter(name="start_time",
                                               lookup_expr='gt')
    start_time__gte = django_filters.TimeFilter(name="start_time",
                                                lookup_expr='gte')

    class Meta:
        model = Meeting
        fields = ('name', 'location', 'description', 'start_date',
                  'start_time', 'duration_minutes', 'course', 'creator',
                  'members', 'start_date__lt', 'start_date__lte',
                  'start_date__gt', 'start_date__gte', 'start_time__lt',
                  'start_time__lte', 'start_time__gt', 'start_time__gte')
Пример #5
0
class SessionFilter(django_filters.FilterSet):
    price__gte = django_filters.NumberFilter(field_name='price',
                                             lookup_expr='gte')
    price__lte = django_filters.NumberFilter(field_name='price',
                                             lookup_expr='lte')
    time__gte = django_filters.TimeFilter(widget=forms.TimeInput(
        format='%H:%M', attrs={'class': 'timepicker'}),
                                          field_name='time',
                                          lookup_expr='gte')
    time__lte = django_filters.TimeFilter(widget=forms.TimeInput(
        format='%H:%M', attrs={'class': 'timepicker'}),
                                          field_name='time',
                                          lookup_expr='lte')
    discount_percentage__gte = django_filters.NumberFilter(
        field_name='discount_percentage', lookup_expr='gte')
    discount_percentage__lte = django_filters.NumberFilter(
        field_name='discount_percentage', lookup_expr='lte')
    day_str = django_filters.CharFilter(
        widget=forms.TextInput(attrs={'class': 'mp-datepicker'}),
        field_name='day_str')
    duration = django_filters.TimeFilter(
        widget=forms.TimeInput(format='%H:%M', attrs={'class': 'timepicker'}),
        field_name='duration',
    )

    class Meta:
        model = SessionModel
        fields = [
            'is_booked',
            'is_ready',
        ]
Пример #6
0
class ClassTimeFilter(django_filters.FilterSet):
    lesson_start__qte = django_filters.TimeFilter(name="lesson_start", lookup_expr="gte")
    lesson_end__lte = django_filters.TimeFilter(name="lesson_end", lookup_expr="lte")

    class Meta:
        model = ClassTime
        fields = ["lesson_start__qte", "lesson_end__lte"]
Пример #7
0
class TrackerFilter(django_filters.FilterSet):
    calories = django_filters.NumberFilter(field_name='calories',
                                           lookup_expr='exact')
    calories__gte = django_filters.NumberFilter(field_name='calories',
                                                lookup_expr='gte')
    calories__lte = django_filters.NumberFilter(field_name='calories',
                                                lookup_expr='lte')
    calories__ne = django_filters.CharFilter(method='not_equal_filter')
    user = django_filters.NumberFilter(field_name='user', lookup_expr='exact')
    id = django_filters.NumberFilter(field_name='id', lookup_expr='exact')
    text = django_filters.CharFilter(field_name='text', lookup_expr='exact')
    less_than_calories_per_day = django_filters.BooleanFilter(
        field_name='less_than_calories_per_day', lookup_expr='exact')
    time__gte = django_filters.TimeFilter(field_name='time', lookup_expr='gte')
    time__lte = django_filters.TimeFilter(field_name='time', lookup_expr='lte')
    time = django_filters.TimeFilter(field_name='time', lookup_expr='exact')
    date__gte = django_filters.DateFilter(field_name='date', lookup_expr='gte')
    date__lte = django_filters.DateFilter(field_name='date', lookup_expr='lte')
    date = django_filters.DateFilter(field_name='date', lookup_expr='exact')

    def not_equal_filter(self, queryset, name, value):
        field = name.split("__")[0]
        kwargs = {}
        kwargs[str(field)] = value
        return queryset.filter(~Q(**kwargs))

    class Meta:
        model = TrackerEntry
        fields = [
            'calories', 'user', 'id', 'text', 'date', 'time',
            'less_than_calories_per_day'
        ]
Пример #8
0
class HorarioTransporteFilter(django_filters.FilterSet):
    hora_de_partida = django_filters.TimeFilter(field_name="hora_de_partida",
                                                lookup_expr="gte")
    hora_de_chegada = django_filters.TimeFilter(field_name="hora_de_chegada",
                                                lookup_expr="lte")

    class Meta:
        model = HorarioTransporte
        fields = ['hora_de_partida', 'hora_de_chegada']
Пример #9
0
class ReckoningFilter(django_filters.FilterSet):
    money_transfered__gte = django_filters.NumberFilter(field_name='money_transfered', lookup_expr='gte')
    money_transfered__lte = django_filters.NumberFilter(field_name='money_transfered', lookup_expr='lte')
    transfered_at_time__gte = django_filters.TimeFilter(widget=forms.TimeInput(format='%H:%M',attrs={'class':'timepicker'}),field_name='transfered_at_time', lookup_expr='gte')
    transfered_at_time__lte = django_filters.TimeFilter(widget=forms.TimeInput(format='%H:%M',attrs={'class':'timepicker'}),field_name='transfered_at_time', lookup_expr='lte')
    str_transfered_at_date = django_filters.CharFilter(widget=forms.TextInput(attrs={'class':'mp-datepicker'}),field_name='str_transfered_at_date')

    class Meta:
        model = ReckoningModel
        fields = ['str_transfered_at_date',]
Пример #10
0
class BusFilter(django_filters.FilterSet):
    departure_railway = django_filters.CharFilter(lookup_expr='icontains')
    destination_railway = django_filters.CharFilter(lookup_expr='icontains')
    departure_date_gt = django_filters.DateFilter(field_name='departure_date', lookup_expr='gt')
    departure_date_lt = django_filters.DateFilter(field_name='departure_date', lookup_expr='lt')
    departure_time_gt = django_filters.TimeFilter(field_name='departure_time', lookup_expr='gt')
    departure_time_lt = django_filters.TimeFilter(field_name='departure_time', lookup_expr='lt')

    class Meta:
        model = BusFlight
        fields = ['departure_railway', 'destination_railway', 'departure_date_gt', 'departure_date_lt',
                  'departure_time_gt', 'departure_time_lt']
Пример #11
0
class RideFilter(django_filters.FilterSet):
    
    startAddress = django_filters.CharFilter(lookup_expr='contains')
    endAddress = django_filters.CharFilter(lookup_expr='contains')
    rideTime = django_filters.TimeFilter(widget=forms.TimeInput(attrs={
        'type': 'time'
    }))
    # rideTime = django_filters.CharFilter(lookup_expr='contains')
    # rideDate = django_filters.CharFilter(lookup_expr='contains')
    rideDate = django_filters.DateFilter(widget=forms.DateInput(attrs={
        'type': 'date'
    }))
    class Meta:
        model = Ride
        fields =  [
                  'rideDate',
                  'rideTime',
                  # 'postedTime',
                  # 'rideStartLoc',
                  # 'rideEndLoc',
                  'startAddress',
                  'endAddress', #old: endAddress
                  # 'spacesAvailable',
                  # 'cost',
                  # 'driver'
                 ]
Пример #12
0
class RotaFilter(django_filters.FilterSet):
    origem = django_filters.CharFilter(field_name="origem",
                                       lookup_expr="icontains")
    destino = django_filters.CharFilter(field_name="destino",
                                        lookup_expr="icontains")
    data = django_filters.DateFilter(field_name="data")
    hora_gte = django_filters.TimeFilter(
        field_name="horarioid__hora_de_partida", lookup_expr="gte")
    hora_lte = django_filters.TimeFilter(
        field_name="horarioid__hora_de_chegada", lookup_expr="lte")

    class Meta:
        model = Rota
        fields = [
            'origem', 'destino', 'data', 'horarioid__hora_de_partida',
            'horarioid__hora_de_chegada'
        ]
Пример #13
0
class BookingFilter(django_filters.FilterSet):
    destination = django_filters.CharFilter(lookup_expr='iexact')
    pickup = django_filters.CharFilter(lookup_expr='iexact')
    date = django_filters.DateFilter(lookup_expr='iexact')
    time = django_filters.TimeFilter(lookup_expr='lt')

    class Meta:
        model = createbooking
        fields = ['destination', 'pickup', 'date', 'time']
Пример #14
0
class CineFilter(filters.FilterSet):
    name = filters.CharFilter(label='Cine', lookup_expr='icontains')
    movie__name = filters.CharFilter(label='Nombre de la pelicula',
                                     lookup_expr='icontains')
    movie__hour = filters.TimeFilter(label='Hora de la función',
                                     lookup_expr='icontains')

    class Meta:
        model = Cine
        fields = [
            'name',
            'movie__name',
            'movie__hour',
        ]
Пример #15
0
class SessionFilter(django_filters.FilterSet):
    price__gte = django_filters.NumberFilter(widget=forms.TextInput(
        attrs={
            "style":
            "direction:rtl; text-align:right; color:#d4af37; font-family: 'Lalezar', cursive;",
            'placeholder': 'قیمت سانس کمتر از (تومان)',
            'id': 'price__gte',
        }),
                                             field_name='price',
                                             lookup_expr='gte')
    price__lte = django_filters.NumberFilter(widget=forms.TextInput(
        attrs={
            "style":
            "direction:rtl; text-align:right; color:#d4af37; font-family: 'Lalezar', cursive;",
            'placeholder': 'قیمت سانس بیشتز از (تومان)',
            'id': 'price__lte',
        }),
                                             field_name='price',
                                             lookup_expr='lte')
    time__gte = django_filters.TimeFilter(widget=forms.TimeInput(
        format='%H:%M',
        attrs={
            "style":
            "direction:rtl; text-align:right; color:#d4af37; font-family: 'Lalezar', cursive;",
            'placeholder': 'ساعت شروع سانس بعد از',
            'id': 'time__gte',
            'class': 'timepicker'
        }),
                                          field_name='time',
                                          lookup_expr='gte')
    time__lte = django_filters.TimeFilter(widget=forms.TimeInput(
        format='%H:%M',
        attrs={
            "style":
            "direction:rtl; text-align:right; color:#d4af37; font-family: 'Lalezar', cursive;",
            'placeholder': 'ساعت شروع سانس قبل از',
            'id': 'time__lte',
            'class': 'timepicker'
        }),
                                          field_name='time',
                                          lookup_expr='lte')
    discount_percentage__gte = django_filters.NumberFilter(
        widget=forms.TextInput(
            attrs={
                "style":
                "direction:rtl; text-align:right; color:#d4af37; font-family: 'Lalezar', cursive;",
                'placeholder': 'درصد تخفیف کمتر از',
                'id': 'discount_percentage__gte',
            }),
        field_name='discount_percentage',
        lookup_expr='gte')
    discount_percentage__lte = django_filters.NumberFilter(
        widget=forms.TextInput(
            attrs={
                "style":
                "direction:rtl; text-align:right; color:#d4af37; font-family: 'Lalezar', cursive;",
                'placeholder': 'درصد تخفیف بیشتر از',
                'id': 'discount_percentage__lte',
            }),
        field_name='discount_percentage',
        lookup_expr='lte')
    day_str = django_filters.CharFilter(widget=forms.TextInput(
        attrs={
            "style":
            "direction:rtl; text-align:right; color:#d4af37; font-family: 'Lalezar', cursive;",
            'placeholder': 'روز سانس',
            'type': 'text',
            'id': 'exampleInput3',
            'data-mddatetimepicker': 'true',
            'data-englishnumber': 'true',
            'autocomplete': 'off'
        }),
                                        field_name='day_str')
    duration = django_filters.TimeFilter(
        widget=forms.TimeInput(
            format='%H:%M',
            attrs={
                "style":
                "direction:rtl; text-align:right; color:#d4af37; font-family: 'Lalezar', cursive;",
                'placeholder': 'طول سانس',
                'id': 'duration',
                'class': 'timepicker'
            }),
        field_name='duration',
    )

    class Meta:
        model = SessionModel
        fields = [
            'is_booked',
            'is_ready',
        ]
    def _django_filter_lookups_from_field(cls, field: Field) -> dict:
        data = {
            field.name + '__isnull': django_filters.BooleanFilter(field_name=field.name, lookup_expr='isnull')
        }

        if isinstance(field, (models.ForeignKey, models.OneToOneField)):
            data[field.name] = django_filters.ModelChoiceFilter(queryset=field.related_model.objects.all())

        # numerics
        if isinstance(field, (models.IntegerField, models.AutoField)):
            data[field.name] = django_filters.NumberFilter(field_name=field.name)
            data[field.name + '__gt'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='gt')
            data[field.name + '__gte'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='gte')
            data[field.name + '__lte'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='lte')
            data[field.name + '__lt'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='lt')

        # chars
        if isinstance(field, (models.CharField, models.TextField)):
            data[field.name] = django_filters.CharFilter(field_name=field.name, lookup_expr='iexact')
            data[field.name + '__search'] = django_filters.CharFilter(field_name=field.name, lookup_expr='icontains')
            data[field.name + '__in'] = django_filters.CharFilter(field_name=field.name, lookup_expr='in')
            data[field.name + '__startswith'] = django_filters.CharFilter(field_name=field.name,
                                                                          lookup_expr='istartswith')
            data[field.name + '__endswith'] = django_filters.CharFilter(field_name=field.name, lookup_expr='iendswith')

            # data[field.name + '__regex'] = django_filters.CharFilter(field_name=field.name, lookup_expr='regex') todo

        # date
        # todo what the f**k with shamsi
        if isinstance(field, models.DateField):
            data[field.name] = django_filters.DateFilter(field_name=field.name)
            data[field.name + '__year'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='year')
            data[field.name + '__year__gt'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='year__gt')
            data[field.name + '__year__gte'] = django_filters.NumberFilter(field_name=field.name,
                                                                           lookup_expr='year__gte')
            data[field.name + '__year__lte'] = django_filters.NumberFilter(field_name=field.name,
                                                                           lookup_expr='year__lte')
            data[field.name + '__year__lt'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='year__lt')
            data[field.name + '__month'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='month')
            data[field.name + '__month__gt'] = django_filters.NumberFilter(field_name=field.name,
                                                                           lookup_expr='month__gt')
            data[field.name + '__month__gte'] = django_filters.NumberFilter(field_name=field.name,
                                                                            lookup_expr='month__gte')
            data[field.name + '__month__lte'] = django_filters.NumberFilter(field_name=field.name,
                                                                            lookup_expr='month__lte')
            data[field.name + '__month__lt'] = django_filters.NumberFilter(field_name=field.name,
                                                                           lookup_expr='month__lt')
            data[field.name + '__day'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='day')
            data[field.name + '__day__gt'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='day__gt')
            data[field.name + '__day__gte'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='day__gte')
            data[field.name + '__day__lte'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='day__lte')
            data[field.name + '__day__lt'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='day__lt')

        if isinstance(field, (models.TimeField, models.DateTimeField)):
            data[field.name] = django_filters.TimeFilter(field_name=field.name)
            data[field.name + '__hour'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='hour')
            data[field.name + '__hour__gt'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='hour__gt')
            data[field.name + '__hour__gte'] = django_filters.NumberFilter(field_name=field.name,
                                                                           lookup_expr='hour__gte')
            data[field.name + '__hour__lte'] = django_filters.NumberFilter(field_name=field.name,
                                                                           lookup_expr='hour__lte')
            data[field.name + '__hour__lt'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='hour__lt')
            data[field.name + '__minute'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='minute')
            data[field.name + '__minute__gt'] = django_filters.NumberFilter(field_name=field.name,
                                                                            lookup_expr='minute__gt')
            data[field.name + '__minute__gte'] = django_filters.NumberFilter(field_name=field.name,
                                                                             lookup_expr='minute__gte')
            data[field.name + '__minute__lte'] = django_filters.NumberFilter(field_name=field.name,
                                                                             lookup_expr='minute__lte')
            data[field.name + '__minute__lt'] = django_filters.NumberFilter(field_name=field.name,
                                                                            lookup_expr='minute__lt')
            data[field.name + '__second'] = django_filters.NumberFilter(field_name=field.name, lookup_expr='second')
            data[field.name + '__second__gt'] = django_filters.NumberFilter(field_name=field.name,
                                                                            lookup_expr='second__gt')
            data[field.name + '__second__gte'] = django_filters.NumberFilter(field_name=field.name,
                                                                             lookup_expr='second__gte')
            data[field.name + '__second__lte'] = django_filters.NumberFilter(field_name=field.name,
                                                                             lookup_expr='second__lte')
            data[field.name + '__second__lt'] = django_filters.NumberFilter(field_name=field.name,
                                                                            lookup_expr='second__lt')

        if isinstance(field, models.DateTimeField):
            data[field.name] = django_filters.IsoDateTimeFromToRangeFilter(field_name=field.name)

        return data