mirror of
https://github.com/ansible/awx.git
synced 2026-07-06 13:58:05 -02:30
Added config resource with project base dir and local paths, various other API cleanup.
This commit is contained in:
@@ -9,9 +9,8 @@ from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
# Django REST framework
|
||||
from rest_framework import serializers, pagination
|
||||
from rest_framework.templatetags.rest_framework import replace_query_param
|
||||
# Django REST Framework
|
||||
from rest_framework import serializers
|
||||
|
||||
# AnsibleWorks
|
||||
from ansibleworks.main.models import *
|
||||
@@ -19,37 +18,6 @@ from ansibleworks.main.models import *
|
||||
BASE_FIELDS = ('id', 'url', 'related', 'summary_fields', 'created',
|
||||
'creation_date', 'name', 'description')
|
||||
|
||||
class NextPageField(pagination.NextPageField):
|
||||
''' makes the pagination relative URL not full URL '''
|
||||
|
||||
def to_native(self, value):
|
||||
if not value.has_next():
|
||||
return None
|
||||
page = value.next_page_number()
|
||||
request = self.context.get('request')
|
||||
url = request and request.get_full_path() or ''
|
||||
return replace_query_param(url, self.page_field, page)
|
||||
|
||||
class PreviousPageField(pagination.NextPageField):
|
||||
''' makes the pagination relative URL not full URL '''
|
||||
|
||||
def to_native(self, value):
|
||||
if not value.has_previous():
|
||||
return None
|
||||
page = value.previous_page_number()
|
||||
request = self.context.get('request')
|
||||
url = request and request.get_full_path() or ''
|
||||
return replace_query_param(url, self.page_field, page)
|
||||
|
||||
class PaginationSerializer(pagination.BasePaginationSerializer):
|
||||
'''
|
||||
Custom pagination serializer to output only URL path (without host/port).
|
||||
'''
|
||||
|
||||
count = serializers.Field(source='paginator.count')
|
||||
next = NextPageField(source='*')
|
||||
previous = PreviousPageField(source='*')
|
||||
|
||||
# objects that if found we should add summary info for them
|
||||
SUMMARIZABLE_FKS = (
|
||||
'organization', 'host', 'group', 'inventory', 'project', 'team', 'job', 'job_template',
|
||||
@@ -142,11 +110,10 @@ class OrganizationSerializer(BaseSerializer):
|
||||
class ProjectSerializer(BaseSerializer):
|
||||
|
||||
playbooks = serializers.Field(source='playbooks')
|
||||
local_path_choices = serializers.SerializerMethodField('get_local_path_choices')
|
||||
|
||||
class Meta:
|
||||
model = Project
|
||||
fields = BASE_FIELDS + ('local_path', 'local_path_choices')
|
||||
fields = BASE_FIELDS + ('local_path',)
|
||||
# 'default_playbook', 'scm_type')
|
||||
|
||||
def get_related(self, obj):
|
||||
@@ -157,9 +124,6 @@ class ProjectSerializer(BaseSerializer):
|
||||
))
|
||||
return res
|
||||
|
||||
def get_local_path_choices(self, obj):
|
||||
return Project.get_local_path_choices()
|
||||
|
||||
class ProjectPlaybooksSerializer(ProjectSerializer):
|
||||
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user