From: Radek Czajka Date: Wed, 5 May 2021 08:03:13 +0000 (+0200) Subject: Unlisted collections. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/251b72488d27f769ed0574f39a91f5d2da3d27a6 Unlisted collections. --- 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 edd1fa1ac..4ce940fac 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 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)