Resolve default ordering warnings from tests

This commit is contained in:
AlanCoding
2019-05-02 18:00:18 -04:00
parent f174902bb2
commit f4c18843a3
13 changed files with 82 additions and 0 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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):