Publishing tags, and fixes.
[wolnelektury.git] / src / catalogue / templatetags / catalogue_tags.py
index 718ffd3..b45fc50 100644 (file)
@@ -106,7 +106,7 @@ def nice_title_from_tags(tags, related_tags):
             # No info on genre, but there's only one kind related.
             subpieces = []
             pieces.append([
-                t.collective_noun or t.name for t in self['kind']
+                t.collective_noun or t.name for t in related_tags['kind']
             ])
             plural = False
         else:
@@ -131,9 +131,9 @@ def nice_title_from_tags(tags, related_tags):
     p = []
     for sublist in pieces:
         for item in sublist[:-2]:
-            p.append(item) + ','
+            p.append(item + ',')
         for item in sublist[-2:-1]:
-            p.append(item) + ' i'
+            p.append(item + ' i')
         p.append(sublist[-1])
 
     return ' '.join(p)
@@ -413,12 +413,14 @@ def related_books(context, instance, limit=6, random=1, taken=0):
 
 
 @register.simple_tag
-def related_books_2022(instance, limit=4, taken=0):
+def related_books_2022(book=None, picture=None, limit=4, taken=0):
     limit -= taken
     max_books = limit
 
     books_qs = Book.objects.filter(findable=True)
-    books_qs = books_qs.exclude(common_slug=instance.common_slug).exclude(ancestor=instance)
+    if book is not None:
+        books_qs = books_qs.exclude(common_slug=book.common_slug).exclude(ancestor=book)
+    instance = book or picture
     books = Book.tagged.related_to(instance, books_qs)[:max_books]
 
     return books