2017-08-13 13:44:48 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from rest_framework import viewsets
|
|
|
|
|
2017-08-16 22:33:02 +00:00
|
|
|
from core.models import (Child, DiaperChange, Feeding, Note, Sleep, Timer,
|
|
|
|
TummyTime)
|
2017-08-13 20:26:52 +00:00
|
|
|
from core.utils import filter_by_params
|
2017-08-16 22:33:02 +00:00
|
|
|
|
2017-08-16 12:49:58 +00:00
|
|
|
from .serializers import (ChildSerializer, DiaperChangeSerializer,
|
2017-08-13 20:48:16 +00:00
|
|
|
FeedingSerializer, NoteSerializer, SleepSerializer,
|
2017-08-16 22:33:02 +00:00
|
|
|
TimerSerializer, TummyTimeSerializer,)
|
2017-08-13 14:48:16 +00:00
|
|
|
|
|
|
|
|
2017-08-16 12:49:58 +00:00
|
|
|
class ChildViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Child.objects.all()
|
|
|
|
serializer_class = ChildSerializer
|
2017-08-13 14:48:16 +00:00
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-13 20:26:52 +00:00
|
|
|
params = ['first_name', 'last_name']
|
2017-08-16 12:49:58 +00:00
|
|
|
return filter_by_params(self.request, Child, params)
|
2017-08-13 20:15:57 +00:00
|
|
|
|
2017-08-13 14:48:16 +00:00
|
|
|
|
2017-08-13 19:51:25 +00:00
|
|
|
class DiaperChangeViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = DiaperChange.objects.all()
|
|
|
|
serializer_class = DiaperChangeSerializer
|
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-17 16:17:51 +00:00
|
|
|
params = ['child__last_name', 'wet', 'solid', 'color']
|
2017-08-13 20:26:52 +00:00
|
|
|
return filter_by_params(self.request, DiaperChange, params)
|
2017-08-13 20:15:57 +00:00
|
|
|
|
2017-08-13 19:51:25 +00:00
|
|
|
|
2017-08-13 15:59:14 +00:00
|
|
|
class FeedingViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Feeding.objects.all()
|
|
|
|
serializer_class = FeedingSerializer
|
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-17 16:17:51 +00:00
|
|
|
params = ['child__last_name', 'type', 'method', 'amount']
|
2017-08-13 20:26:52 +00:00
|
|
|
return filter_by_params(self.request, Feeding, params)
|
2017-08-13 20:15:57 +00:00
|
|
|
|
2017-08-13 15:59:14 +00:00
|
|
|
|
2017-08-13 20:48:16 +00:00
|
|
|
class NoteViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Note.objects.all()
|
|
|
|
serializer_class = NoteSerializer
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2017-08-17 16:17:51 +00:00
|
|
|
params = ['child__last_name']
|
2017-08-13 20:48:16 +00:00
|
|
|
return filter_by_params(self.request, Note, params)
|
|
|
|
|
|
|
|
|
2017-08-13 14:48:16 +00:00
|
|
|
class SleepViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Sleep.objects.all()
|
|
|
|
serializer_class = SleepSerializer
|
2017-08-13 15:59:14 +00:00
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-17 16:17:51 +00:00
|
|
|
params = ['child__last_name']
|
2017-08-13 20:26:52 +00:00
|
|
|
return filter_by_params(self.request, Sleep, params)
|
2017-08-13 20:15:57 +00:00
|
|
|
|
2017-08-13 15:59:14 +00:00
|
|
|
|
2017-08-16 22:33:02 +00:00
|
|
|
class TimerViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Timer.objects.all()
|
|
|
|
serializer_class = TimerSerializer
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2017-08-17 18:42:44 +00:00
|
|
|
params = ['name', 'active', 'user']
|
2017-08-16 22:33:02 +00:00
|
|
|
return filter_by_params(self.request, Timer, params)
|
|
|
|
|
|
|
|
|
2017-08-13 19:05:44 +00:00
|
|
|
class TummyTimeViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = TummyTime.objects.all()
|
|
|
|
serializer_class = TummyTimeSerializer
|
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-17 16:17:51 +00:00
|
|
|
params = ['child__last_name']
|
2017-08-13 20:26:52 +00:00
|
|
|
return filter_by_params(self.request, TummyTime, params)
|