From 0e7a275a2824ec5c2c3b62177022b29a9300ebd2 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Tue, 11 Apr 2023 22:41:52 +0200 Subject: [PATCH] Order participations by validity status and by trigram Signed-off-by: Emmy D'Anello --- .../0008_alter_participation_options.py | 20 +++++++++++++++++++ participation/models.py | 1 + participation/tables.py | 1 + participation/views.py | 16 +++++++++++---- registration/tables.py | 3 +-- 5 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 participation/migrations/0008_alter_participation_options.py diff --git a/participation/migrations/0008_alter_participation_options.py b/participation/migrations/0008_alter_participation_options.py new file mode 100644 index 0000000..a47916b --- /dev/null +++ b/participation/migrations/0008_alter_participation_options.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2 on 2023-04-11 20:41 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("participation", "0007_note_observer_oral_passage_observer"), + ] + + operations = [ + migrations.AlterModelOptions( + name="participation", + options={ + "ordering": ("valid", "team__trigram"), + "verbose_name": "participation", + "verbose_name_plural": "participations", + }, + ), + ] diff --git a/participation/models.py b/participation/models.py index 88434c0..7e435f6 100644 --- a/participation/models.py +++ b/participation/models.py @@ -341,6 +341,7 @@ class Participation(models.Model): class Meta: verbose_name = _("participation") verbose_name_plural = _("participations") + ordering = ('valid', 'team__trigram',) class Pool(models.Model): diff --git a/participation/tables.py b/participation/tables.py index ad8a27d..6248a2f 100644 --- a/participation/tables.py +++ b/participation/tables.py @@ -54,6 +54,7 @@ class ParticipationTable(tables.Table): } model = Team fields = ('name', 'trigram', 'valid',) + order = ('-valid',) class TournamentTable(tables.Table): diff --git a/participation/views.py b/participation/views.py index 2c25bb7..49b9c77 100644 --- a/participation/views.py +++ b/participation/views.py @@ -24,7 +24,7 @@ from django.utils.crypto import get_random_string from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, DetailView, FormView, RedirectView, TemplateView, UpdateView, View from django.views.generic.edit import FormMixin, ProcessFormView -from django_tables2 import SingleTableView +from django_tables2 import SingleTableView, MultiTableMixin from magic import Magic from odf.opendocument import OpenDocumentSpreadsheet from odf.style import Style, TableCellProperties, TableColumnProperties, TextProperties @@ -555,16 +555,24 @@ class TournamentUpdateView(VolunteerMixin, UpdateView): return super().dispatch(request, *args, **kwargs) -class TournamentDetailView(DetailView): +class TournamentDetailView(MultiTableMixin, DetailView): """ Display tournament detail. """ model = Tournament + def dispatch(self, request, *args, **kwargs): + self.tables = [ + ParticipationTable(self.get_object().participations.all()), + PoolTable(self.get_object().pools.order_by('id').all()), + ] + return super().dispatch(request, *args, **kwargs) + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context["teams"] = ParticipationTable(self.object.participations.all()) - context["pools"] = PoolTable(self.object.pools.order_by('id').all()) + tables = context['tables'] + context["teams"] = tables[0] + context["pools"] = tables[1] notes = dict() for participation in self.object.participations.all(): diff --git a/registration/tables.py b/registration/tables.py index 62c6769..5344804 100644 --- a/registration/tables.py +++ b/registration/tables.py @@ -19,8 +19,7 @@ class RegistrationTable(tables.Table): ) def order_type(self, queryset, desc): - types = ["volunteerregistration", "-volunteerregistration__admin", "participantregistration"] - return queryset.order_by(*(("-" if desc else "") + t for t in types)), True + return queryset.order_by(('-' if desc else '') + 'polymorphic_ctype'), True class Meta: attrs = {