From ee9416d8edba88445f3e8dd90e261e00b0215257 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 30 Jan 2024 13:47:22 +0100 Subject: [PATCH] Set order_by on DatabaseListView queryset --- orchestra/contrib/musician/urls.py | 2 +- orchestra/contrib/musician/views.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/orchestra/contrib/musician/urls.py b/orchestra/contrib/musician/urls.py index 50ea0161..98b81601 100644 --- a/orchestra/contrib/musician/urls.py +++ b/orchestra/contrib/musician/urls.py @@ -37,6 +37,6 @@ urlpatterns = [ path('mailboxes//delete/', views.MailboxDeleteView.as_view(), name='mailbox-delete'), path('mailboxes//change-password/', views.MailboxChangePasswordView.as_view(), name='mailbox-password'), path('mailing-lists/', views.MailingListsView.as_view(), name='mailing-lists'), - path('databases/', views.DatabasesView.as_view(), name='database-list'), + path('databases/', views.DatabaseListView.as_view(), name='database-list'), path('saas/', views.SaasListView.as_view(), name='saas-list'), ] diff --git a/orchestra/contrib/musician/views.py b/orchestra/contrib/musician/views.py index 7551de99..b5fff69e 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -3,6 +3,7 @@ import smtplib from typing import Any from django.conf import settings +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ImproperlyConfigured from django.core.mail import mail_managers from django.db.models import Value @@ -29,6 +30,7 @@ from orchestra.contrib.databases.models import Database from orchestra.contrib.domains.models import Domain, Record from orchestra.contrib.lists.models import List from orchestra.contrib.mailboxes.models import Address, Mailbox +from orchestra.contrib.resources.models import Resource, ResourceData from orchestra.contrib.saas.models import SaaS from orchestra.utils.html import html_to_pdf @@ -453,7 +455,7 @@ class MailboxChangePasswordView(CustomContextMixin, UserTokenRequiredMixin, Upda return self.model.objects.filter(account=self.request.user) -class DatabasesView(ServiceListView): +class DatabaseListView(ServiceListView): template_name = "musician/database_list.html" model = Database service_class = DatabaseService @@ -463,11 +465,9 @@ class DatabasesView(ServiceListView): } def get_queryset(self): - qs = super().get_queryset() - # TODO(@slamora): optimize query - from django.contrib.contenttypes.models import ContentType + qs = super().get_queryset().order_by("name") - from orchestra.contrib.resources.models import Resource, ResourceData + # TODO(@slamora): optimize query ctype = ContentType.objects.get_for_model(self.model) disk_resource = Resource.objects.get(name='disk', content_type=ctype) for db in qs: