mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
Integrate a simple api list and detail display
This commit is contained in:
parent
64d258322c
commit
aac489eea4
@ -28,7 +28,7 @@ from awx.main.utils import *
|
||||
|
||||
# FIXME: machinery for auto-adding audit trail logs to all CREATE/EDITS
|
||||
|
||||
__all__ = ['APIView', 'GenericAPIView', 'ListAPIView', 'ListCreateAPIView',
|
||||
__all__ = ['APIView', 'GenericAPIView', 'ListAPIView', 'SimpleListAPIView', 'ListCreateAPIView',
|
||||
'SubListAPIView', 'SubListCreateAPIView', 'RetrieveAPIView',
|
||||
'RetrieveUpdateAPIView', 'RetrieveUpdateDestroyAPIView']
|
||||
|
||||
@ -172,6 +172,9 @@ class GenericAPIView(generics.GenericAPIView, APIView):
|
||||
ret['search_fields'] = self.search_fields
|
||||
return ret
|
||||
|
||||
class SimpleListAPIView(generics.ListAPIView, GenericAPIView):
|
||||
pass
|
||||
|
||||
class ListAPIView(generics.ListAPIView, GenericAPIView):
|
||||
# Base class for a read-only list view.
|
||||
|
||||
|
@ -999,6 +999,34 @@ class JobEventSerializer(BaseSerializer):
|
||||
pass
|
||||
return d
|
||||
|
||||
class ActivityStreamSerializer(BaseSerializer):
|
||||
|
||||
class Meta:
|
||||
model = ActivityStream
|
||||
fields = ('id', 'url', 'related', 'summary_fields', 'timestamp', 'operation', 'changes')
|
||||
|
||||
def get_related(self, obj):
|
||||
if obj is None:
|
||||
return {}
|
||||
# res = super(ActivityStreamSerializer, self).get_related(obj)
|
||||
# res.update(dict(
|
||||
# #audit_trail = reverse('api:organization_audit_trail_list', args=(obj.pk,)),
|
||||
# projects = reverse('api:organization_projects_list', args=(obj.pk,)),
|
||||
# inventories = reverse('api:organization_inventories_list', args=(obj.pk,)),
|
||||
# users = reverse('api:organization_users_list', args=(obj.pk,)),
|
||||
# admins = reverse('api:organization_admins_list', args=(obj.pk,)),
|
||||
# #tags = reverse('api:organization_tags_list', args=(obj.pk,)),
|
||||
# teams = reverse('api:organization_teams_list', args=(obj.pk,)),
|
||||
# ))
|
||||
# return res
|
||||
|
||||
def get_summary_fields(self, obj):
|
||||
if obj is None:
|
||||
return {}
|
||||
d = super(ActivityStreamSerializer, self).get_summary_fields(obj)
|
||||
return d
|
||||
|
||||
|
||||
class AuthTokenSerializer(serializers.Serializer):
|
||||
|
||||
username = serializers.CharField()
|
||||
|
@ -141,10 +141,10 @@ job_event_urls = patterns('awx.api.views',
|
||||
url(r'^(?P<pk>[0-9]+)/hosts/$', 'job_event_hosts_list'),
|
||||
)
|
||||
|
||||
# activity_stream_urls = patterns('awx.api.views',
|
||||
# url(r'^$', 'activity_stream_list'),
|
||||
# url(r'^(?P<pk>[0-9]+)/$', 'activity_stream_detail'),
|
||||
# )
|
||||
activity_stream_urls = patterns('awx.api.views',
|
||||
url(r'^$', 'activity_stream_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/$', 'activity_stream_detail'),
|
||||
)
|
||||
|
||||
v1_urls = patterns('awx.api.views',
|
||||
url(r'^$', 'api_v1_root_view'),
|
||||
@ -167,7 +167,7 @@ v1_urls = patterns('awx.api.views',
|
||||
url(r'^jobs/', include(job_urls)),
|
||||
url(r'^job_host_summaries/', include(job_host_summary_urls)),
|
||||
url(r'^job_events/', include(job_event_urls)),
|
||||
# url(r'^activity_stream/', include(activity_stream_urls)),
|
||||
url(r'^activity_stream/', include(activity_stream_urls)),
|
||||
)
|
||||
|
||||
urlpatterns = patterns('awx.api.views',
|
||||
|
@ -88,6 +88,7 @@ class ApiV1RootView(APIView):
|
||||
data['hosts'] = reverse('api:host_list')
|
||||
data['job_templates'] = reverse('api:job_template_list')
|
||||
data['jobs'] = reverse('api:job_list')
|
||||
data['activity_stream'] = reverse('api:activity_stream_list')
|
||||
return Response(data)
|
||||
|
||||
class ApiV1ConfigView(APIView):
|
||||
@ -1058,6 +1059,15 @@ class JobJobEventsList(BaseJobEventsList):
|
||||
headers=headers)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
class ActivityStreamList(SimpleListAPIView):
|
||||
|
||||
model = ActivityStream
|
||||
serializer_class = ActivityStreamSerializer
|
||||
|
||||
class ActivityStreamDetail(RetrieveAPIView):
|
||||
|
||||
model = ActivityStream
|
||||
serializer_class = ActivityStreamSerializer
|
||||
|
||||
# Create view functions for all of the class-based views to simplify inclusion
|
||||
# in URL patterns and reverse URL lookups, converting CamelCase names to
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
from django.db import models
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
class ActivityStream(models.Model):
|
||||
@ -33,3 +34,6 @@ class ActivityStream(models.Model):
|
||||
object2_type = models.TextField(null=True, blank=True)
|
||||
|
||||
object_relationship_type = models.TextField(blank=True)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('api:activity_stream_detail', args=(self.pk,))
|
||||
|
Loading…
Reference in New Issue
Block a user