jumpserver/apps/ops/serializers/job.py

42 lines
1.7 KiB
Python
Raw Normal View History

2022-12-02 04:21:56 +00:00
from django.utils.translation import ugettext as _
2022-11-11 11:20:17 +00:00
from rest_framework import serializers
from common.drf.fields import ReadableHiddenField
2022-11-18 10:46:48 +00:00
from ops.mixin import PeriodTaskSerializerMixin
2022-11-11 11:20:17 +00:00
from ops.models import Job, JobExecution
class JobSerializer(serializers.ModelSerializer, PeriodTaskSerializerMixin):
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
2022-12-02 09:18:11 +00:00
run_after_save = serializers.BooleanField(label=_("Run after save"), read_only=True, default=False, required=False)
2022-11-11 11:20:17 +00:00
class Meta:
model = Job
2022-12-02 09:18:11 +00:00
read_only_fields = ["id", "date_last_run", "date_created", "date_updated", "average_time_cost",
"run_after_save"]
2022-11-18 10:46:48 +00:00
fields = read_only_fields + [
"name", "instant", "type", "module", "args", "playbook", "assets", "runas_policy", "runas", "creator",
"use_parameter_define",
2022-11-17 12:10:13 +00:00
"parameters_define",
"timeout",
"chdir",
"comment",
2022-11-18 10:46:48 +00:00
"summary",
2022-12-02 09:18:11 +00:00
"is_periodic", "interval", "crontab"
2022-11-11 11:20:17 +00:00
]
class JobExecutionSerializer(serializers.ModelSerializer):
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
job_type = serializers.ReadOnlyField(label=_("Job type"))
count = serializers.ReadOnlyField(label=_("Count"))
2022-11-11 11:20:17 +00:00
class Meta:
model = JobExecution
read_only_fields = ["id", "task_id", "timedelta", "count", "time_cost", 'is_finished', 'date_start',
'date_finished',
'date_created',
'is_success', 'task_id', 'short_id', 'job_type', 'creator']
2022-11-11 11:20:17 +00:00
fields = read_only_fields + [
2022-11-17 12:10:13 +00:00
"job", "parameters"
2022-11-11 11:20:17 +00:00
]