mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-06 08:21:50 -05:00
View and some validation logic for database config
* Fixing some bugs in the manifest definition * Database model and schema migration for tower settings * Initial View and Serializer implementation using a strategy of merging model instances and named tuples
This commit is contained in:
@@ -144,6 +144,7 @@ class APIView(views.APIView):
|
||||
'new_in_220': getattr(self, 'new_in_220', False),
|
||||
'new_in_230': getattr(self, 'new_in_230', False),
|
||||
'new_in_240': getattr(self, 'new_in_240', False),
|
||||
'new_in_300': getattr(self, 'new_in_300', False),
|
||||
}
|
||||
|
||||
def get_description(self, html=False):
|
||||
|
||||
@@ -267,7 +267,7 @@ class BaseSerializer(serializers.ModelSerializer):
|
||||
return choices
|
||||
|
||||
def get_url(self, obj):
|
||||
if obj is None:
|
||||
if obj is None or not hasattr(obj, 'get_absolute_url'):
|
||||
return ''
|
||||
elif isinstance(obj, User):
|
||||
return reverse('api:user_detail', args=(obj.pk,))
|
||||
@@ -2105,7 +2105,12 @@ class ActivityStreamSerializer(BaseSerializer):
|
||||
first_name = obj.actor.first_name,
|
||||
last_name = obj.actor.last_name)
|
||||
return summary_fields
|
||||
|
||||
class TowerSettingsSerializer(BaseSerializer):
|
||||
|
||||
class Meta:
|
||||
model = TowerSettings
|
||||
fields = ('key', 'description', 'category', 'value', 'value_type', 'user')
|
||||
|
||||
class AuthTokenSerializer(serializers.Serializer):
|
||||
|
||||
|
||||
@@ -220,6 +220,9 @@ activity_stream_urls = patterns('awx.api.views',
|
||||
url(r'^(?P<pk>[0-9]+)/$', 'activity_stream_detail'),
|
||||
)
|
||||
|
||||
settings_urls = patterns('awx.api.views',
|
||||
url(r'^$', 'settings_list'))
|
||||
|
||||
v1_urls = patterns('awx.api.views',
|
||||
url(r'^$', 'api_v1_root_view'),
|
||||
url(r'^ping/$', 'api_v1_ping_view'),
|
||||
@@ -230,7 +233,8 @@ v1_urls = patterns('awx.api.views',
|
||||
url(r'^dashboard/$', 'dashboard_view'),
|
||||
url(r'^dashboard/graphs/jobs/$', 'dashboard_jobs_graph_view'),
|
||||
url(r'^dashboard/graphs/inventory/$', 'dashboard_inventory_graph_view'),
|
||||
url(r'^schedules/', include(schedule_urls)),
|
||||
url(r'^settings/', include(settings_urls)),
|
||||
url(r'^schedules/', include(schedule_urls)),
|
||||
url(r'^organizations/', include(organization_urls)),
|
||||
url(r'^users/', include(user_urls)),
|
||||
url(r'^projects/', include(project_urls)),
|
||||
|
||||
@@ -12,6 +12,7 @@ import socket
|
||||
import sys
|
||||
import errno
|
||||
from base64 import b64encode
|
||||
from collections import namedtuple
|
||||
|
||||
# Django
|
||||
from django.conf import settings
|
||||
@@ -113,6 +114,7 @@ class ApiV1RootView(APIView):
|
||||
data['authtoken'] = reverse('api:auth_token_view')
|
||||
data['ping'] = reverse('api:api_v1_ping_view')
|
||||
data['config'] = reverse('api:api_v1_config_view')
|
||||
data['settings'] = reverse('api:settings_list')
|
||||
data['me'] = reverse('api:user_me_list')
|
||||
data['dashboard'] = reverse('api:dashboard_view')
|
||||
data['organizations'] = reverse('api:organization_list')
|
||||
@@ -2959,6 +2961,31 @@ class ActivityStreamDetail(RetrieveAPIView):
|
||||
# Okay, let it through.
|
||||
return super(type(self), self).get(request, *args, **kwargs)
|
||||
|
||||
class SettingsList(ListCreateAPIView):
|
||||
|
||||
model = TowerSettings
|
||||
serializer_class = TowerSettingsSerializer
|
||||
new_in_300 = True
|
||||
filter_backends = ()
|
||||
|
||||
def get_queryset(self):
|
||||
SettingsTuple = namedtuple('Settings', ['key', 'description', 'category', 'value', 'value_type', 'user'])
|
||||
# TODO: Filter by what the user can see
|
||||
all_defined_settings = {s.key: SettingsTuple(s.key, s.description, s.category, s.value, s.value_type, s.user) for s in TowerSettings.objects.all()}
|
||||
manifest_settings = settings.TOWER_SETTINGS_MANIFEST
|
||||
settings_actual = []
|
||||
for settings_key in manifest_settings:
|
||||
if settings_key in all_defined_settings:
|
||||
settings_actual.append(all_defined_settings[settings_key])
|
||||
else:
|
||||
m_entry = manifest_settings[settings_key]
|
||||
settings_actual.append(SettingsTuple(settings_key,
|
||||
m_entry['description'],
|
||||
m_entry['category'],
|
||||
m_entry['default'],
|
||||
m_entry['type'],
|
||||
None))
|
||||
return settings_actual
|
||||
|
||||
# Create view functions for all of the class-based views to simplify inclusion
|
||||
# in URL patterns and reverse URL lookups, converting CamelCase names to
|
||||
|
||||
Reference in New Issue
Block a user