2021-10-31 13:13:38 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from django_filters import rest_framework as filters
|
|
|
|
from core import models
|
|
|
|
|
|
|
|
|
2021-11-19 16:14:24 +00:00
|
|
|
class ChildFieldFilter(filters.FilterSet):
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
fields = ['child']
|
|
|
|
|
|
|
|
|
|
|
|
class TimeFieldFilter(ChildFieldFilter):
|
2021-11-19 15:50:38 +00:00
|
|
|
date = filters.DateFilter(field_name='time__date', label='Date')
|
2021-10-31 13:13:38 +00:00
|
|
|
date_max = filters.DateFilter(field_name='time__date', label='Max. Date',
|
|
|
|
lookup_expr='lte')
|
2021-11-19 16:14:24 +00:00
|
|
|
date_min = filters.DateFilter(field_name='time__date', label='Min. Date',
|
|
|
|
lookup_expr='gte')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
fields = sorted(ChildFieldFilter.Meta.fields + [
|
|
|
|
'date',
|
|
|
|
'date_max',
|
|
|
|
'date_min'
|
|
|
|
])
|
2021-10-31 13:13:38 +00:00
|
|
|
|
|
|
|
|
2021-11-19 16:14:24 +00:00
|
|
|
class StartEndFieldFilter(ChildFieldFilter):
|
2021-10-31 13:34:45 +00:00
|
|
|
end = filters.DateFilter(field_name='end__date', label='End Date')
|
|
|
|
end_max = filters.DateFilter(field_name='end__date', label='Max. End Date',
|
|
|
|
lookup_expr='lte')
|
2021-11-19 16:14:24 +00:00
|
|
|
end_min = filters.DateFilter(field_name='end__date', label='Min. End Date',
|
|
|
|
lookup_expr='gte')
|
2021-10-31 13:34:45 +00:00
|
|
|
start = filters.DateFilter(field_name='start__date', label='Start Date')
|
2021-11-19 16:14:24 +00:00
|
|
|
start_max = filters.DateFilter(field_name='start__date', lookup_expr='lte',
|
2021-10-31 13:34:45 +00:00
|
|
|
label='Max. End Date')
|
2021-11-19 16:14:24 +00:00
|
|
|
start_min = filters.DateFilter(field_name='start__date', lookup_expr='gte',
|
|
|
|
label='Min. Start Date')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
fields = sorted(ChildFieldFilter.Meta.fields + [
|
|
|
|
'end',
|
|
|
|
'end_max',
|
|
|
|
'end_min',
|
|
|
|
'start',
|
|
|
|
'start_max',
|
|
|
|
'start_min'
|
|
|
|
])
|
2021-10-31 13:34:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DiaperChangeFilter(TimeFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(TimeFieldFilter.Meta):
|
2021-10-31 13:13:38 +00:00
|
|
|
model = models.DiaperChange
|
2021-11-19 16:14:24 +00:00
|
|
|
fields = sorted(TimeFieldFilter.Meta.fields + [
|
|
|
|
'wet',
|
|
|
|
'solid',
|
|
|
|
'color',
|
|
|
|
'amount'
|
|
|
|
])
|
2021-10-31 13:13:38 +00:00
|
|
|
|
|
|
|
|
2021-10-31 13:34:45 +00:00
|
|
|
class FeedingFilter(StartEndFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(StartEndFieldFilter.Meta):
|
2021-10-31 13:34:45 +00:00
|
|
|
model = models.Feeding
|
2021-11-19 16:14:24 +00:00
|
|
|
fields = sorted(StartEndFieldFilter.Meta.fields + ['type', 'method'])
|
2021-10-31 13:34:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NoteFilter(TimeFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(TimeFieldFilter.Meta):
|
2021-10-31 13:13:38 +00:00
|
|
|
model = models.Note
|
|
|
|
|
|
|
|
|
2021-10-31 13:34:45 +00:00
|
|
|
class SleepFilter(StartEndFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(StartEndFieldFilter.Meta):
|
2021-10-31 13:34:45 +00:00
|
|
|
model = models.Sleep
|
|
|
|
|
|
|
|
|
|
|
|
class TemperatureFilter(TimeFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(TimeFieldFilter.Meta):
|
2021-10-31 13:13:38 +00:00
|
|
|
model = models.Temperature
|
2021-10-31 13:34:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TimerFilter(StartEndFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(StartEndFieldFilter.Meta):
|
2021-10-31 13:34:45 +00:00
|
|
|
model = models.Timer
|
2021-11-19 16:14:24 +00:00
|
|
|
fields = sorted(StartEndFieldFilter.Meta.fields + ['active', 'user'])
|
2021-10-31 13:34:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TummyTimeFilter(StartEndFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(StartEndFieldFilter.Meta):
|
2021-10-31 13:34:45 +00:00
|
|
|
model = models.TummyTime
|