Resolve default ordering warnings from tests

This commit is contained in:
AlanCoding 2019-05-02 18:00:18 -04:00
parent f174902bb2
commit f4c18843a3
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
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):

View File

@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-03 14:30
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('main', '0076_v360_add_new_instance_group_relations'),
]
operations = [
migrations.AlterModelOptions(
name='adhoccommand',
options={'ordering': ('id',)},
),
migrations.AlterModelOptions(
name='credentialinputsource',
options={'ordering': ('target_credential', 'source_credential', 'input_field_name')},
),
migrations.AlterModelOptions(
name='instance',
options={'ordering': ('hostname',)},
),
migrations.AlterModelOptions(
name='inventorysource',
options={'ordering': ('inventory', 'name')},
),
migrations.AlterModelOptions(
name='inventoryupdate',
options={'ordering': ('inventory', 'name')},
),
migrations.AlterModelOptions(
name='notificationtemplate',
options={'ordering': ('name',)},
),
migrations.AlterModelOptions(
name='oauth2accesstoken',
options={'ordering': ('id',), 'verbose_name': 'access token'},
),
migrations.AlterModelOptions(
name='oauth2application',
options={'ordering': ('organization', 'name'), 'verbose_name': 'application'},
),
migrations.AlterModelOptions(
name='role',
options={'ordering': ('content_type', 'object_id'), 'verbose_name_plural': 'roles'},
),
migrations.AlterModelOptions(
name='unifiedjob',
options={'ordering': ('id',)},
),
migrations.AlterModelOptions(
name='unifiedjobtemplate',
options={'ordering': ('name',)},
),
]

View File

@ -30,6 +30,7 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin):
class Meta(object):
app_label = 'main'
ordering = ('id',)
diff_mode = models.BooleanField(
default=False,

View File

@ -1312,6 +1312,7 @@ class CredentialInputSource(PrimordialModel):
class Meta:
app_label = 'main'
unique_together = (('target_credential', 'input_field_name'),)
ordering = ('target_credential', 'source_credential', 'input_field_name',)
target_credential = models.ForeignKey(
'Credential',

View File

@ -98,6 +98,7 @@ class Instance(HasPolicyEditsMixin, BaseModel):
class Meta:
app_label = 'main'
ordering = ("hostname",)
POLICY_FIELDS = frozenset(('managed_by_policy', 'hostname', 'capacity_adjustment'))

View File

@ -1451,6 +1451,7 @@ class InventorySource(UnifiedJobTemplate, InventorySourceOptions, CustomVirtualE
class Meta:
app_label = 'main'
ordering = ('inventory', 'name')
inventory = models.ForeignKey(
'Inventory',
@ -1680,6 +1681,7 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin,
class Meta:
app_label = 'main'
ordering = ('inventory', 'name')
inventory = models.ForeignKey(
'Inventory',

View File

@ -50,6 +50,7 @@ class NotificationTemplate(CommonModelNameNotUnique):
class Meta:
app_label = 'main'
unique_together = ('organization', 'name')
ordering = ("name",)
organization = models.ForeignKey(
'Organization',

View File

@ -28,6 +28,7 @@ class OAuth2Application(AbstractApplication):
app_label = 'main'
verbose_name = _('application')
unique_together = (("name", "organization"),)
ordering = ('organization', 'name')
CLIENT_CONFIDENTIAL = "confidential"
CLIENT_PUBLIC = "public"
@ -89,6 +90,7 @@ class OAuth2AccessToken(AbstractAccessToken):
class Meta:
app_label = 'main'
verbose_name = _('access token')
ordering = ('id',)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,

View File

@ -138,6 +138,7 @@ class Role(models.Model):
index_together = [
("content_type", "object_id")
]
ordering = ("content_type", "object_id")
role_field = models.TextField(null=False)
singleton_name = models.TextField(null=True, default=None, db_index=True, unique=True)

View File

@ -98,6 +98,7 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
class Meta:
app_label = 'main'
ordering = ('name',)
# unique_together here is intentionally commented out. Please make sure sub-classes of this model
# contain at least this uniqueness restriction: SOFT_UNIQUE_TOGETHER = [('polymorphic_ctype', 'name')]
#unique_together = [('polymorphic_ctype', 'name')]
@ -556,6 +557,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
class Meta:
app_label = 'main'
ordering = ('id',)
old_pk = models.PositiveIntegerField(
null=True,