2020-05-08 16:29:18 +00:00
|
|
|
"""Flow API Views"""
|
2020-05-08 17:46:39 +00:00
|
|
|
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
|
|
|
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet
|
2020-05-08 16:29:18 +00:00
|
|
|
|
2020-05-08 17:46:39 +00:00
|
|
|
from passbook.flows.models import Flow, FlowStageBinding, Stage
|
2020-05-08 16:29:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FlowSerializer(ModelSerializer):
|
|
|
|
"""Flow Serializer"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = Flow
|
2020-05-08 17:46:39 +00:00
|
|
|
fields = ["pk", "name", "slug", "designation", "stages", "policies"]
|
2020-05-08 16:29:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FlowViewSet(ModelViewSet):
|
|
|
|
"""Flow Viewset"""
|
|
|
|
|
|
|
|
queryset = Flow.objects.all()
|
|
|
|
serializer_class = FlowSerializer
|
|
|
|
|
|
|
|
|
2020-05-08 17:46:39 +00:00
|
|
|
class FlowStageBindingSerializer(ModelSerializer):
|
|
|
|
"""FlowStageBinding Serializer"""
|
2020-05-08 16:29:18 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
2020-05-08 17:46:39 +00:00
|
|
|
model = FlowStageBinding
|
|
|
|
fields = ["pk", "flow", "stage", "re_evaluate_policies", "order", "policies"]
|
2020-05-08 16:29:18 +00:00
|
|
|
|
|
|
|
|
2020-05-08 17:46:39 +00:00
|
|
|
class FlowStageBindingViewSet(ModelViewSet):
|
|
|
|
"""FlowStageBinding Viewset"""
|
2020-05-08 16:29:18 +00:00
|
|
|
|
2020-05-08 17:46:39 +00:00
|
|
|
queryset = FlowStageBinding.objects.all()
|
|
|
|
serializer_class = FlowStageBindingSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class StageSerializer(ModelSerializer):
|
|
|
|
"""Stage Serializer"""
|
|
|
|
|
|
|
|
__type__ = SerializerMethodField(method_name="get_type")
|
|
|
|
|
|
|
|
def get_type(self, obj):
|
|
|
|
"""Get object type so that we know which API Endpoint to use to get the full object"""
|
|
|
|
return obj._meta.object_name.lower().replace("stage", "")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = Stage
|
|
|
|
fields = ["pk", "name", "__type__"]
|
|
|
|
|
|
|
|
|
|
|
|
class StageViewSet(ReadOnlyModelViewSet):
|
|
|
|
"""Stage Viewset"""
|
|
|
|
|
|
|
|
queryset = Stage.objects.all()
|
|
|
|
serializer_class = StageSerializer
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return Stage.objects.select_subclasses()
|