from rest_framework import serializers
from annotations.models import VogonUser
from models import *
from concepts.models import Concept, Type
[docs]class UserSerializer(serializers.ModelSerializer):
[docs]class RemoteCollectionSerializer(serializers.Serializer):
source = serializers.IntegerField()
id_or_uri = serializers.CharField(max_length=255)
name = serializers.CharField(max_length=255)
[docs]class RemoteResourceSerializer(serializers.Serializer):
source = serializers.IntegerField()
id_or_uri = serializers.CharField(max_length=255)
title = serializers.CharField(max_length=255)
[docs]class RepositorySerializer(serializers.ModelSerializer):
[docs]class RelationSerializer(serializers.ModelSerializer):
[docs]class AppellationSerializer(serializers.ModelSerializer):
[docs]class ConceptSerializer(serializers.ModelSerializer):
[docs]class TypeSerializer(serializers.ModelSerializer):
[docs]class RelationSetSerializer(serializers.ModelSerializer):
appellations = AppellationSerializer(many=True)
concepts = ConceptSerializer(many=True)
[docs]class TemporalBoundsSerializer(serializers.ModelSerializer):
[docs]class TextSerializer(serializers.ModelSerializer):
[docs] class Meta:
model = Text
fields = ('id', 'uri', 'title', 'created', 'added',
'addedBy', 'source', 'annotators', 'annotation_count')
[docs] def create(self, validated_data):
repository = Repository.objects.get(pk=validated_data['source'])
# TODO: Make retrieval/tokenization/other processing asynchronous.
tokenizedContent = tokenize(retrieve(repository, validated_data['uri']))
text = Text(uri=validated_data['uri'],
title=validated_data['title'],
source=repository,
addedBy=self.context['request'].user,
tokenizedContent=tokenizedContent)
text.save()
return HttpResponse(text.id)
[docs]class TextCollectionSerializer(serializers.ModelSerializer):
[docs] class Meta:
model = TextCollection