From 7c9518afa6614a276de6fd762d8c1eb065ce7d38 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 29 Mar 2021 10:21:48 -0700 Subject: [PATCH 1/7] Adds info to editions page --- bookwyrm/templates/book/book.html | 19 +----------- bookwyrm/templates/book/editions.html | 33 +++++++++++++++++++++ bookwyrm/templates/book/publisher_info.html | 24 +++++++++++++++ bookwyrm/templates/editions.html | 14 --------- bookwyrm/views/books.py | 2 +- 5 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 bookwyrm/templates/book/editions.html create mode 100644 bookwyrm/templates/book/publisher_info.html delete mode 100644 bookwyrm/templates/editions.html diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index aef8fba1..95cf86ad 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -76,24 +76,7 @@ {% endif %} -

- {% if book.physical_format and not book.pages %} - {{ book.physical_format | title }} - {% elif book.physical_format and book.pages %} - {% blocktrans with format=book.physical_format|title pages=book.pages %}{{ format }}, {{ pages }} pages{% endblocktrans %} - {% elif book.pages %} - {% blocktrans with pages=book.pages %}{{ pages }} pages{% endblocktrans %} - {% endif %} -

-

- {% if book.published_date and book.publishers %} - {% blocktrans with date=book.published_date|date:'M jS Y' publisher=book.publishers|join:', ' %}Published {{ date }} by {{ publisher }}.{% endblocktrans %} - {% elif book.published_date %} - {% blocktrans with date=book.published_date|date:'M jS Y' %}Published {{ date }}{% endblocktrans %} - {% elif book.publishers %} - {% blocktrans with publisher=book.publishers|join:', ' %}Published by {{ publisher }}.{% endblocktrans %} - {% endif %} -

+ {% include 'book/publisher_info.html' with book=book %} {% if book.openlibrary_key %}

{% trans "View on OpenLibrary" %}

diff --git a/bookwyrm/templates/book/editions.html b/bookwyrm/templates/book/editions.html new file mode 100644 index 00000000..b77dc1a6 --- /dev/null +++ b/bookwyrm/templates/book/editions.html @@ -0,0 +1,33 @@ +{% extends 'layout.html' %} +{% load i18n %} +{% load bookwyrm_tags %} + +{% block title %}{% blocktrans with book_title=work.title %}Editions of {{ book_title }}{% endblocktrans %}{% endblock %} + +{% block content %} +
+

{% blocktrans with work_path=work.local_path work_title=work.title %}Editions of "{{ work_title }}"{% endblocktrans %}

+ + {% for book in editions %} +
+ +
+

+ + {{ book.title }} + +

+ {% include 'book/publisher_info.html' with book=book %} +
+
+ {% include 'snippets/shelve_button/shelve_button.html' with book=book switch_mode=True %} +
+
+ {% endfor %} +
+{% endblock %} + diff --git a/bookwyrm/templates/book/publisher_info.html b/bookwyrm/templates/book/publisher_info.html new file mode 100644 index 00000000..0ab35401 --- /dev/null +++ b/bookwyrm/templates/book/publisher_info.html @@ -0,0 +1,24 @@ +{% load i18n %} +

+ {% if book.physical_format and not book.pages %} + {{ book.physical_format | title }} + {% elif book.physical_format and book.pages %} + {% blocktrans with format=book.physical_format|title pages=book.pages %}{{ format }}, {{ pages }} pages{% endblocktrans %} + {% elif book.pages %} + {% blocktrans with pages=book.pages %}{{ pages }} pages{% endblocktrans %} + {% endif %} +

+{% if book.languages %} +

+ {% blocktrans with languages=book.languages|join:", " %}{{ languages }} language{% endblocktrans %} +

+{% endif %} +

+ {% if book.published_date and book.publishers %} + {% blocktrans with date=book.published_date|date:'M jS Y' publisher=book.publishers|join:', ' %}Published {{ date }} by {{ publisher }}.{% endblocktrans %} + {% elif book.published_date %} + {% blocktrans with date=book.published_date|date:'M jS Y' %}Published {{ date }}{% endblocktrans %} + {% elif book.publishers %} + {% blocktrans with publisher=book.publishers|join:', ' %}Published by {{ publisher }}.{% endblocktrans %} + {% endif %} +

