Fixes #4076: Recommendations from collections.
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 18 Sep 2020 13:35:40 +0000 (15:35 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 18 Sep 2020 13:35:40 +0000 (15:35 +0200)
14 files changed:
src/catalogue/locale/de/LC_MESSAGES/django.po
src/catalogue/locale/en/LC_MESSAGES/django.po
src/catalogue/locale/es/LC_MESSAGES/django.po
src/catalogue/locale/fr/LC_MESSAGES/django.po
src/catalogue/locale/it/LC_MESSAGES/django.po
src/catalogue/locale/lt/LC_MESSAGES/django.po
src/catalogue/locale/pl/LC_MESSAGES/django.mo
src/catalogue/locale/pl/LC_MESSAGES/django.po
src/catalogue/locale/ru/LC_MESSAGES/django.po
src/catalogue/locale/uk/LC_MESSAGES/django.po
src/catalogue/migrations/0030_collection_role.py [new file with mode: 0644]
src/catalogue/models/collection.py
src/catalogue/views.py
src/wolnelektury/views.py

index bb9fdc0..b78748b 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
 "PO-Revision-Date: 2013-04-09 10:38+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index a16499f..86902eb 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
 "PO-Revision-Date: 2013-04-09 10:38+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 725d2d9..826fc7a 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
 "PO-Revision-Date: 2013-04-09 10:39+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 96bae9f..c8b83aa 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
 "PO-Revision-Date: 2013-04-09 10:38+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 489a6a8..9845f28 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
 "PO-Revision-Date: 2013-04-09 10:39+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index be2d17f..36987e9 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
 "PO-Revision-Date: 2013-04-09 10:40+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index b45c68d..dfc9070 100644 (file)
Binary files a/src/catalogue/locale/pl/LC_MESSAGES/django.mo and b/src/catalogue/locale/pl/LC_MESSAGES/django.mo differ
index 2cf6644..d2d3059 100644 (file)
@@ -5,8 +5,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: WolneLektury\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
-"PO-Revision-Date: 2015-12-31 16:45+0100\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
+"PO-Revision-Date: 2020-09-18 15:34+0200\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: Fundacja Nowoczesna Polska <fundacja@nowoczesnapolska.org."
 "pl>\n"
@@ -17,7 +17,7 @@ msgstr ""
 "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
 "|| n%100>=20) ? 1 : 2);\n"
 "X-Translated-Using: django-rosetta 0.5.6\n"
-"X-Generator: Poedit 1.8.4\n"
+"X-Generator: Poedit 2.3\n"
 
 #: catalogue/constants.py:9
 msgid "Creative Commons Attribution-ShareAlike 3.0 Unported"
@@ -233,10 +233,8 @@ msgid "cover for mobile app"
 msgstr "okładka dla aplikacji"
 
 #: catalogue/models/book.py:107
-#, fuzzy
-#| msgid "cover for mobile app"
 msgid "cover for Ebookpoint"
-msgstr "okładka dla aplikacji"
+msgstr "okładka dla Ebookpoint"
 
 #: catalogue/models/book.py:136 catalogue/models/collection.py:19
 msgid "book"
index 357039e..cd580cb 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
 "PO-Revision-Date: 2013-04-09 10:40+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 8c1160d..2902742 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-09-10 15:34+0200\n"
+"POT-Creation-Date: 2020-09-17 10:36+0200\n"
 "PO-Revision-Date: 2013-04-09 10:40+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
diff --git a/src/catalogue/migrations/0030_collection_role.py b/src/catalogue/migrations/0030_collection_role.py
new file mode 100644 (file)
index 0000000..6d5e8e5
--- /dev/null
@@ -0,0 +1,18 @@
+# Generated by Django 2.2.16 on 2020-09-18 13:29
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('catalogue', '0029_auto_20200414_1516'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='collection',
+            name='role',
+            field=models.CharField(blank=True, choices=[('', '–'), ('recommend', 'recommended')], db_index=True, max_length=128),
+        ),
+    ]
index 739ad78..d964762 100644 (file)
@@ -17,6 +17,10 @@ class Collection(models.Model):
     book_slugs = models.TextField(_('book slugs'))
     kind = models.CharField(_('kind'), max_length=10, blank=False, default='book', db_index=True,
                             choices=(('book', _('book')), ('picture', _('picture'))))
+    role = models.CharField(max_length=128, blank=True, db_index=True, choices=[
+        ('', '–'),
+        ('recommend', _('recommended')),
+    ])
 
     class Meta:
         ordering = ('title',)
index aeed403..ef2527b 100644 (file)
@@ -449,7 +449,7 @@ def tag_catalogue(request, category):
 
 
 def collections(request):
-    objects = Collection.objects.all()
+    objects = Collection.objects.filter(role='')
 
     if len(objects) > 3:
         best = random.sample(list(objects), 3)
index 415a4fd..1c0f40c 100644 (file)
@@ -52,7 +52,21 @@ def main_page(request):
     except IndexError:
         pass
 
-    ctx['best'] = Book.objects.filter(findable=True).order_by('?')[:5]
+    best = []
+    best_places = 5
+    for recommended in Collection.objects.filter(role='recommend').order_by('?'):
+        books = list(recommended.get_books().exclude(id__in=[b.id for b in best]).order_by('?')[:best_places])
+        best.extend(books)
+        best_places -= len(books)
+        if not best_places:
+            break
+    if best_places:
+        best.extend(
+            list(
+                Book.objects.filter(findable=True).exclude(id__in=[b.id for b in best]).order_by('?')[:best_places]
+            )
+        )
+    ctx['best'] = best
 
     return render(request, "main_page.html", ctx)