Filter editions

This commit is contained in:
Mouse Reeve 2021-03-29 11:13:23 -07:00
parent 769ba6466c
commit 9c798a4feb
3 changed files with 16 additions and 3 deletions

View file

@ -5,8 +5,11 @@
<label class="label is-block" for="id_format">{% trans "Format:" %}</label>
<div class="select">
<select id="format" name="format">
<option value="">{% trans "Any" %}</option>
{% for format in formats %}{% if format %}
<option value="{{ format }}">{{ format|title }}</option>
<option value="{{ format }}" {% if request.GET.format == format %}selected{% endif %}>
{{ format|title }}
</option>
{% endif %}{% endfor %}
</select>
</div>

View file

@ -5,8 +5,11 @@
<label class="label is-block" for="id_language">{% trans "Language:" %}</label>
<div class="select">
<select id="language" name="language">
<option value="">{% trans "Any" %}</option>
{% for language in languages %}
<option value="{{ language }}">{{ language }}</option>
<option value="{{ language }}" {% if request.GET.language == language %}selected{% endif %}>
{{ language }}
</option>
{% endfor %}
</select>
</div>

View file

@ -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),