correct sorting by author in lists: collection, audiobooks
authorJan Szejko <j-sz@o2.pl>
Sat, 30 Jan 2016 23:56:33 +0000 (00:56 +0100)
committerJan Szejko <j-sz@o2.pl>
Sat, 30 Jan 2016 23:56:33 +0000 (00:56 +0100)
src/catalogue/models/collection.py
src/catalogue/views.py

index 15a4e2a..0150055 100644 (file)
@@ -49,7 +49,7 @@ class Collection(models.Model):
 
     def get_books(self):
         from catalogue.models import Book
 
     def get_books(self):
         from catalogue.models import Book
-        return Book.objects.filter(self.get_query())
+        return Book.objects.filter(self.get_query()).order_by('sort_key_author', 'sort_key')
 
     def flush_includes(self, languages=True):
         if not languages:
 
     def flush_includes(self, languages=True):
         if not languages:
index 92fe162..09f48c7 100644 (file)
@@ -57,14 +57,15 @@ def book_list(request, filter=None, get_filter=None, template_name='catalogue/bo
 
 
 def audiobook_list(request):
 
 
 def audiobook_list(request):
-    books = models.Book.objects.filter(Q(media__type='mp3') | Q(media__type='ogg')).distinct()
+    books = models.Book.objects.filter(media__type__in=('mp3', 'ogg')).distinct().order_by(
+        'sort_key_author', 'sort_key')
     books = list(books)
     if len(books) > 3:
         best = random.sample(books, 3)
     else:
         best = books
 
     books = list(books)
     if len(books) > 3:
         best = random.sample(books, 3)
     else:
         best = books
 
-    daisy = models.Book.objects.filter(media__type='daisy').distinct()
+    daisy = models.Book.objects.filter(media__type='daisy').distinct().order_by('sort_key_author', 'sort_key')
 
     return render(request, 'catalogue/audiobook_list.html', {
         'books': books,
 
     return render(request, 'catalogue/audiobook_list.html', {
         'books': books,
@@ -163,9 +164,9 @@ def tagged_object_list(request, tags='', gallery=False):
                 raise Http404
             else:
                 if tags:
                 raise Http404
             else:
                 if tags:
-                    objects = Picture.tagged.with_all(tags).order_by('sort_key_author', 'sort_key')
+                    objects = Picture.tagged.with_all(tags)
                 else:
                 else:
-                    objects = Picture.objects.all().order_by('sort_key_author', 'sort_key')
+                    objects = Picture.objects.all()
             areas = PictureArea.objects.filter(picture__in=objects)
             categories = split_tags(
                 models.Tag.objects.usage_for_queryset(
             areas = PictureArea.objects.filter(picture__in=objects)
             categories = split_tags(
                 models.Tag.objects.usage_for_queryset(
@@ -181,15 +182,15 @@ def tagged_object_list(request, tags='', gallery=False):
             else:
                 all_books = models.Book.objects.filter(parent=None)
             if shelf_is_set:
             else:
                 all_books = models.Book.objects.filter(parent=None)
             if shelf_is_set:
-                objects = all_books.order_by('sort_key_author', 'sort_key')
+                objects = all_books
                 related_book_tags = models.Tag.objects.usage_for_queryset(
                     objects, counts=True).exclude(
                     category='set').exclude(pk__in=tags_pks)
             else:
                 if tags:
                 related_book_tags = models.Tag.objects.usage_for_queryset(
                     objects, counts=True).exclude(
                     category='set').exclude(pk__in=tags_pks)
             else:
                 if tags:
-                    objects = models.Book.tagged_top_level(tags).order_by('sort_key_author', 'sort_key')
+                    objects = models.Book.tagged_top_level(tags)
                 else:
                 else:
-                    objects = all_books.order_by('sort_key_author', 'sort_key')
+                    objects = all_books
                 # WTF: was outside if, overwriting value assigned if shelf_is_set
                 related_book_tags = get_top_level_related_tags(tags)
 
                 # WTF: was outside if, overwriting value assigned if shelf_is_set
                 related_book_tags = get_top_level_related_tags(tags)
 
@@ -201,6 +202,7 @@ def tagged_object_list(request, tags='', gallery=False):
                     fragments, counts=True).filter(
                     category='theme').exclude(pk__in=tags_pks),
             )
                     fragments, counts=True).filter(
                     category='theme').exclude(pk__in=tags_pks),
             )
+        objects = objects.order_by('sort_key_author', 'sort_key')
 
     objects = list(objects)
     if len(objects) > 3:
 
     objects = list(objects)
     if len(objects) > 3: