jumpserver/apps/ops/serializers/job.py

34 lines
988 B
Python
Raw Normal View History

2022-11-11 11:20:17 +00:00
from django.db import transaction
from rest_framework import serializers
from common.drf.fields import ReadableHiddenField
from ops.models import Job, JobExecution
_all_ = []
class JobSerializer(serializers.ModelSerializer):
owner = ReadableHiddenField(default=serializers.CurrentUserDefault())
class Meta:
model = Job
fields = [
"id", "name", "instant", "type", "module", "args", "playbook", "assets", "runas_policy", "runas", "owner",
"variables",
"timeout",
"chdir",
"comment",
2022-11-11 11:20:17 +00:00
"date_created",
"date_updated"
]
class JobExecutionSerializer(serializers.ModelSerializer):
class Meta:
model = JobExecution
read_only_fields = ["id", "task_id", "timedelta", "time_cost", 'is_finished', 'date_start', 'date_created',
'is_success', 'task_id', 'short_id']
fields = read_only_fields + [
"job"
]