Exemplo n.º 1
0
class ScheduledJobSerializer(serializers.ModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name="extras-api:scheduledjob-detail")
    user = NestedUserSerializer(read_only=True)
    approved_by_user = NestedUserSerializer(read_only=True)

    class Meta:
        model = ScheduledJob
        fields = [
            "id",
            "url",
            "name",
            "user",
            "task",
            "interval",
            "queue",
            "job_class",
            "last_run_at",
            "total_run_count",
            "date_changed",
            "description",
            "user",
            "approved_by_user",
            "approval_required",
            "approved_at",
        ]
Exemplo n.º 2
0
class JobResultSerializer(serializers.ModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name="extras-api:jobresult-detail")
    user = NestedUserSerializer(read_only=True)
    status = ChoiceField(choices=JobResultStatusChoices, read_only=True)
    job_model = NestedJobSerializer(read_only=True)
    obj_type = ContentTypeField(read_only=True)
    schedule = NestedScheduledJobSerializer(read_only=True)

    class Meta:
        model = JobResult
        fields = [
            "id",
            "url",
            "created",
            "completed",
            "name",
            "job_model",
            "obj_type",
            "status",
            "user",
            "data",
            "job_id",
            "schedule",
        ]
Exemplo n.º 3
0
class NestedJobResultSerializer(serializers.ModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name="extras-api:jobresult-detail")
    status = ChoiceField(choices=choices.JobResultStatusChoices)
    user = NestedUserSerializer(read_only=True)

    class Meta:
        model = models.JobResult
        fields = ["url", "created", "completed", "user", "status"]
Exemplo n.º 4
0
class RackReservationSerializer(TaggedObjectSerializer, CustomFieldModelSerializer):
    url = serializers.HyperlinkedIdentityField(view_name="dcim-api:rackreservation-detail")
    rack = NestedRackSerializer()
    user = NestedUserSerializer()
    tenant = NestedTenantSerializer(required=False, allow_null=True)

    class Meta:
        model = RackReservation
        fields = [
            "id",
            "url",
            "rack",
            "units",
            "created",
            "user",
            "tenant",
            "description",
            "tags",
            "custom_fields",
        ]
Exemplo n.º 5
0
class ObjectChangeSerializer(serializers.ModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name="extras-api:objectchange-detail")
    user = NestedUserSerializer(read_only=True)
    action = ChoiceField(choices=ObjectChangeActionChoices, read_only=True)
    changed_object_type = ContentTypeField(read_only=True)
    changed_object = serializers.SerializerMethodField(read_only=True)

    class Meta:
        model = ObjectChange
        fields = [
            "id",
            "url",
            "time",
            "user",
            "user_name",
            "request_id",
            "action",
            "changed_object_type",
            "changed_object_id",
            "changed_object",
            "object_data",
        ]

    @swagger_serializer_method(serializer_or_field=serializers.DictField)
    def get_changed_object(self, obj):
        """
        Serialize a nested representation of the changed object.
        """
        if obj.changed_object is None:
            return None

        try:
            serializer = get_serializer_for_model(obj.changed_object,
                                                  prefix="Nested")
        except SerializerNotFound:
            return obj.object_repr
        context = {"request": self.context["request"]}
        data = serializer(obj.changed_object, context=context).data

        return data