Suggest recently edited books if we're out of user books

This commit is contained in:
Mouse Reeve 2021-01-31 10:56:40 -08:00
parent 1a4c53da2c
commit 1e9189d43c
3 changed files with 20 additions and 12 deletions

View file

@ -5,7 +5,7 @@
<header class="columns content">
<div class="column">
<h1 class="title">{{ list.name }} <span class="subtitle">{% include 'snippets/privacy-icons.html' with item=list %}</span></h1>
<p class="subtitle help">Created by {% include 'snippets/username.html' with user=list.user %}</p>
<p class="subtitle help">Created {% if list.curation != 'open' %} and curated{% endif %} by {% include 'snippets/username.html' with user=list.user %}</p>
{% include 'snippets/trimmed_text.html' with full=list.description %}
</div>
{% if request.user == list.user %}
@ -64,7 +64,7 @@
{% if not list.curation == 'closed' or request.user == list.user %}
<section class="column is-one-quarter">
<h2>Add Books</h2>
<h2>{% if list.curation == 'open' or request.user == list.user %}Add{% else %}Suggest{% endif %} Books</h2>
{% for book in suggested_books %}
<div class="block columns">
<div class="column is-narrow">
@ -75,7 +75,7 @@
<form name="add-book" method="post" action="{% url 'list-add-book' list.id %}">
{% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}">
<button type="submit" class="button is-small is-link">Add</button>
<button type="submit" class="button is-small is-link">{% if list.curation == 'open' or request.user == list.user %}Add{% else %}Submit{% endif %}</button>
</form>
</div>
</div>

View file

@ -1,18 +1,18 @@
{% if item.privacy == 'public' %}
<span class="icon icon-globe" title="Public post">
<span class="is-sr-only">Public post</span>
<span class="icon icon-globe" title="Public">
<span class="is-sr-only">Public</span>
</span>
{% elif item.privacy == 'unlisted' %}
<span class="icon icon-unlock" title="Unlisted post">
<span class="is-sr-only">Unlisted post</span>
<span class="icon icon-unlock" title="Unlisted">
<span class="is-sr-only">Unlisted</span>
</span>
{% elif item.privacy == 'followers' %}
<span class="icon icon-lock" title="Followers-only post">
<span class="is-sr-only">Followers-only post</span>
<span class="icon icon-lock" title="Followers-only">
<span class="is-sr-only">Followers-only</span>
</span>
{% else %}
<span class="icon icon-envelope" title="Private post">
<span class="is-sr-only">Private post</span>
<span class="icon icon-envelope" title="Private">
<span class="is-sr-only">Private</span>
</span>
{% endif %}

View file

@ -55,11 +55,19 @@ class List(View):
suggestions = request.user.shelfbook_set.filter(
~Q(book__in=book_list.books.all())
)
suggestions = [s.book for s in suggestions[:5]]
if len(suggestions) < 5:
suggestions += [s.default_edition for s in \
models.Work.objects.filter(
~Q(editions__in=book_list.books.all()),
).order_by('-updated_date')
][:5 - len(suggestions)]
data = {
'title': '%s | Lists' % book_list.name,
'list': book_list,
'suggested_books': [s.book for s in suggestions[:5]],
'suggested_books': suggestions,
'list_form': forms.ListForm(instance=book_list),
}
return TemplateResponse(request, 'lists/list.html', data)