예제 #1
0
class PolicySerializer(serializers.ModelSerializer):
    """Serializer for the policy model."""

    uuid = serializers.UUIDField(read_only=True)
    name = serializers.CharField(required=True, max_length=150)
    description = serializers.CharField(allow_null=True, required=False)
    group = GroupInputSerializer(required=True)
    roles = RoleMinimumSerializer(many=True, required=True)
    created = serializers.DateTimeField(read_only=True)
    modified = serializers.DateTimeField(read_only=True)

    class Meta:
        """Metadata for the serializer."""

        model = Policy
        fields = ('uuid', 'name', 'description',
                  'group', 'roles', 'created', 'modified')

    def to_representation(self, obj):
        """Convert representation to dictionary object."""
        group = GroupInputSerializer(obj.group)
        roles = []
        for role in obj.roles.all():
            serializer = RoleMinimumSerializer(role)
            roles.append(serializer.data)
        return {
            'uuid': obj.uuid,
            'name': obj.name,
            'description': obj.description,
            'group': group.data,
            'roles': roles,
            'created': obj.created,
            'modified': obj.modified
        }
예제 #2
0
class PolicySerializer(SerializerCreateOverrideMixin,
                       serializers.ModelSerializer):
    """Serializer for the policy model."""

    uuid = serializers.UUIDField(read_only=True)
    name = serializers.CharField(required=True, max_length=150)
    description = serializers.CharField(allow_null=True, required=False)
    group = GroupInputSerializer(required=True)
    roles = RoleMinimumSerializer(many=True, required=True)
    created = serializers.DateTimeField(read_only=True)
    modified = serializers.DateTimeField(read_only=True)

    class Meta:
        """Metadata for the serializer."""

        model = Policy
        fields = ("uuid", "name", "description", "group", "roles", "created",
                  "modified")

    def to_representation(self, obj):
        """Convert representation to dictionary object."""
        group = GroupInputSerializer(obj.group)
        roles = []
        for role in obj.roles.all():
            serializer = RoleMinimumSerializer(role)
            roles.append(serializer.data)
        return {
            "uuid": obj.uuid,
            "name": obj.name,
            "description": obj.description,
            "group": group.data,
            "roles": roles,
            "created": obj.created,
            "modified": obj.modified,
        }
예제 #3
0
 def to_representation(self, obj):
     """Convert representation to dictionary object."""
     group = GroupInputSerializer(obj.group)
     roles = []
     for role in obj.roles.all():
         serializer = RoleMinimumSerializer(role)
         roles.append(serializer.data)
     return {
         'uuid': obj.uuid,
         'name': obj.name,
         'description': obj.description,
         'group': group.data,
         'roles': roles,
         'created': obj.created,
         'modified': obj.modified
     }
예제 #4
0
 def to_representation(self, obj):
     """Convert representation to dictionary object."""
     group = GroupInputSerializer(obj.group)
     roles = []
     for role in obj.roles.all():
         serializer = RoleMinimumSerializer(role)
         roles.append(serializer.data)
     return {
         "uuid": obj.uuid,
         "name": obj.name,
         "description": obj.description,
         "group": group.data,
         "roles": roles,
         "created": obj.created,
         "modified": obj.modified,
     }