Merge pull request #828 from mouse-reeve/lists-ui

Lists UI tweaks
This commit is contained in:
Mouse Reeve 2021-03-30 10:48:19 -07:00 committed by GitHub
commit 84c35fe570
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 23 deletions

View file

@ -1,6 +1,7 @@
""" make a list of books!! """
from django.apps import apps
from django.db import models
from django.utils import timezone
from bookwyrm import activitypub
from bookwyrm.settings import DOMAIN
@ -79,6 +80,10 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
""" create a notification too """
created = not bool(self.id)
super().save(*args, **kwargs)
# tick the updated date on the parent list
self.book_list.updated_date = timezone.now()
self.book_list.save(broadcast=False)
list_owner = self.book_list.user
# create a notification if somoene ELSE added to a local user's list
if created and list_owner.local and list_owner != self.user:

View file

@ -14,7 +14,13 @@
{% endfor %}
</div>
<div class="card-content is-flex-grow-0">
{% if list.description %}{{ list.description | to_markdown | safe | truncatewords_html:20 }}{% endif %}
<div {% if list.description %}title="{{ list.description }}"{% endif %}>
{% if list.description %}
{{ list.description|to_markdown|safe|truncatechars_html:30 }}
{% else %}
&nbsp;
{% endif %}
</div>
<p class="subtitle help">
{% include 'lists/created_text.html' with list=list %}
</p>

View file

@ -1,17 +1,19 @@
{% extends 'layout.html' %}
{% load bookwyrm_tags %}
{% load i18n %}
{% block title %}{% trans "Lists" %}{% endblock %}
{% block content %}
<header class="block">
<h1 class="title">{% trans "Lists" %}</h1>
</header>
{% if request.user.is_authenticated and not lists.has_previous %}
<header class="block columns is-mobile">
<div class="column">
<h2 class="title">{% trans "Your lists" %}</h2>
<h1 class="title">
{% trans "Lists" %}
{% if request.user.is_authenticated %}
<a class="help has-text-weight-normal" href="{% url 'user-lists' request.user|username %}">Your lists</a>
{% endif %}
</h1>
</div>
<div class="column is-narrow">
{% trans "Create List" as button_text %}
@ -23,23 +25,11 @@
{% include 'lists/create_form.html' with controls_text="create-list" %}
</div>
<section class="block content">
{% if request.user.list_set.exists %}
{% include 'lists/list_items.html' with lists=request.user.list_set.all|slice:4 %}
{% endif %}
{% if request.user.list_set.count > 4 %}
<a href="{% url 'user-lists' request.user.localname %}">{% blocktrans with size=request.user.list_set.count %}See all {{ size }} lists{% endblocktrans %}</a>
{% endif %}
</section>
{% endif %}
{% if lists %}
<section class="block content">
<h2 class="title">{% trans "Recent Lists" %}</h2>
{% include 'lists/list_items.html' with lists=lists %}
</section>
<div>
{% include 'snippets/pagination.html' with page=lists path=path %}
</div>

View file

@ -27,17 +27,17 @@ class Lists(View):
except ValueError:
page = 1
user = request.user if request.user.is_authenticated else None
# hide lists with no approved books
lists = (
models.List.objects.filter(
~Q(user=user),
models.List.objects.annotate(
item_count=Count("listitem", filter=Q(listitem__approved=True))
)
.annotate(item_count=Count("listitem", filter=Q(listitem__approved=True)))
.filter(item_count__gt=0)
.order_by("-updated_date")
.distinct()
.all()
)
lists = privacy_filter(
request.user, lists, privacy_levels=["public", "followers"]
)