From: Radek Czajka Date: Fri, 18 Sep 2020 13:35:40 +0000 (+0200) Subject: Fixes #4076: Recommendations from collections. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/907aba88951334676a259dccc8f7edd8934d5e00 Fixes #4076: Recommendations from collections. --- diff --git a/src/catalogue/locale/de/LC_MESSAGES/django.po b/src/catalogue/locale/de/LC_MESSAGES/django.po index bb9fdc0cc..b78748b09 100644 --- a/src/catalogue/locale/de/LC_MESSAGES/django.po +++ b/src/catalogue/locale/de/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/catalogue/locale/en/LC_MESSAGES/django.po b/src/catalogue/locale/en/LC_MESSAGES/django.po index a16499f57..86902eba1 100644 --- a/src/catalogue/locale/en/LC_MESSAGES/django.po +++ b/src/catalogue/locale/en/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/catalogue/locale/es/LC_MESSAGES/django.po b/src/catalogue/locale/es/LC_MESSAGES/django.po index 725d2d964..826fc7a26 100644 --- a/src/catalogue/locale/es/LC_MESSAGES/django.po +++ b/src/catalogue/locale/es/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/catalogue/locale/fr/LC_MESSAGES/django.po b/src/catalogue/locale/fr/LC_MESSAGES/django.po index 96bae9f07..c8b83aabb 100644 --- a/src/catalogue/locale/fr/LC_MESSAGES/django.po +++ b/src/catalogue/locale/fr/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/catalogue/locale/it/LC_MESSAGES/django.po b/src/catalogue/locale/it/LC_MESSAGES/django.po index 489a6a8a5..9845f285e 100644 --- a/src/catalogue/locale/it/LC_MESSAGES/django.po +++ b/src/catalogue/locale/it/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/catalogue/locale/lt/LC_MESSAGES/django.po b/src/catalogue/locale/lt/LC_MESSAGES/django.po index be2d17f49..36987e9e1 100644 --- a/src/catalogue/locale/lt/LC_MESSAGES/django.po +++ b/src/catalogue/locale/lt/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/catalogue/locale/pl/LC_MESSAGES/django.mo b/src/catalogue/locale/pl/LC_MESSAGES/django.mo index b45c68d89..dfc907019 100644 Binary files a/src/catalogue/locale/pl/LC_MESSAGES/django.mo and b/src/catalogue/locale/pl/LC_MESSAGES/django.mo differ diff --git a/src/catalogue/locale/pl/LC_MESSAGES/django.po b/src/catalogue/locale/pl/LC_MESSAGES/django.po index 2cf664433..d2d3059ca 100644 --- a/src/catalogue/locale/pl/LC_MESSAGES/django.po +++ b/src/catalogue/locale/pl/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: Fundacja Nowoczesna Polska \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" diff --git a/src/catalogue/locale/ru/LC_MESSAGES/django.po b/src/catalogue/locale/ru/LC_MESSAGES/django.po index 357039e80..cd580cb57 100644 --- a/src/catalogue/locale/ru/LC_MESSAGES/django.po +++ b/src/catalogue/locale/ru/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/catalogue/locale/uk/LC_MESSAGES/django.po b/src/catalogue/locale/uk/LC_MESSAGES/django.po index 8c1160d10..2902742da 100644 --- a/src/catalogue/locale/uk/LC_MESSAGES/django.po +++ b/src/catalogue/locale/uk/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/catalogue/migrations/0030_collection_role.py b/src/catalogue/migrations/0030_collection_role.py new file mode 100644 index 000000000..6d5e8e5c6 --- /dev/null +++ b/src/catalogue/migrations/0030_collection_role.py @@ -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), + ), + ] diff --git a/src/catalogue/models/collection.py b/src/catalogue/models/collection.py index 739ad78ec..d964762ba 100644 --- a/src/catalogue/models/collection.py +++ b/src/catalogue/models/collection.py @@ -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',) diff --git a/src/catalogue/views.py b/src/catalogue/views.py index aeed403ab..ef2527b59 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -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) diff --git a/src/wolnelektury/views.py b/src/wolnelektury/views.py index 415a4fd1b..1c0f40cd3 100644 --- a/src/wolnelektury/views.py +++ b/src/wolnelektury/views.py @@ -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)