Specify default DataTable sorting for some backend forms
authorMagnus Hagander <magnus@hagander.net>
Sun, 23 Sep 2018 12:56:59 +0000 (14:56 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sun, 23 Sep 2018 12:58:22 +0000 (14:58 +0200)
We had sorting, but when adding DataTable everything reverted to sorting
based on the first column. Fix that for example for all items that have
a defined sortkey column.

postgresqleu/confreg/backendforms.py
postgresqleu/confreg/backendviews.py
template/confreg/admin_backend_list.html

index fc30d1754afde466769152ed6866941355118ebd..6e856f5fbec33fa78095e6a0336823ba3c12f86c 100644 (file)
@@ -44,6 +44,7 @@ class BackendForm(ConcurrentProtectedModelForm):
        allow_copy_previous = False
        copy_transform_form = None
        coltypes = {}
+       defaultsort = []
        readonly_fields = []
        file_fields = []
        linked_objects = {}
@@ -265,6 +266,7 @@ class BackendRegistrationTypeForm(BackendForm):
        coltypes = {
                'Sortkey': ['nosearch' ],
        }
+       defaultsort = [[4, 'asc']]
        auto_cascade_delete_to=['registrationtype_days', 'registrationtype_requires_option']
 
        class Meta:
@@ -361,6 +363,7 @@ class BackendTrackForm(BackendForm):
        coltypes = {
                'Sortkey': ['nosearch' ],
        }
+       defaultsort = [[1, 'asc']]
 
        @classmethod
        def copy_from_conference(self, targetconf, sourceconf, idlist):
@@ -386,6 +389,7 @@ class BackendRoomForm(BackendForm):
        coltypes = {
                'Sortkey': ['nosearch' ],
        }
+       defaultsort = [[1, 'asc']]
 
 class BackendTransformConferenceDateTimeForm(django.forms.Form):
        timeshift = django.forms.DurationField(required=True, help_text="Shift all times by this much")
@@ -595,9 +599,12 @@ class BackendFeedbackQuestionForm(BackendForm):
        class Meta:
                model = ConferenceFeedbackQuestion
                fields = ['question', 'isfreetext', 'textchoices', 'sortkey', 'newfieldset']
+
        coltypes = {
                'Sortkey': ['nosearch' ],
+               'Newfieldset': ['nosort', ],
        }
+       defaultsort = [[2, 'asc']]
 
        def clean(self):
                cleaned_data = super(BackendFeedbackQuestionForm, self).clean()
index 4d91f99bfffcb0c7c43bdd02a19efd08dac463e0..fe864b29c8b381d395fa848323591c3e7c1c8715 100644 (file)
@@ -251,6 +251,7 @@ def backend_handle_copy_previous(request, formclass, restpieces, conference):
                        'plural_name': formclass.Meta.model._meta.verbose_name_plural,
                        'headers': [formclass.get_field_verbose_name(f) for f in formclass.list_fields],
                        'coltypes': formclass.coltypes,
+                       'defaultsort': formclass.defaultsort,
                        'return_url': '../',
                        'allow_new': False,
                        'allow_delete': False,
@@ -290,6 +291,7 @@ def backend_list_editor(request, urlname, formclass, resturl, allow_new=True, al
                        'plural_name': formclass.Meta.model._meta.verbose_name_plural,
                        'headers': [formclass.get_field_verbose_name(f) for f in formclass.list_fields],
                        'coltypes': formclass.coltypes,
+                       'defaultsort': formclass.defaultsort,
                        'return_url': return_url,
                        'allow_new': allow_new,
                        'allow_delete': allow_delete,
index 6b18163cd167be78eb8cd8212564248d763c1d8f..cc3854994e7eef9d15ad78687adfc813abc8ece5 100644 (file)
@@ -16,6 +16,9 @@ $(document).ready(function() {
          { targets: 'coltype-nosearch', searchable: false},
 
       ],
+{%if defaultsort%}
+      'order': {{defaultsort|safe}},
+{%endif%}
    });
 
    $('#copyallcheckbox').click(function(e) {