mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-24 08:51:48 -05:00
Resolve default ordering warnings from tests
This commit is contained in:
@@ -402,6 +402,8 @@ class OrderByBackend(BaseFilterBackend):
|
||||
order_by = value.split(',')
|
||||
else:
|
||||
order_by = (value,)
|
||||
if order_by is None:
|
||||
order_by = self.get_default_ordering(view)
|
||||
if order_by:
|
||||
order_by = self._validate_ordering_fields(queryset.model, order_by)
|
||||
|
||||
@@ -428,6 +430,12 @@ class OrderByBackend(BaseFilterBackend):
|
||||
# Return a 400 for invalid field names.
|
||||
raise ParseError(*e.args)
|
||||
|
||||
def get_default_ordering(self, view):
|
||||
ordering = getattr(view, 'ordering', None)
|
||||
if isinstance(ordering, str):
|
||||
return (ordering,)
|
||||
return ordering
|
||||
|
||||
def _validate_ordering_fields(self, model, order_by):
|
||||
for field_name in order_by:
|
||||
# strip off the negation prefix `-` if it exists
|
||||
|
||||
@@ -815,6 +815,7 @@ class RetrieveUpdateDestroyAPIView(RetrieveUpdateAPIView, DestroyAPIView):
|
||||
class ResourceAccessList(ParentMixin, ListAPIView):
|
||||
|
||||
serializer_class = ResourceAccessListElementSerializer
|
||||
ordering = ('username',)
|
||||
|
||||
def get_queryset(self):
|
||||
obj = self.get_parent_object()
|
||||
|
||||
@@ -4455,6 +4455,7 @@ class RoleUsersList(SubListAttachDetachAPIView):
|
||||
serializer_class = serializers.UserSerializer
|
||||
parent_model = models.Role
|
||||
relationship = 'members'
|
||||
ordering = ('username',)
|
||||
|
||||
def get_queryset(self):
|
||||
role = self.get_parent_object()
|
||||
|
||||
@@ -116,6 +116,7 @@ class OrganizationUsersList(BaseUsersList):
|
||||
serializer_class = UserSerializer
|
||||
parent_model = Organization
|
||||
relationship = 'member_role.members'
|
||||
ordering = ('username',)
|
||||
|
||||
|
||||
class OrganizationAdminsList(BaseUsersList):
|
||||
@@ -124,6 +125,7 @@ class OrganizationAdminsList(BaseUsersList):
|
||||
serializer_class = UserSerializer
|
||||
parent_model = Organization
|
||||
relationship = 'admin_role.members'
|
||||
ordering = ('username',)
|
||||
|
||||
|
||||
class OrganizationProjectsList(SubListCreateAttachDetachAPIView):
|
||||
|
||||
Reference in New Issue
Block a user