forked from HumanSignal/label-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserializers.py
49 lines (35 loc) · 1.67 KB
/
serializers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
"""
import os
from io_storages.base_models import ExportStorage, ImportStorage
from rest_framework import serializers
from tasks.models import Task
from tasks.serializers import AnnotationSerializer, TaskSerializer
from users.models import User
class ImportStorageSerializer(serializers.ModelSerializer):
type = serializers.ReadOnlyField(default=os.path.basename(os.path.dirname(__file__)))
synchronizable = serializers.BooleanField(required=False, default=True)
class Meta:
model = ImportStorage
fields = '__all__'
class ExportStorageSerializer(serializers.ModelSerializer):
type = serializers.ReadOnlyField(default=os.path.basename(os.path.dirname(__file__)))
synchronizable = serializers.BooleanField(required=False, default=True)
class Meta:
model = ExportStorage
fields = '__all__'
class StorageTaskSerializer(TaskSerializer):
def __init__(self, *args, **kwargs):
# task is nested into the annotation, we don't need annotations in the task again
kwargs['context'] = {'resolve_uri': False}
super().__init__(*args, **kwargs)
class Meta:
model = Task
fields = '__all__'
class StorageCompletedBySerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'first_name', 'last_name', 'email')
class StorageAnnotationSerializer(AnnotationSerializer):
task = StorageTaskSerializer(read_only=True, omit=['annotations'])
completed_by = StorageCompletedBySerializer(read_only=True)