Django 3
[redakcja.git] / src / catalogue / templatetags / book_list.py
old mode 100755 (executable)
new mode 100644 (file)
index 9ac996b..db24c69
@@ -1,5 +1,6 @@
-from __future__ import absolute_import
-
+# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
 from re import split
 from django.db.models import Q, Count
 from django import template
@@ -12,12 +13,7 @@ register = template.Library()
 
 class ChunksList(object):
     def __init__(self, chunk_qs):
-        #self.chunk_qs = chunk_qs#.annotate(
-            #book_length=Count('book__chunk')).select_related(
-            #'book')#, 'stage__name',
-            #'user')
-        self.chunk_qs = chunk_qs.select_related('book__hidden')
-
+        self.chunk_qs = chunk_qs.select_related('book', 'book__project', 'stage', 'user')
         self.book_qs = chunk_qs.values('book_id')
 
     def __getitem__(self, key):
@@ -103,7 +99,7 @@ def document_list_filter(request, **kwargs):
 
     chunks = chunks.order_by('book__title', 'book', 'number')
 
-    if not request.user.is_authenticated():
+    if not request.user.is_authenticated:
         chunks = chunks.filter(book__public=True)
 
     state = arg_or_GET('status')
@@ -163,9 +159,9 @@ def image_list_filter(request, **kwargs):
     def arg_or_GET(field):
         return kwargs.get(field, request.GET.get(field))
 
-    images = Image.objects.all()
+    images = Image.objects.all().select_related('user', 'stage', 'project')
 
-    if not request.user.is_authenticated():
+    if not request.user.is_authenticated:
         images = images.filter(public=True)
 
     state = arg_or_GET('status')