From d18f17e7a8bdcafd4ef341b1cbe90c5c275a9dcb Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 28 Oct 2022 15:29:48 +0200 Subject: [PATCH] Collections pages. --- .../0040_alter_collection_description.py | 19 +++++++ .../0041_alter_collection_authors.py | 18 +++++++ src/catalogue/models/collection.py | 5 +- .../catalogue/2022/author_detail.html | 15 ++---- .../templates/catalogue/2022/collection.html | 50 +++++++++++++++++++ .../templates/catalogue/2022/collections.html | 38 ++++++++++++++ src/catalogue/views.py | 13 ++++- .../0015_alter_carousel_placement.py | 18 +++++++ src/wolnelektury/static/2021/scripts/main.js | 11 ++-- 9 files changed, 169 insertions(+), 18 deletions(-) create mode 100644 src/catalogue/migrations/0040_alter_collection_description.py create mode 100644 src/catalogue/migrations/0041_alter_collection_authors.py create mode 100644 src/catalogue/templates/catalogue/2022/collection.html create mode 100644 src/catalogue/templates/catalogue/2022/collections.html create mode 100644 src/social/migrations/0015_alter_carousel_placement.py diff --git a/src/catalogue/migrations/0040_alter_collection_description.py b/src/catalogue/migrations/0040_alter_collection_description.py new file mode 100644 index 000000000..eb47756db --- /dev/null +++ b/src/catalogue/migrations/0040_alter_collection_description.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.8 on 2022-10-28 13:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0039_collection_authors'), + ] + + operations = [ + migrations.AlterField( + model_name='collection', + name='description', + field=models.TextField(blank=True, default='', verbose_name='description'), + preserve_default=False, + ), + ] diff --git a/src/catalogue/migrations/0041_alter_collection_authors.py b/src/catalogue/migrations/0041_alter_collection_authors.py new file mode 100644 index 000000000..2feb345d6 --- /dev/null +++ b/src/catalogue/migrations/0041_alter_collection_authors.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.8 on 2022-10-28 13:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0040_alter_collection_description'), + ] + + operations = [ + migrations.AlterField( + model_name='collection', + name='authors', + field=models.ManyToManyField(blank=True, limit_choices_to={'category': 'author'}, to='catalogue.tag'), + ), + ] diff --git a/src/catalogue/models/collection.py b/src/catalogue/models/collection.py index 75c56ea99..412a976d4 100644 --- a/src/catalogue/models/collection.py +++ b/src/catalogue/models/collection.py @@ -13,11 +13,12 @@ class Collection(models.Model): """A collection of books, which might be defined before publishing them.""" title = models.CharField(_('title'), max_length=120, db_index=True) slug = models.SlugField(_('slug'), max_length=120, primary_key=True) - description = models.TextField(_('description'), null=True, blank=True) + description = models.TextField(_('description'), blank=True) book_slugs = models.TextField(_('book slugs')) authors = models.ManyToManyField( 'Tag', - limit_choices_to={'category': 'author'} + limit_choices_to={'category': 'author'}, + blank=True ) kind = models.CharField(_('kind'), max_length=10, blank=False, default='book', db_index=True, choices=(('book', _('book')), ('picture', _('picture')))) diff --git a/src/catalogue/templates/catalogue/2022/author_detail.html b/src/catalogue/templates/catalogue/2022/author_detail.html index d32c01204..17514ed98 100644 --- a/src/catalogue/templates/catalogue/2022/author_detail.html +++ b/src/catalogue/templates/catalogue/2022/author_detail.html @@ -2,17 +2,13 @@ {% load choose_cites from social_tags %} -{% block global-content %} -
- -
-
+{% block breadcrumbs %} + Katalog + Autor +{% endblock %} +{% block main %}
{% if tags.0.photo %} @@ -72,5 +68,4 @@ {% endif %}
-
{% endblock %} diff --git a/src/catalogue/templates/catalogue/2022/collection.html b/src/catalogue/templates/catalogue/2022/collection.html new file mode 100644 index 000000000..38c52d847 --- /dev/null +++ b/src/catalogue/templates/catalogue/2022/collection.html @@ -0,0 +1,50 @@ +{% extends '2022/base.html' %} + + +{% block breadcrumbs %} + Katalog + Kolekcje +{% endblock %} + + +{% block main %} + +
+
+

