mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Filter editions
This commit is contained in:
parent
769ba6466c
commit
9c798a4feb
3 changed files with 16 additions and 3 deletions
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue