mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Merge pull request #818 from mouse-reeve/editions-page
Editions page refactor
This commit is contained in:
commit
a96761b587
16 changed files with 194 additions and 93 deletions
|
@ -76,24 +76,7 @@
|
|||
{% endif %}
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
{% 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 %}
|
||||
</p>
|
||||
<p>
|
||||
{% 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 %}
|
||||
</p>
|
||||
{% include 'book/publisher_info.html' with book=book %}
|
||||
|
||||
{% if book.openlibrary_key %}
|
||||
<p><a href="https://openlibrary.org/books/{{ book.openlibrary_key }}" target="_blank" rel="noopener">{% trans "View on OpenLibrary" %}</a></p>
|
||||
|
|
6
bookwyrm/templates/book/edition_filters.html
Normal file
6
bookwyrm/templates/book/edition_filters.html
Normal file
|
@ -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 %}
|
36
bookwyrm/templates/book/editions.html
Normal file
36
bookwyrm/templates/book/editions.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
|
||||
{% block title %}{% blocktrans with book_title=work.title %}Editions of {{ book_title }}{% endblocktrans %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="block">
|
||||
<h1 class="title">{% blocktrans with work_path=work.local_path work_title=work.title %}Editions of <a href="{{ work_path }}">"{{ work_title }}"</a>{% endblocktrans %}</h1>
|
||||
</div>
|
||||
|
||||
{% include 'book/edition_filters.html' %}
|
||||
|
||||
<div class="block">
|
||||
{% for book in editions %}
|
||||
<div class="columns">
|
||||
<div class="column is-2">
|
||||
<a href="/book/{{ book.id }}">
|
||||
{% include 'snippets/book_cover.html' with book=book size="medium" %}
|
||||
</a>
|
||||
</div>
|
||||
<div class="column is-7">
|
||||
<h2 class="title is-5">
|
||||
<a href="/book/{{ book.id }}" class="has-text-black">
|
||||
{{ book.title }}
|
||||
</a>
|
||||
</h2>
|
||||
{% include 'book/publisher_info.html' with book=book %}
|
||||
</div>
|
||||
<div class="column is-3">
|
||||
{% include 'snippets/shelve_button/shelve_button.html' with book=book switch_mode=True %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
16
bookwyrm/templates/book/format_filter.html
Normal file
16
bookwyrm/templates/book/format_filter.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<label class="label is-block" for="id_format">{% trans "Format:" %}</label>
|
||||
<div class="select">
|
||||
<select id="id_format" name="format">
|
||||
<option value="">{% trans "Any" %}</option>
|
||||
{% for format in formats %}{% if format %}
|
||||
<option value="{{ format }}" {% if request.GET.format == format %}selected{% endif %}>
|
||||
{{ format|title }}
|
||||
</option>
|
||||
{% endif %}{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endblock %}
|
16
bookwyrm/templates/book/language_filter.html
Normal file
16
bookwyrm/templates/book/language_filter.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<label class="label is-block" for="id_language">{% trans "Language:" %}</label>
|
||||
<div class="select">
|
||||
<select id="id_language" name="language">
|
||||
<option value="">{% trans "Any" %}</option>
|
||||
{% for language in languages %}
|
||||
<option value="{{ language }}" {% if request.GET.language == language %}selected{% endif %}>
|
||||
{{ language }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endblock %}
|
24
bookwyrm/templates/book/publisher_info.html
Normal file
24
bookwyrm/templates/book/publisher_info.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% load i18n %}
|
||||
<p>
|
||||
{% 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 %}
|
||||
</p>
|
||||
{% if book.languages %}
|
||||
<p>
|
||||
{% blocktrans with languages=book.languages|join:", " %}{{ languages }} language{% endblocktrans %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
{% 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 %}
|
||||
</p>
|
14
bookwyrm/templates/directory/community_filter.html
Normal file
14
bookwyrm/templates/directory/community_filter.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<legend class="label">{% trans "Community" %}</legend>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="scope" value="local" {% if request.GET.scope == "local" %}checked{% endif %}>
|
||||
{% trans "Local users" %}
|
||||
</label>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="scope" value="federated" {% if not request.GET.sort or request.GET.scope == "federated" %}checked{% endif %}>
|
||||
{% trans "Federated community" %}
|
||||
</label>
|
||||
{% endblock %}
|
|
@ -36,64 +36,7 @@
|
|||
</div></div>
|
||||
{% endif %}
|
||||
|
||||
<div class="notification content">
|
||||
<h2 class="columns is-mobile mb-0">
|
||||
<span class="column pb-0">Filters</span>
|
||||
|
||||
<span class="column is-narrow pb-0">
|
||||
{% 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" %}
|
||||
</span>
|
||||
</h2>
|
||||
|
||||
<form class="hidden mt-3" id="filters" method-"get" action="{% url 'directory' %}" tabindex="0">
|
||||
<div class="columns">
|
||||
<div class="column is-flex">
|
||||
<div class="box is-flex-grow-1">
|
||||
<legend class="label">{% trans "User type" %}</legend>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="software" value="bookwyrm" {% if not request.GET.sort or request.GET.software == 'bookwyrm' %}checked{% endif %}>
|
||||
{% trans "BookWyrm users" %}
|
||||
</label>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="software" value="all" {% if request.GET.software == 'all' %}checked{% endif %}>
|
||||
{% trans "All known users" %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-flex">
|
||||
<div class="box is-flex-grow-1">
|
||||
<legend class="label">{% trans "Community" %}</legend>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="scope" value="local" {% if request.GET.scope == "local" %}checked{% endif %}>
|
||||
{% trans "Local users" %}
|
||||
</label>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="scope" value="federated" {% if not request.GET.sort or request.GET.scope == "federated" %}checked{% endif %}>
|
||||
{% trans "Federated community" %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-flex">
|
||||
<div class="box is-flex-grow-1">
|
||||
<label class="label" for="id_sort">{% trans "Order by" %}</label>
|
||||
<div class="select">
|
||||
<select name="sort" id="id_sort">
|
||||
<option value="suggested" {% if not request.GET.sort or request.GET.sort == "suggested" %}checked{% endif %}>{% trans "Suggested" %}</option>
|
||||
<option value="recent" {% if request.GET.sort == "suggested" %}checked{% endif %}>{% trans "Recently active" %}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="button is-primary">{% trans "Apply filters" %}</button>
|
||||
</form>
|
||||
{% if request.GET %}
|
||||
<a class="help" href="{% url 'directory' %}">{% trans "Clear filters" %}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% include 'directory/filters.html' %}
|
||||
|
||||
<div class="columns is-multiline">
|
||||
{% for user in users %}
|
7
bookwyrm/templates/directory/filters.html
Normal file
7
bookwyrm/templates/directory/filters.html
Normal file
|
@ -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 %}
|
12
bookwyrm/templates/directory/sort_filter.html
Normal file
12
bookwyrm/templates/directory/sort_filter.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<label class="label" for="id_sort">{% trans "Order by" %}</label>
|
||||
<div class="select">
|
||||
<select name="sort" id="id_sort">
|
||||
<option value="suggested" {% if not request.GET.sort or request.GET.sort == "suggested" %}checked{% endif %}>{% trans "Suggested" %}</option>
|
||||
<option value="recent" {% if request.GET.sort == "suggested" %}checked{% endif %}>{% trans "Recently active" %}</option>
|
||||
</select>
|
||||
</div>
|
||||
{% endblock %}
|
14
bookwyrm/templates/directory/user_type_filter.html
Normal file
14
bookwyrm/templates/directory/user_type_filter.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<legend class="label">{% trans "User type" %}</legend>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="software" value="bookwyrm" {% if not request.GET.sort or request.GET.software == 'bookwyrm' %}checked{% endif %}>
|
||||
{% trans "BookWyrm users" %}
|
||||
</label>
|
||||
<label class="is-block">
|
||||
<input type="radio" class="radio" name="software" value="all" {% if request.GET.software == 'all' %}checked{% endif %}>
|
||||
{% trans "All known users" %}
|
||||
</label>
|
||||
{% endblock %}
|
|
@ -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 %}
|
||||
<div class="block">
|
||||
<h1 class="title">{% blocktrans with work_path=work.local_path work_title=work.title %}Editions of <a href="{{ work_path }}">"{{ work_title }}"</a>{% endblocktrans %}</h1>
|
||||
|
||||
{% include 'snippets/book_tiles.html' with books=editions %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<div class="column is-flex">
|
||||
<div class="box is-flex-grow-1">
|
||||
{% block filter %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
25
bookwyrm/templates/snippets/filters_panel/filters_panel.html
Normal file
25
bookwyrm/templates/snippets/filters_panel/filters_panel.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
{% load i18n %}
|
||||
<div class="notification content">
|
||||
<h2 class="columns is-mobile mb-0">
|
||||
<span class="column pb-0">Filters</span>
|
||||
|
||||
<span class="column is-narrow pb-0">
|
||||
{% 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" %}
|
||||
</span>
|
||||
</h2>
|
||||
|
||||
<form class="hidden mt-3" id="filters" method-"get" action="{{ request.path }}" tabindex="0">
|
||||
<div class="columns">
|
||||
{% block filter_fields %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
<button class="button is-primary">{% trans "Apply filters" %}</button>
|
||||
</form>
|
||||
|
||||
{% if request.GET %}
|
||||
<a class="help" href="{{ request.path }}">{% trans "Clear filters" %}</a>
|
||||
{% endif %}
|
||||
</div>
|
|
@ -252,12 +252,25 @@ 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": work.editions.order_by("-edition_rank").all(),
|
||||
"editions": editions.filter(**filters).all(),
|
||||
"work": work,
|
||||
"languages": languages,
|
||||
"formats": set(
|
||||
e.physical_format.lower() for e in editions if e.physical_format
|
||||
),
|
||||
}
|
||||
return TemplateResponse(request, "editions.html", data)
|
||||
return TemplateResponse(request, "book/editions.html", data)
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
|
@ -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 """
|
||||
|
|
Loading…
Reference in a new issue