1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

add list of modules to fact_version OPTIONS endpoint

This commit is contained in:
Chris Meyers 2015-05-12 08:58:35 -04:00
parent 11eb4d325b
commit d03004ae74

View File

@ -8,7 +8,7 @@ import logging
from dateutil import rrule
from ast import literal_eval
from rest_framework_mongoengine.serializers import MongoEngineModelSerializer
from rest_framework_mongoengine.serializers import MongoEngineModelSerializer, MongoEngineModelSerializerOptions
# PyYAML
import yaml
@ -372,6 +372,23 @@ class BaseSerializer(serializers.ModelSerializer):
return ret
class BaseFactSerializerOptions(MongoEngineModelSerializerOptions):
def __init__(self, meta):
super(BaseFactSerializerOptions, self).__init__(meta)
class BaseFactSerializer(MongoEngineModelSerializer):
_options_class = BaseFactSerializerOptions
__metaclass__ = BaseSerializerMetaclass
def get_fields(self):
ret = super(BaseFactSerializer, self).get_fields()
if 'module' in ret:
choices = [(o, o) for o in FactVersion.objects.all().only('module').distinct('module')]
ret['module'] = ChoiceField(source='module', choices=choices, read_only=True, required=False)
return ret
class UnifiedJobTemplateSerializer(BaseSerializer):
class Meta:
@ -2018,7 +2035,7 @@ class AuthTokenSerializer(serializers.Serializer):
raise serializers.ValidationError('Must include "username" and "password"')
class FactVersionSerializer(MongoEngineModelSerializer):
class FactVersionSerializer(BaseFactSerializer):
related = serializers.SerializerMethodField('get_related')
class Meta:
@ -2037,7 +2054,8 @@ class FactVersionSerializer(MongoEngineModelSerializer):
))
return res
class FactSerializer(MongoEngineModelSerializer):
class FactSerializer(BaseFactSerializer):
class Meta:
model = Fact