mirror of https://github.com/snachodog/mybuddy.git
Add "timer" field information to OPTIONS (#131)
This commit is contained in:
parent
3071050881
commit
7276dc331a
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
|
||||||
|
class TimerFieldSupportMixin:
|
||||||
|
def options(self, request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Add information about the optional "timer" field.
|
||||||
|
"""
|
||||||
|
meta = self.metadata_class()
|
||||||
|
data = meta.determine_metadata(request, self)
|
||||||
|
post = data.get('actions').get('POST') # type: OrderedDict
|
||||||
|
post['timer'] = OrderedDict({
|
||||||
|
"type": "integer",
|
||||||
|
"required": False,
|
||||||
|
"read_only": False,
|
||||||
|
"label": "Timer",
|
||||||
|
"details": "ID for an existing Timer, may be used in place of the "
|
||||||
|
"`start`, `end`, and/or `child` fields. "
|
||||||
|
})
|
||||||
|
details = "Required unless a value is provided in the `timer` field."
|
||||||
|
post['child']['details'] = details
|
||||||
|
post['start']['details'] = details
|
||||||
|
post['end']['details'] = details
|
||||||
|
return Response(data)
|
|
@ -4,6 +4,7 @@ from rest_framework import viewsets
|
||||||
from core import models
|
from core import models
|
||||||
|
|
||||||
from . import serializers
|
from . import serializers
|
||||||
|
from .mixins import TimerFieldSupportMixin
|
||||||
|
|
||||||
|
|
||||||
class ChildViewSet(viewsets.ModelViewSet):
|
class ChildViewSet(viewsets.ModelViewSet):
|
||||||
|
@ -19,7 +20,7 @@ class DiaperChangeViewSet(viewsets.ModelViewSet):
|
||||||
filterset_fields = ('child', 'wet', 'solid', 'color', 'amount')
|
filterset_fields = ('child', 'wet', 'solid', 'color', 'amount')
|
||||||
|
|
||||||
|
|
||||||
class FeedingViewSet(viewsets.ModelViewSet):
|
class FeedingViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
|
||||||
queryset = models.Feeding.objects.all()
|
queryset = models.Feeding.objects.all()
|
||||||
serializer_class = serializers.FeedingSerializer
|
serializer_class = serializers.FeedingSerializer
|
||||||
filterset_fields = ('child', 'type', 'method')
|
filterset_fields = ('child', 'type', 'method')
|
||||||
|
@ -31,7 +32,7 @@ class NoteViewSet(viewsets.ModelViewSet):
|
||||||
filterset_fields = ('child',)
|
filterset_fields = ('child',)
|
||||||
|
|
||||||
|
|
||||||
class SleepViewSet(viewsets.ModelViewSet):
|
class SleepViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
|
||||||
queryset = models.Sleep.objects.all()
|
queryset = models.Sleep.objects.all()
|
||||||
serializer_class = serializers.SleepSerializer
|
serializer_class = serializers.SleepSerializer
|
||||||
filterset_fields = ('child',)
|
filterset_fields = ('child',)
|
||||||
|
@ -49,7 +50,7 @@ class TimerViewSet(viewsets.ModelViewSet):
|
||||||
filterset_fields = ('child', 'active', 'user')
|
filterset_fields = ('child', 'active', 'user')
|
||||||
|
|
||||||
|
|
||||||
class TummyTimeViewSet(viewsets.ModelViewSet):
|
class TummyTimeViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
|
||||||
queryset = models.TummyTime.objects.all()
|
queryset = models.TummyTime.objects.all()
|
||||||
serializer_class = serializers.TummyTimeSerializer
|
serializer_class = serializers.TummyTimeSerializer
|
||||||
filterset_fields = ('child',)
|
filterset_fields = ('child',)
|
||||||
|
|
Loading…
Reference in New Issue