2021-10-31 13:13:38 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from core import models
|
2022-04-16 01:44:25 +00:00
|
|
|
from django_filters import rest_framework as filters
|
2021-10-31 13:13:38 +00:00
|
|
|
|
|
|
|
|
2022-04-04 02:23:35 +00:00
|
|
|
class CharInFilter(filters.BaseInFilter, filters.CharFilter):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-11-19 16:14:24 +00:00
|
|
|
class ChildFieldFilter(filters.FilterSet):
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = ["child"]
|
2021-11-19 16:14:24 +00:00
|
|
|
|
|
|
|
|
2022-04-04 02:23:35 +00:00
|
|
|
class TagsFieldFilter(filters.FilterSet):
|
|
|
|
tags = CharInFilter(
|
|
|
|
field_name="tags__name",
|
|
|
|
label="tag",
|
|
|
|
help_text="A list of tag names, comma separated",
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
2021-11-19 16:14:24 +00:00
|
|
|
class TimeFieldFilter(ChildFieldFilter):
|
2022-04-16 01:44:25 +00:00
|
|
|
date = filters.IsoDateTimeFilter(field_name="time", label="DateTime")
|
|
|
|
date_max = filters.IsoDateTimeFilter(
|
|
|
|
field_name="time", label="Max. DateTime", lookup_expr="lte"
|
2022-02-10 00:00:30 +00:00
|
|
|
)
|
2022-04-16 01:44:25 +00:00
|
|
|
date_min = filters.IsoDateTimeFilter(
|
|
|
|
field_name="time", label="Min. DateTime", lookup_expr="gte"
|
2022-02-10 00:00:30 +00:00
|
|
|
)
|
2021-11-19 16:14:24 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2022-02-10 00:00:30 +00:00
|
|
|
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):
|
2022-04-16 01:44:25 +00:00
|
|
|
end = filters.IsoDateTimeFilter(field_name="end", label="End DateTime")
|
|
|
|
end_max = filters.IsoDateTimeFilter(
|
|
|
|
field_name="end", label="Max. End DateTime", lookup_expr="lte"
|
2022-02-10 00:00:30 +00:00
|
|
|
)
|
2022-04-16 01:44:25 +00:00
|
|
|
end_min = filters.IsoDateTimeFilter(
|
|
|
|
field_name="end", label="Min. End DateTime", lookup_expr="gte"
|
2022-02-10 00:00:30 +00:00
|
|
|
)
|
2022-04-16 01:44:25 +00:00
|
|
|
start = filters.IsoDateTimeFilter(field_name="start", label="Start DateTime")
|
|
|
|
start_max = filters.IsoDateTimeFilter(
|
|
|
|
field_name="start", lookup_expr="lte", label="Max. End DateTime"
|
2022-02-10 00:00:30 +00:00
|
|
|
)
|
2022-04-16 01:44:25 +00:00
|
|
|
start_min = filters.IsoDateTimeFilter(
|
|
|
|
field_name="start", lookup_expr="gte", label="Min. Start DateTime"
|
2022-02-10 00:00:30 +00:00
|
|
|
)
|
2021-11-19 16:14:24 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = sorted(
|
|
|
|
ChildFieldFilter.Meta.fields
|
|
|
|
+ ["end", "end_max", "end_min", "start", "start_max", "start_min"]
|
|
|
|
)
|
2021-10-31 13:34:45 +00:00
|
|
|
|
|
|
|
|
2022-04-04 02:23:35 +00:00
|
|
|
class DiaperChangeFilter(TimeFieldFilter, TagsFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(TimeFieldFilter.Meta):
|
2021-10-31 13:13:38 +00:00
|
|
|
model = models.DiaperChange
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = sorted(
|
|
|
|
TimeFieldFilter.Meta.fields + ["wet", "solid", "color", "amount"]
|
|
|
|
)
|
2021-10-31 13:13:38 +00:00
|
|
|
|
|
|
|
|
2022-04-04 02:23:35 +00:00
|
|
|
class FeedingFilter(StartEndFieldFilter, TagsFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(StartEndFieldFilter.Meta):
|
2021-10-31 13:34:45 +00:00
|
|
|
model = models.Feeding
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = sorted(StartEndFieldFilter.Meta.fields + ["type", "method"])
|
2021-10-31 13:34:45 +00:00
|
|
|
|
|
|
|
|
2022-04-04 02:23:35 +00:00
|
|
|
class NoteFilter(TimeFieldFilter, TagsFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(TimeFieldFilter.Meta):
|
2021-10-31 13:13:38 +00:00
|
|
|
model = models.Note
|
|
|
|
|
|
|
|
|
2023-07-02 16:18:14 +00:00
|
|
|
class PumpingFilter(StartEndFieldFilter):
|
|
|
|
class Meta(StartEndFieldFilter.Meta):
|
2022-05-27 22:39:25 +00:00
|
|
|
model = models.Pumping
|
|
|
|
|
|
|
|
|
2022-04-04 02:23:35 +00:00
|
|
|
class SleepFilter(StartEndFieldFilter, TagsFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(StartEndFieldFilter.Meta):
|
2021-10-31 13:34:45 +00:00
|
|
|
model = models.Sleep
|
|
|
|
|
|
|
|
|
2022-04-04 02:23:35 +00:00
|
|
|
class TemperatureFilter(TimeFieldFilter, TagsFieldFilter):
|
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
|
2022-08-14 20:55:57 +00:00
|
|
|
fields = sorted(StartEndFieldFilter.Meta.fields + ["user"])
|
2021-10-31 13:34:45 +00:00
|
|
|
|
|
|
|
|
2022-04-04 02:23:35 +00:00
|
|
|
class TummyTimeFilter(StartEndFieldFilter, TagsFieldFilter):
|
2021-11-19 16:14:24 +00:00
|
|
|
class Meta(StartEndFieldFilter.Meta):
|
2021-10-31 13:34:45 +00:00
|
|
|
model = models.TummyTime
|