Show choices in OPTIONS response for ad hoc command module_name even when empty.

This commit is contained in:
Chris Church 2015-05-14 15:02:52 -04:00
parent 7d65b439fa
commit 8e89e0e829
2 changed files with 6 additions and 2 deletions

View File

@ -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

View File

@ -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,