diff --git a/bookwyrm/templates/editions.html b/bookwyrm/templates/editions.html deleted file mode 100644 index f8319757..00000000 --- a/bookwyrm/templates/editions.html +++ /dev/null @@ -1,14 +0,0 @@ -{% extends 'layout.html' %} -{% load i18n %} -{% load bookwyrm_tags %} - -{% block title %}{% blocktrans with book_title=work.title %}Editions of {{ book_title }}{% endblocktrans %}{% endblock %} - -{% block content %} -
-

{% blocktrans with work_path=work.local_path work_title=work.title %}Editions of "{{ work_title }}"{% endblocktrans %}

- - {% include 'snippets/book_tiles.html' with books=editions %} -
-{% endblock %} - diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index cabc3223..5c8eab4c 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -257,7 +257,7 @@ class Editions(View): "editions": work.editions.order_by("-edition_rank").all(), "work": work, } - return TemplateResponse(request, "editions.html", data) + return TemplateResponse(request, "book/editions.html", data) @login_required From b13e8d75cdb126ca05e19f037537ea39ef3932ca Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 29 Mar 2021 10:39:13 -0700 Subject: [PATCH 2/7] Introduces filters snippets --- .../templates/directory/community_filter.html | 14 +++++ .../templates/{ => directory}/directory.html | 59 +------------------ bookwyrm/templates/directory/filters.html | 7 +++ bookwyrm/templates/directory/sort_filter.html | 12 ++++ .../templates/directory/user_type_filter.html | 14 +++++ .../snippets/filters_panel/filter_field.html | 6 ++ .../snippets/filters_panel/filters_panel.html | 25 ++++++++ bookwyrm/views/directory.py | 2 +- 8 files changed, 80 insertions(+), 59 deletions(-) create mode 100644 bookwyrm/templates/directory/community_filter.html rename bookwyrm/templates/{ => directory}/directory.html (56%) create mode 100644 bookwyrm/templates/directory/filters.html create mode 100644 bookwyrm/templates/directory/sort_filter.html create mode 100644 bookwyrm/templates/directory/user_type_filter.html create mode 100644 bookwyrm/templates/snippets/filters_panel/filter_field.html create mode 100644 bookwyrm/templates/snippets/filters_panel/filters_panel.html diff --git a/bookwyrm/templates/directory/community_filter.html b/bookwyrm/templates/directory/community_filter.html new file mode 100644 index 00000000..bd0ba778 --- /dev/null +++ b/bookwyrm/templates/directory/community_filter.html @@ -0,0 +1,14 @@ +{% extends 'snippets/filters_panel/filter_field.html' %} +{% load i18n %} + +{% block filter %} +{% trans "Community" %} + + +{% endblock %} diff --git a/bookwyrm/templates/directory.html b/bookwyrm/templates/directory/directory.html similarity index 56% rename from bookwyrm/templates/directory.html rename to bookwyrm/templates/directory/directory.html index 3d47e26b..7413f67d 100644 --- a/bookwyrm/templates/directory.html +++ b/bookwyrm/templates/directory/directory.html @@ -36,64 +36,7 @@ {% endif %} -
-

- Filters - - - {% trans "Show filters" as text %} - {% include 'snippets/toggle/open_button.html' with text=text controls_text="filters" icon="arrow-down" class="is-small" focus="filters" %} - {% trans "Hide filters" as text %} - {% include 'snippets/toggle/close_button.html' with text=text controls_text="filters" icon="x" class="is-small" %} - -

