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