scheduling.py 5.08 KB
Newer Older
1 2 3 4
"""
This file contains the serializers (for the elsewhere defined data models)
"""

Jorrit Schaap's avatar
Jorrit Schaap committed
5 6 7
import logging
logger = logging.getLogger(__name__)

8 9
from rest_framework import serializers
from .. import models
10
from .specification import RelationalHyperlinkedModelSerializer
11 12


13
class SubtaskConnectorSerializer(serializers.HyperlinkedModelSerializer):
14
    class Meta:
15
        model = models.SubtaskConnector
16 17 18
        fields = '__all__'


19
class SubtaskStateSerializer(serializers.ModelSerializer):
20
    class Meta:
21
        model = models.SubtaskState
22 23 24
        fields = '__all__'


25
class SubtaskTypeSerializer(serializers.ModelSerializer):
26
    class Meta:
27
        model = models.SubtaskType
28 29 30
        fields = '__all__'


31
class StationTypeSerializer(serializers.ModelSerializer):
32
    class Meta:
33
        model = models.StationType
34 35 36
        fields = '__all__'


37 38 39 40 41 42 43 44 45 46 47 48
class AlgorithmSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Algorithm
        fields = '__all__'


class ScheduleMethodSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.ScheduleMethod
        fields = '__all__'


49
class SubtaskTemplateSerializer(serializers.HyperlinkedModelSerializer):
50
    class Meta:
51
        model = models.SubtaskTemplate
52 53 54
        fields = '__all__'


55
class DefaultSubtaskTemplateSerializer(serializers.HyperlinkedModelSerializer):
56
    class Meta:
57
        model = models.DefaultSubtaskTemplate
58 59 60
        fields = '__all__'


61 62 63 64 65 66 67 68 69 70 71 72 73
class DataproductSpecificationsTemplateSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.DataproductSpecificationsTemplate
        fields = '__all__'


class DefaultDataproductSpecificationsTemplateSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.DefaultDataproductSpecificationsTemplate
        fields = '__all__'


class SubtaskInputSelectionTemplateSerializer(serializers.HyperlinkedModelSerializer):
74
    class Meta:
75
        model = models.SubtaskInputSelectionTemplate
76 77 78
        fields = '__all__'


79
class DataproductFeedbackTemplateSerializer(serializers.HyperlinkedModelSerializer):
80
    class Meta:
81
        model = models.DataproductFeedbackTemplate
82 83 84
        fields = '__all__'


85
class SubtaskSerializer(serializers.HyperlinkedModelSerializer):
86
    class Meta:
87
        model = models.Subtask
88 89 90
        fields = '__all__'


91
class SubtaskInputSerializer(serializers.HyperlinkedModelSerializer):
92
    class Meta:
93 94 95 96 97 98 99
        model = models.SubtaskInput
        fields = '__all__'


class SubtaskOutputSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.SubtaskOutput
100 101 102 103 104 105 106 107 108 109 110 111 112
        fields = '__all__'


class DataproductSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.Dataproduct
        fields = '__all__'


class AntennaSetSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.AntennaSet
        fields = '__all__'
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142


class DataproductTransformSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.DataproductTransform
        fields = '__all__'


class FilesystemSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.Filesystem
        fields = '__all__'


class ClusterSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.Cluster
        fields = '__all__'


class DataproductArchiveInfoSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.DataproductArchiveInfo
        fields = '__all__'


class DataproductHashSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.DataproductHash
        fields = '__all__'
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159


class SubtaskSerializerJSONeditorOnline(RelationalHyperlinkedModelSerializer):

    # Create a JSON editor form to replace the simple text field based on the schema in the template that this
    # draft refers to. If that fails, the JSONField remains a standard text input.
    #
    # Note: I feel a bit uneasy with this since I feel there should be a more straight-forward solution tham
    #  ...intercepting the init process to determine the schema (or template uri or so) for the style attribute.
    #  ...Hoewever, I did not manage to simply pass the value(!) of e.g. the template field as a style attribute
    #  ...of the JSONField via a SerializerMethodField or similar, although I feel that should be possible.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        import json

        try:
160 161 162 163 164
            if isinstance(self.instance, models.Subtask):
                schema = self.instance.specifications_template.schema
                self.fields['specifications_doc'] = serializers.JSONField(
                    style={'template': 'josdejong_jsoneditor_widget.html',
                           'schema': json.dumps(schema)})
Jorrit Schaap's avatar
Jorrit Schaap committed
165
        except Exception as e:
166
            # todo: Shall we use one of the default templates for the init?
Jorrit Schaap's avatar
Jorrit Schaap committed
167
            logger.exception('Could not determine schema, hence no fancy JSON form. Expected for list view.')
168 169 170 171

    class Meta:
        model = models.Subtask
        fields = '__all__'