- - - {% if request.GET %} - {% trans "Clear filters" %} - {% endif %} -
+{% include 'directory/filters.html' %}
{% for user in users %} diff --git a/bookwyrm/templates/directory/filters.html b/bookwyrm/templates/directory/filters.html new file mode 100644 index 00000000..c6bbe157 --- /dev/null +++ b/bookwyrm/templates/directory/filters.html @@ -0,0 +1,7 @@ +{% extends 'snippets/filters_panel/filters_panel.html' %} + +{% block filter_fields %} +{% include 'directory/user_type_filter.html' %} +{% include 'directory/community_filter.html' %} +{% include 'directory/sort_filter.html' %} +{% endblock %} diff --git a/bookwyrm/templates/directory/sort_filter.html b/bookwyrm/templates/directory/sort_filter.html new file mode 100644 index 00000000..82b561fb --- /dev/null +++ b/bookwyrm/templates/directory/sort_filter.html @@ -0,0 +1,12 @@ +{% extends 'snippets/filters_panel/filter_field.html' %} +{% load i18n %} + +{% block filter %} + +
+ +
+{% endblock %} diff --git a/bookwyrm/templates/directory/user_type_filter.html b/bookwyrm/templates/directory/user_type_filter.html new file mode 100644 index 00000000..b5961c82 --- /dev/null +++ b/bookwyrm/templates/directory/user_type_filter.html @@ -0,0 +1,14 @@ +{% extends 'snippets/filters_panel/filter_field.html' %} +{% load i18n %} + +{% block filter %} +{% trans "User type" %} + + +{% endblock %} diff --git a/bookwyrm/templates/snippets/filters_panel/filter_field.html b/bookwyrm/templates/snippets/filters_panel/filter_field.html new file mode 100644 index 00000000..0a8daaa1 --- /dev/null +++ b/bookwyrm/templates/snippets/filters_panel/filter_field.html @@ -0,0 +1,6 @@ +
+
+ {% block filter %} + {% endblock %} +
+
diff --git a/bookwyrm/templates/snippets/filters_panel/filters_panel.html b/bookwyrm/templates/snippets/filters_panel/filters_panel.html new file mode 100644 index 00000000..185f5bc4 --- /dev/null +++ b/bookwyrm/templates/snippets/filters_panel/filters_panel.html @@ -0,0 +1,25 @@ +{% load i18n %} +
+

+ Filters + + + {% trans "Show filters" as text %} + {% include 'snippets/toggle/open_button.html' with text=text controls_text="filters" icon="arrow-down" class="is-small" focus="filters" %} + {% trans "Hide filters" as text %} + {% include 'snippets/toggle/close_button.html' with text=text controls_text="filters" icon="x" class="is-small" %} + +

+ + + + {% if request.GET %} + {% trans "Clear filters" %} + {% endif %} +
diff --git a/bookwyrm/views/directory.py b/bookwyrm/views/directory.py index c57b47f7..b329eede 100644 --- a/bookwyrm/views/directory.py +++ b/bookwyrm/views/directory.py @@ -41,7 +41,7 @@ class Directory(View): data = { "users": paginated.page(page), } - return TemplateResponse(request, "directory.html", data) + return TemplateResponse(request, "directory/directory.html", data) def post(self, request): """ join the directory """ From 769ba6466c84654ed6fc0fb82a79b3a223e3ddf2 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 29 Mar 2021 10:58:35 -0700 Subject: [PATCH 3/7] Adds filters ui to editions page --- bookwyrm/templates/book/edition_filters.html | 6 ++++++ bookwyrm/templates/book/editions.html | 5 ++++- bookwyrm/templates/book/format_filter.html | 13 +++++++++++++ bookwyrm/templates/book/language_filter.html | 13 +++++++++++++ bookwyrm/views/books.py | 6 +++++- 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 bookwyrm/templates/book/edition_filters.html create mode 100644 bookwyrm/templates/book/format_filter.html create mode 100644 bookwyrm/templates/book/language_filter.html diff --git a/bookwyrm/templates/book/edition_filters.html b/bookwyrm/templates/book/edition_filters.html new file mode 100644 index 00000000..a55b72af --- /dev/null +++ b/bookwyrm/templates/book/edition_filters.html @@ -0,0 +1,6 @@ +{% extends 'snippets/filters_panel/filters_panel.html' %} + +{% block filter_fields %} +{% include 'book/language_filter.html' %} +{% include 'book/format_filter.html' %} +{% endblock %} diff --git a/bookwyrm/templates/book/editions.html b/bookwyrm/templates/book/editions.html index b77dc1a6..7290cce9 100644 --- a/bookwyrm/templates/book/editions.html +++ b/bookwyrm/templates/book/editions.html @@ -7,7 +7,11 @@ {% block content %}

