Digital Rights Management für elektronische Patientenakten
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serializers.py 2.2KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from abc import ABC
  2. from django.contrib.auth.models import User, Group
  3. from rest_framework import serializers
  4. from health_view.models import FolderPart, JustifiedKey, FolderPart_Name, FolderInfo
  5. class UserSerializer(serializers.HyperlinkedModelSerializer):
  6. class Meta:
  7. model = User
  8. fields = ['url', 'username', 'email', 'groups']
  9. class GroupSerializer(serializers.HyperlinkedModelSerializer):
  10. class Meta:
  11. model = Group
  12. fields = ['url', 'name']
  13. class KeySerializer(serializers.Serializer):
  14. part = serializers.CharField()
  15. justified_name = serializers.CharField(max_length=100)
  16. key = serializers.CharField(max_length=260)
  17. def create(self, validated_data):
  18. part = FolderPart.objects.get(pk=validated_data.get("part_class"))
  19. justified_name = FolderPart.objects.get(pk=validated_data.get("part_class"))
  20. key = validated_data.get("part_key")
  21. JustifiedKey(part=part, justified_name=justified_name, key=key)
  22. return True
  23. def update(self, instance, validated_data):
  24. instance.part = FolderPart.objects.get(pk=validated_data.get("part_class"))
  25. instance.justified_name = FolderPart.objects.get(pk=validated_data.get("part_class"))
  26. instance.key = instance.part_context = validated_data.get("part_key")
  27. instance.save()
  28. return True
  29. class ContentSerializer(serializers.Serializer):
  30. part_class = serializers.CharField()
  31. folder_id = serializers.CharField()
  32. part_context = serializers.CharField()
  33. def update(self, instance, validated_data):
  34. instance.part_class = FolderPart_Name.objects.get(pk=validated_data.get("part_class"))
  35. instance.folder_id = FolderInfo.objects.get(pk=validated_data.get("folder_id"))
  36. instance.part_context = validated_data.get("part_context")
  37. instance.save()
  38. return instance
  39. class FolderPartSerializer(serializers.Serializer):
  40. part = serializers.CharField()
  41. justified_name = serializers.CharField()
  42. key = serializers.CharField()
  43. class FolderPartNameSerializer(serializers.HyperlinkedModelSerializer):
  44. class Meta:
  45. model = FolderPart_Name()
  46. fields = ['part_name']