from abc import ABC from django.contrib.auth.models import User, Group from rest_framework import serializers from health_view.models import FolderPart, JustifiedKey, FolderPart_Name, FolderInfo class UserSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = User fields = ['url', 'username', 'email', 'groups'] class GroupSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Group fields = ['url', 'name'] class KeySerializer(serializers.Serializer): part = serializers.CharField() justified_name = serializers.CharField(max_length=100) key = serializers.CharField(max_length=260) def create(self, validated_data): part = FolderPart.objects.get(pk=validated_data.get("part_class")) justified_name = FolderPart.objects.get(pk=validated_data.get("part_class")) key = validated_data.get("part_key") JustifiedKey(part=part, justified_name=justified_name, key=key) return True def update(self, instance, validated_data): instance.part = FolderPart.objects.get(pk=validated_data.get("part_class")) instance.justified_name = FolderPart.objects.get(pk=validated_data.get("part_class")) instance.key = instance.part_context = validated_data.get("part_key") instance.save() return True class ContentSerializer(serializers.Serializer): part_class = serializers.CharField() folder_id = serializers.CharField() part_context = serializers.CharField() def update(self, instance, validated_data): instance.part_class = FolderPart_Name.objects.get(pk=validated_data.get("part_class")) instance.folder_id = FolderInfo.objects.get(pk=validated_data.get("folder_id")) instance.part_context = validated_data.get("part_context") instance.save() return instance class FolderPartSerializer(serializers.Serializer): part = serializers.CharField() justified_name = serializers.CharField() key = serializers.CharField() class FolderPartNameSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = FolderPart_Name() fields = ['part_name']