{% blocktrans with work_path=work.local_path work_title=work.title %}Editions of "{{ work_title }}"{% endblocktrans %}

+
+{% include 'book/edition_filters.html' %} + +
{% for book in editions %}
@@ -30,4 +34,3 @@ {% endfor %}
{% endblock %} - diff --git a/bookwyrm/templates/book/format_filter.html b/bookwyrm/templates/book/format_filter.html new file mode 100644 index 00000000..7bd8f6c7 --- /dev/null +++ b/bookwyrm/templates/book/format_filter.html @@ -0,0 +1,13 @@ +{% extends 'snippets/filters_panel/filter_field.html' %} +{% load i18n %} + +{% block filter %} + +
+ +
+{% endblock %} diff --git a/bookwyrm/templates/book/language_filter.html b/bookwyrm/templates/book/language_filter.html new file mode 100644 index 00000000..fc21d5e2 --- /dev/null +++ b/bookwyrm/templates/book/language_filter.html @@ -0,0 +1,13 @@ +{% extends 'snippets/filters_panel/filter_field.html' %} +{% load i18n %} + +{% block filter %} + +
+ +
+{% endblock %} diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index 5c8eab4c..6d10e131 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -252,10 +252,14 @@ class Editions(View): if is_api_request(request): return ActivitypubResponse(work.to_edition_list(**request.GET)) + editions = work.editions.order_by("-edition_rank").all() + languages = set(sum([e.languages for e in editions], [])) data = { - "editions": work.editions.order_by("-edition_rank").all(), + "editions": editions, "work": work, + "languages": languages, + "formats": set(e.physical_format.lower() for e in editions), } return TemplateResponse(request, "book/editions.html", data) From 9c798a4feba0f172823a72d3f13a9c535f254490 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 29 Mar 2021 11:13:23 -0700 Subject: [PATCH 4/7] Filter editions --- bookwyrm/templates/book/format_filter.html | 5 ++++- bookwyrm/templates/book/language_filter.html | 5 ++++- bookwyrm/views/books.py | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/book/format_filter.html b/bookwyrm/templates/book/format_filter.html index 7bd8f6c7..05275528 100644 --- a/bookwyrm/templates/book/format_filter.html +++ b/bookwyrm/templates/book/format_filter.html @@ -5,8 +5,11 @@
diff --git a/bookwyrm/templates/book/language_filter.html b/bookwyrm/templates/book/language_filter.html index fc21d5e2..c6798a9b 100644 --- a/bookwyrm/templates/book/language_filter.html +++ b/bookwyrm/templates/book/language_filter.html @@ -5,8 +5,11 @@
diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index 6d10e131..8434cec0 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -252,11 +252,18 @@ class Editions(View): if is_api_request(request): return ActivitypubResponse(work.to_edition_list(**request.GET)) + filters = {} + + if request.GET.get("language"): + filters["languages__contains"] = [request.GET.get("language")] + if request.GET.get("format"): + filters["physical_format__iexact"] = request.GET.get("format") + editions = work.editions.order_by("-edition_rank").all() languages = set(sum([e.languages for e in editions], [])) data = { - "editions": editions, + "editions": editions.filter(**filters).all(), "work": work, "languages": languages, "formats": set(e.physical_format.lower() for e in editions), From f8a321c74d6cad8059586021da184dcccc1c70e9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 29 Mar 2021 11:16:34 -0700 Subject: [PATCH 5/7] Fixes labels Good bot --- bookwyrm/templates/book/format_filter.html | 2 +- bookwyrm/templates/book/language_filter.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/book/format_filter.html b/bookwyrm/templates/book/format_filter.html index 05275528..c722b24f 100644 --- a/bookwyrm/templates/book/format_filter.html +++ b/bookwyrm/templates/book/format_filter.html @@ -4,7 +4,7 @@ {% block filter %}
- {% for format in formats %}{% if format %}