{{ collection.title }}

+
+
+ +
+

+ {{ collection.description|safe }} +

+
+ +
+
+
+ + +
+
+ Sortuj: +
+ + + +
+
+
+
+ +
+
+ {% for book in collection.get_books %} + {% include "catalogue/2022/book_box.html" %} + {% endfor %} +
+
+ + +{% endblock %} diff --git a/src/catalogue/templates/catalogue/2022/collections.html b/src/catalogue/templates/catalogue/2022/collections.html new file mode 100644 index 000000000..ba25bcb64 --- /dev/null +++ b/src/catalogue/templates/catalogue/2022/collections.html @@ -0,0 +1,38 @@ +{% extends '2022/base.html' %} + + +{% block breadcrumbs %} + Katalog +{% endblock %} + + +{% block main %} + +
+
+

Kolekcje

+
+
+ + {% for collection in objects %} +
+
+ +
+

+ {{ collection.description|safe }} +

+
+
+ {% for book in collection.get_books %} + {% include 'catalogue/2022/book_box.html' %} + {% endfor %} +
+
+
+ {% endfor %} + + +{% endblock %} diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 12f47a282..b57ba11b5 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -67,7 +67,11 @@ def daisy_list(request): def collection(request, slug): coll = get_object_or_404(Collection, slug=slug) - return render(request, 'catalogue/collection.html', { + if request.EXPERIMENTS['layout'].value: + template_name = 'catalogue/2022/collection.html' + else: + template_name = 'catalogue/collection.html' + return render(request, template_name, { 'collection': coll, 'active_menu_item': 'collections', }) @@ -480,7 +484,12 @@ def collections(request): else: best = objects - return render(request, 'catalogue/collections.html', { + if request.EXPERIMENTS['layout'].value: + template_name = 'catalogue/2022/collections.html' + else: + template_name = 'catalogue/collections.html' + + return render(request, template_name, { 'objects': objects, 'best': best, 'active_menu_item': 'collections' diff --git a/src/social/migrations/0015_alter_carousel_placement.py b/src/social/migrations/0015_alter_carousel_placement.py new file mode 100644 index 000000000..bce2dace6 --- /dev/null +++ b/src/social/migrations/0015_alter_carousel_placement.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.8 on 2022-10-28 13:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('social', '0014_auto_20221014_1004'), + ] + + operations = [ + migrations.AlterField( + model_name='carousel', + name='placement', + field=models.SlugField(choices=[('main', 'main'), ('main_2022', 'main 2022')], verbose_name='placement'), + ), + ] diff --git a/src/wolnelektury/static/2021/scripts/main.js b/src/wolnelektury/static/2021/scripts/main.js index 97ac9a363..21c76a023 100644 --- a/src/wolnelektury/static/2021/scripts/main.js +++ b/src/wolnelektury/static/2021/scripts/main.js @@ -152,9 +152,12 @@ shelfSlider.slick('slickPrev'); }); - let collectionsSlider = $('.js-collections .l-books'); - let collectionsNextSlide = $('.js-collections .js-next-slide'); - let collectionsPrevSlide = $('.js-collections .js-prev-slide'); + + $('.js-collections').each(function() { + let collectionsSlider = $('.l-books', this); + if ($collectionsSlider.children().length < 2) return; + let collectionsNextSlide = $('.js-next-slide', this); + let collectionsPrevSlide = $('.js-prev-slide', this); collectionsSlider.slick({ slidesToScroll: 1, @@ -183,7 +186,7 @@ event.preventDefault(); collectionsSlider.slick('slickPrev'); }); - + }); let newBooksSlider = $('.js-new-books-slider .l-books'); let newBooksNextSlide = $('.js-new-books-slider .js-next-slide'); let newBooksPrevSlide = $('.js-new-books-slider .js-prev-slide'); -- 2.20.1