mirror of
https://github.com/ansible/awx.git
synced 2026-01-23 15:38:06 -03:30
Resolve default ordering warnings from tests
This commit is contained in:
parent
f174902bb2
commit
f4c18843a3
@ -402,6 +402,8 @@ class OrderByBackend(BaseFilterBackend):
|
|||||||
order_by = value.split(',')
|
order_by = value.split(',')
|
||||||
else:
|
else:
|
||||||
order_by = (value,)
|
order_by = (value,)
|
||||||
|
if order_by is None:
|
||||||
|
order_by = self.get_default_ordering(view)
|
||||||
if order_by:
|
if order_by:
|
||||||
order_by = self._validate_ordering_fields(queryset.model, 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.
|
# Return a 400 for invalid field names.
|
||||||
raise ParseError(*e.args)
|
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):
|
def _validate_ordering_fields(self, model, order_by):
|
||||||
for field_name in order_by:
|
for field_name in order_by:
|
||||||
# strip off the negation prefix `-` if it exists
|
# strip off the negation prefix `-` if it exists
|
||||||
|
|||||||
@ -815,6 +815,7 @@ class RetrieveUpdateDestroyAPIView(RetrieveUpdateAPIView, DestroyAPIView):
|
|||||||
class ResourceAccessList(ParentMixin, ListAPIView):
|
class ResourceAccessList(ParentMixin, ListAPIView):
|
||||||
|
|
||||||
serializer_class = ResourceAccessListElementSerializer
|
serializer_class = ResourceAccessListElementSerializer
|
||||||
|
ordering = ('username',)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
obj = self.get_parent_object()
|
obj = self.get_parent_object()
|
||||||
|
|||||||
@ -4455,6 +4455,7 @@ class RoleUsersList(SubListAttachDetachAPIView):
|
|||||||
serializer_class = serializers.UserSerializer
|
serializer_class = serializers.UserSerializer
|
||||||
parent_model = models.Role
|
parent_model = models.Role
|
||||||
relationship = 'members'
|
relationship = 'members'
|
||||||
|
ordering = ('username',)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
role = self.get_parent_object()
|
role = self.get_parent_object()
|
||||||
|
|||||||
@ -116,6 +116,7 @@ class OrganizationUsersList(BaseUsersList):
|
|||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
parent_model = Organization
|
parent_model = Organization
|
||||||
relationship = 'member_role.members'
|
relationship = 'member_role.members'
|
||||||
|
ordering = ('username',)
|
||||||
|
|
||||||
|
|
||||||
class OrganizationAdminsList(BaseUsersList):
|
class OrganizationAdminsList(BaseUsersList):
|
||||||
@ -124,6 +125,7 @@ class OrganizationAdminsList(BaseUsersList):
|
|||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
parent_model = Organization
|
parent_model = Organization
|
||||||
relationship = 'admin_role.members'
|
relationship = 'admin_role.members'
|
||||||
|
ordering = ('username',)
|
||||||
|
|
||||||
|
|
||||||
class OrganizationProjectsList(SubListCreateAttachDetachAPIView):
|
class OrganizationProjectsList(SubListCreateAttachDetachAPIView):
|
||||||
|
|||||||
59
awx/main/migrations/0077_v360_add_default_orderings.py
Normal file
59
awx/main/migrations/0077_v360_add_default_orderings.py
Normal 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',)},
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -30,6 +30,7 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin):
|
|||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
ordering = ('id',)
|
||||||
|
|
||||||
diff_mode = models.BooleanField(
|
diff_mode = models.BooleanField(
|
||||||
default=False,
|
default=False,
|
||||||
|
|||||||
@ -1312,6 +1312,7 @@ class CredentialInputSource(PrimordialModel):
|
|||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
unique_together = (('target_credential', 'input_field_name'),)
|
unique_together = (('target_credential', 'input_field_name'),)
|
||||||
|
ordering = ('target_credential', 'source_credential', 'input_field_name',)
|
||||||
|
|
||||||
target_credential = models.ForeignKey(
|
target_credential = models.ForeignKey(
|
||||||
'Credential',
|
'Credential',
|
||||||
|
|||||||
@ -98,6 +98,7 @@ class Instance(HasPolicyEditsMixin, BaseModel):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
ordering = ("hostname",)
|
||||||
|
|
||||||
POLICY_FIELDS = frozenset(('managed_by_policy', 'hostname', 'capacity_adjustment'))
|
POLICY_FIELDS = frozenset(('managed_by_policy', 'hostname', 'capacity_adjustment'))
|
||||||
|
|
||||||
|
|||||||
@ -1451,6 +1451,7 @@ class InventorySource(UnifiedJobTemplate, InventorySourceOptions, CustomVirtualE
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
ordering = ('inventory', 'name')
|
||||||
|
|
||||||
inventory = models.ForeignKey(
|
inventory = models.ForeignKey(
|
||||||
'Inventory',
|
'Inventory',
|
||||||
@ -1680,6 +1681,7 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin,
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
ordering = ('inventory', 'name')
|
||||||
|
|
||||||
inventory = models.ForeignKey(
|
inventory = models.ForeignKey(
|
||||||
'Inventory',
|
'Inventory',
|
||||||
|
|||||||
@ -50,6 +50,7 @@ class NotificationTemplate(CommonModelNameNotUnique):
|
|||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
unique_together = ('organization', 'name')
|
unique_together = ('organization', 'name')
|
||||||
|
ordering = ("name",)
|
||||||
|
|
||||||
organization = models.ForeignKey(
|
organization = models.ForeignKey(
|
||||||
'Organization',
|
'Organization',
|
||||||
|
|||||||
@ -28,6 +28,7 @@ class OAuth2Application(AbstractApplication):
|
|||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
verbose_name = _('application')
|
verbose_name = _('application')
|
||||||
unique_together = (("name", "organization"),)
|
unique_together = (("name", "organization"),)
|
||||||
|
ordering = ('organization', 'name')
|
||||||
|
|
||||||
CLIENT_CONFIDENTIAL = "confidential"
|
CLIENT_CONFIDENTIAL = "confidential"
|
||||||
CLIENT_PUBLIC = "public"
|
CLIENT_PUBLIC = "public"
|
||||||
@ -89,6 +90,7 @@ class OAuth2AccessToken(AbstractAccessToken):
|
|||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
verbose_name = _('access token')
|
verbose_name = _('access token')
|
||||||
|
ordering = ('id',)
|
||||||
|
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
settings.AUTH_USER_MODEL,
|
settings.AUTH_USER_MODEL,
|
||||||
|
|||||||
@ -138,6 +138,7 @@ class Role(models.Model):
|
|||||||
index_together = [
|
index_together = [
|
||||||
("content_type", "object_id")
|
("content_type", "object_id")
|
||||||
]
|
]
|
||||||
|
ordering = ("content_type", "object_id")
|
||||||
|
|
||||||
role_field = models.TextField(null=False)
|
role_field = models.TextField(null=False)
|
||||||
singleton_name = models.TextField(null=True, default=None, db_index=True, unique=True)
|
singleton_name = models.TextField(null=True, default=None, db_index=True, unique=True)
|
||||||
|
|||||||
@ -98,6 +98,7 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
ordering = ('name',)
|
||||||
# unique_together here is intentionally commented out. Please make sure sub-classes of this model
|
# 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')]
|
# contain at least this uniqueness restriction: SOFT_UNIQUE_TOGETHER = [('polymorphic_ctype', 'name')]
|
||||||
#unique_together = [('polymorphic_ctype', 'name')]
|
#unique_together = [('polymorphic_ctype', 'name')]
|
||||||
@ -556,6 +557,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
ordering = ('id',)
|
||||||
|
|
||||||
old_pk = models.PositiveIntegerField(
|
old_pk = models.PositiveIntegerField(
|
||||||
null=True,
|
null=True,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user