fix: swagger 500

pull/8970/head
feng 2022-10-18 10:43:51 +08:00
parent 4f16c1f92c
commit 1b795791de
2 changed files with 9 additions and 10 deletions

View File

@ -45,6 +45,9 @@ class AdHocExecution(BaseAnsibleExecution):
) )
return runner return runner
def task_display(self):
return str(self.task)
class Meta: class Meta:
db_table = "ops_adhoc_execution" db_table = "ops_adhoc_execution"
get_latest_by = 'date_start' get_latest_by = 'date_start'

View File

@ -15,11 +15,11 @@ class AdHocExecutionSerializer(serializers.ModelSerializer):
model = AdHocExecution model = AdHocExecution
fields_mini = ['id'] fields_mini = ['id']
fields_small = fields_mini + [ fields_small = fields_mini + [
'hosts_amount', 'timedelta', 'result', 'summary', 'short_id', 'timedelta', 'result', 'summary', 'short_id',
'is_finished', 'is_success', 'is_finished', 'is_success',
'date_start', 'date_finished', 'date_start', 'date_finished',
] ]
fields_fk = ['task', 'task_display', 'adhoc', 'adhoc_short_id',] fields_fk = ['task', 'task_display']
fields_custom = ['stat', 'last_success', 'last_failure'] fields_custom = ['stat', 'last_success', 'last_failure']
fields = fields_small + fields_fk + fields_custom fields = fields_small + fields_fk + fields_custom
@ -50,20 +50,16 @@ class AdHocExecutionExcludeResultSerializer(AdHocExecutionSerializer):
class AdHocSerializer(serializers.ModelSerializer): class AdHocSerializer(serializers.ModelSerializer):
become_display = serializers.ReadOnlyField()
tasks = serializers.ListField() tasks = serializers.ListField()
class Meta: class Meta:
model = AdHoc model = AdHoc
fields_mini = ['id'] fields_mini = ['id']
fields_small = fields_mini + [ fields_small = fields_mini + [
'tasks', "pattern", "options", "run_as", 'tasks', "pattern", "args", "date_created",
"become", "become_display", "short_id",
"run_as_admin",
"date_created",
] ]
fields_fk = ["task"] fields_fk = ["last_execution"]
fields_m2m = ["hosts"] fields_m2m = ["assets"]
fields = fields_small + fields_fk + fields_m2m fields = fields_small + fields_fk + fields_m2m
read_only_fields = [ read_only_fields = [
'date_created' 'date_created'
@ -92,7 +88,7 @@ class AdHocDetailSerializer(AdHocSerializer):
class Meta(AdHocSerializer.Meta): class Meta(AdHocSerializer.Meta):
fields = AdHocSerializer.Meta.fields + [ fields = AdHocSerializer.Meta.fields + [
'latest_execution', 'created_by', 'run_times', 'task_name' 'latest_execution', 'created_by', 'task_name'
] ]