From 251b72488d27f769ed0574f39a91f5d2da3d27a6 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 5 May 2021 10:03:13 +0200 Subject: [PATCH 1/1] Unlisted collections. --- src/catalogue/admin.py | 1 + src/catalogue/api/views.py | 2 +- src/catalogue/locale/pl/LC_MESSAGES/django.mo | Bin 12599 -> 12633 bytes src/catalogue/locale/pl/LC_MESSAGES/django.po | 19 +++++++++--------- .../migrations/0032_collection_listed.py | 18 +++++++++++++++++ src/catalogue/models/collection.py | 1 + src/catalogue/views.py | 4 ++-- src/wolnelektury/views.py | 4 ++-- 8 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 src/catalogue/migrations/0032_collection_listed.py diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index adc2eaf74..997dd5ed0 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -43,6 +43,7 @@ class FragmentAdmin(admin.ModelAdmin): class CollectionAdmin(admin.ModelAdmin): + list_display = ('title', 'listed') prepopulated_fields = {'slug': ('title',)} diff --git a/src/catalogue/api/views.py b/src/catalogue/api/views.py index bcfe0adfb..885df24aa 100644 --- a/src/catalogue/api/views.py +++ b/src/catalogue/api/views.py @@ -27,7 +27,7 @@ book_tag_categories = ['author', 'epoch', 'kind', 'genre'] class CollectionList(ListAPIView): - queryset = Collection.objects.all() + queryset = Collection.objects.filter(listed=True) serializer_class = serializers.CollectionListSerializer diff --git a/src/catalogue/locale/pl/LC_MESSAGES/django.mo b/src/catalogue/locale/pl/LC_MESSAGES/django.mo index edd1fa1ac71acfd61d0504bf7a3eae3775e758b0..4ce940facc694332c68b83787a8c6e0fe16d4fb2 100644 GIT binary patch delta 3667 zcmXxm3v7;89LMqV(pGhS-&S3!tm;;ys8{PA!fIjSk{QC>ieh7pFqaMEkrWd)%%irU zvy6ziZ0L-x?pBv>6W3tIW=3Lybrv=e+xOS^zot(=&pFSz{LlZK=V9--E91QDNl}H4 zpK`9}x$H{z!DLE>>VQjH}_?bC`q)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bo0nSI}3Ax1-l**OX;VY|eMNM3e8gLBtOq?>W zqjvB&>fwuETiQrV)O^{fXQ2=^z6UD6KB$cK#|XXuBPeJ`qfrAUqXx`E4VZ_ua4~9u zPf&raL5c0!MngWkRJ&XYyfN`nhzktGc8rtC&>v$2BfnQK(eaqS(pfdI^ z>TU7041Y)xkT=ogq28L;P)9Wqb#xQ09zxB#2o>=1=M7)epbt$cYJubCkEjVRVsE^U zN@eF(;hhwr7Ai(%ZU`#i38+lXM2%m9T5tm@fPJWdLq{lRz!lVoY2mX< zLrqkK3iNHPgCCePk$-M3e{>|9Q2|t-HgpoTfwQPjZ&K@L_d~9Lf+Ff^_6y%|15tsD zLY>({)DAqXiVFq`k=#S%6X9ZB4DUD#b-(8`Isg6?^zDBO^|Vew zrFcFnrOQ#7*nrAFsog(e_s?4Wmes3KJB~;XXVj0HC&lWysErk2BdM9ksCnRKFtBdgC&A z|0hxi(GZE%n2k@YL%a6jg$uDB?cGq3_d*@j01V)8YoBb+LM^ZmHScHUI#hTe z9Vi4S6rv{VjauM!Yafc5U@R&#(@;D67!{Cbu14*AJqB?T>fzmo3go*G)Io$$u`V;gRxUdp9UfqwhFRsMY6_ud(Qtarm7;ob3P#eGYA z9@lEF{#;7LK(2BxI}j7Mmy+J&H@NgW8HOAU3C#6v@oolk;&#whZ0!@wS-9KFj814# zVJ!=2~$nr^@favU|bDQDyg9O!4`%Gdt!dXJ-}U=C{qtE*qaTFIZO7 HVUX{CU=whV diff --git a/src/catalogue/locale/pl/LC_MESSAGES/django.po b/src/catalogue/locale/pl/LC_MESSAGES/django.po index 3dc983240..eb9230335 100644 --- a/src/catalogue/locale/pl/LC_MESSAGES/django.po +++ b/src/catalogue/locale/pl/LC_MESSAGES/django.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: WolneLektury\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2021-01-27 10:47+0100\n" +"PO-Revision-Date: 2021-05-05 10:02+0200\n" "Last-Translator: Radek Czajka \n" "Language-Team: Fundacja Nowoczesna Polska \n" @@ -195,7 +195,7 @@ msgstr "dodatkowe informacje" msgid "print on demand" msgstr "druk na żądanie" -#: catalogue/models/book.py:73 catalogue/models/collection.py:22 +#: catalogue/models/book.py:73 catalogue/models/collection.py:23 msgid "recommended" msgstr "polecane" @@ -253,11 +253,11 @@ msgstr "Utwór \"%s\" nie istnieje." msgid "Book %s already exists" msgstr "Książka %s już istnieje" -#: catalogue/models/book.py:853 +#: catalogue/models/book.py:857 msgid "This work needs modernisation" msgstr "Ten utwór wymaga uwspółcześnienia" -#: catalogue/models/book.py:932 catalogue/models/bookmedia.py:33 +#: catalogue/models/book.py:936 catalogue/models/bookmedia.py:33 #, python-format msgid "%s file" msgstr "plik %s" @@ -299,11 +299,15 @@ msgstr "rodzaj" msgid "picture" msgstr "obraz" -#: catalogue/models/collection.py:27 +#: catalogue/models/collection.py:20 +msgid "listed" +msgstr "na liście" + +#: catalogue/models/collection.py:28 msgid "collection" msgstr "kolekcja" -#: catalogue/models/collection.py:28 +#: catalogue/models/collection.py:29 msgid "collections" msgstr "kolekcje" @@ -990,9 +994,6 @@ msgstr "Błąd podczas importowania pliku: %r" #~ msgid "for advanced usage" #~ msgstr "do zadań specjalnych" -#~ msgid "Listen" -#~ msgstr "Słuchaj" - #~ msgid "See" #~ msgstr "Zobacz" diff --git a/src/catalogue/migrations/0032_collection_listed.py b/src/catalogue/migrations/0032_collection_listed.py new file mode 100644 index 000000000..52c9ccd02 --- /dev/null +++ b/src/catalogue/migrations/0032_collection_listed.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.19 on 2021-05-05 07:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0031_auto_20210316_1446'), + ] + + operations = [ + migrations.AddField( + model_name='collection', + name='listed', + field=models.BooleanField(db_index=True, default=True, verbose_name='listed'), + ), + ] diff --git a/src/catalogue/models/collection.py b/src/catalogue/models/collection.py index d964762ba..6f956c73e 100644 --- a/src/catalogue/models/collection.py +++ b/src/catalogue/models/collection.py @@ -17,6 +17,7 @@ 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')))) + listed = models.BooleanField(_('listed'), default=True, db_index=True) role = models.CharField(max_length=128, blank=True, db_index=True, choices=[ ('', '–'), ('recommend', _('recommended')), diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 398c61cc4..904cdc531 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -36,7 +36,7 @@ def catalogue(request): return render(request, 'catalogue/catalogue.html', { 'books': Book.objects.filter(findable=True, parent=None), 'pictures': Picture.objects.all(), - 'collections': Collection.objects.all(), + 'collections': Collection.objects.filter(listed=True), 'active_menu_item': 'all_works', }) @@ -452,7 +452,7 @@ def tag_catalogue(request, category): def collections(request): - objects = Collection.objects.all() + objects = Collection.objects.filter(listed=True) if len(objects) > 3: best = random.sample(list(objects), 3) diff --git a/src/wolnelektury/views.py b/src/wolnelektury/views.py index 1c0f40cd3..48063d29b 100644 --- a/src/wolnelektury/views.py +++ b/src/wolnelektury/views.py @@ -48,13 +48,13 @@ def main_page(request): # Choose a collection for main. try: - ctx['collection'] = Collection.objects.order_by('?')[:1][0] + ctx['collection'] = Collection.objects.filter(listed=True).order_by('?')[:1][0] except IndexError: pass best = [] best_places = 5 - for recommended in Collection.objects.filter(role='recommend').order_by('?'): + for recommended in Collection.objects.filter(listed=True, 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) -- 2.20.1