diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 0bb29b5408..b092d6cf7e 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -121,6 +121,8 @@ class ChoiceField(fields.ChoiceField): def metadata(self): metadata = super(ChoiceField, self).metadata() metadata['choices'] = self.choices or [] + if not self.choices: + metadata.pop('default', None) return metadata # Monkeypatch REST framework to replace default ChoiceField used by @@ -1603,6 +1605,7 @@ class JobRelaunchSerializer(JobSerializer): class AdHocCommandSerializer(UnifiedJobSerializer): name = serializers.CharField(source='name', read_only=True) + module_name = ChoiceField(source='module_name', label='module name', required=bool(not AdHocCommand.MODULE_NAME_DEFAULT), choices=AdHocCommand.MODULE_NAME_CHOICES, default=AdHocCommand.MODULE_NAME_DEFAULT) class Meta: model = AdHocCommand diff --git a/awx/main/models/ad_hoc_commands.py b/awx/main/models/ad_hoc_commands.py index ffeb90522c..1a48bbffcb 100644 --- a/awx/main/models/ad_hoc_commands.py +++ b/awx/main/models/ad_hoc_commands.py @@ -30,6 +30,7 @@ __all__ = ['AdHocCommand', 'AdHocCommandEvent'] class AdHocCommand(UnifiedJob): MODULE_NAME_CHOICES = [(x,x) for x in settings.AD_HOC_COMMANDS] + MODULE_NAME_DEFAULT = 'command' if 'command' in settings.AD_HOC_COMMANDS else None class Meta(object): app_label = 'main' @@ -59,9 +60,9 @@ class AdHocCommand(UnifiedJob): ) module_name = models.CharField( max_length=1024, - default='command', + default=MODULE_NAME_DEFAULT, choices=MODULE_NAME_CHOICES, - blank=True, # If blank, defaults to 'command'. + blank=bool(MODULE_NAME_DEFAULT), ) module_args = models.TextField( blank=True,