jumpserver/apps/ops/serializers/adhoc.py

23 lines
1009 B
Python
Raw Normal View History

# ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals
2024-09-06 09:41:09 +00:00
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
from common.serializers import WritableNestedModelSerializer
from common.serializers.fields import ReadableHiddenField
2024-09-06 09:41:09 +00:00
from common.serializers.mixin import CommonBulkModelSerializer
from .mixin import ScopeSerializerMixin
from ..models import AdHoc
from ops.serializers import AdhocVariableSerializer
class AdHocSerializer(ScopeSerializerMixin, CommonBulkModelSerializer, WritableNestedModelSerializer):
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
variable = AdhocVariableSerializer(many=True, required=False, allow_null=True, label=_('Variable'))
2022-11-11 11:20:17 +00:00
class Meta:
model = AdHoc
2024-10-09 08:10:14 +00:00
read_only_field = ["id", "creator", "date_created", "date_updated", "created_by"]
fields_m2m = ['variable']
fields = read_only_field + fields_m2m + ["id", "name", "scope", "module", "args", "comment"]