Merge pull request #849 from mouse-reeve/ui-small-fixes

UI small fixes
This commit is contained in:
Mouse Reeve 2021-04-02 07:37:31 -07:00 committed by GitHub
commit 6211e66a5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 53 additions and 41 deletions

View file

@ -71,6 +71,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
if self.deleted: if self.deleted:
notification_model.objects.filter(related_status=self).delete() notification_model.objects.filter(related_status=self).delete()
return
if ( if (
self.reply_parent self.reply_parent

View file

@ -3,7 +3,7 @@
{% load humanize %} {% load humanize %}
<div class="columns is-mobile scroll-x mb-0"> <div class="columns is-mobile scroll-x mb-0">
{% for user in suggested_users %} {% for user in suggested_users %}
<div class="column is-flex"> <div class="column is-flex is-flex-grow-0">
<div class="box has-text-centered is-shadowless has-background-white-bis m-0"> <div class="box has-text-centered is-shadowless has-background-white-bis m-0">
<a href="{{ user.local_path }}" class="has-text-black"> <a href="{{ user.local_path }}" class="has-text-black">
{% include 'snippets/avatar.html' with user=user large=True %} {% include 'snippets/avatar.html' with user=user large=True %}

View file

@ -87,11 +87,6 @@
{% trans "Direct Messages" %} {% trans "Direct Messages" %}
</a> </a>
</li> </li>
<li>
<a href="{{ request.user.local_path }}" class="navbar-item">
{% trans 'Profile' %}
</a>
</li>
<li> <li>
<a href="{% url 'directory' %}" class="navbar-item"> <a href="{% url 'directory' %}" class="navbar-item">
{% trans 'Directory' %} {% trans 'Directory' %}

View file

@ -79,6 +79,8 @@
{# accepted #} {# accepted #}
{% if req.invite.invitees.exists %} {% if req.invite.invitees.exists %}
<a href="{{ req.invite.invitees.first.local_path }}">@{{ req.invite.invitees.first.localname }}</a> <a href="{{ req.invite.invitees.first.local_path }}">@{{ req.invite.invitees.first.localname }}</a>
{% else %}
&nbsp;
{% endif %} {% endif %}
{% else %} {% else %}
<form name="ignore-request" method="post" action="{% url 'settings-invite-requests-ignore' %}"> <form name="ignore-request" method="post" action="{% url 'settings-invite-requests-ignore' %}">

View file

@ -0,0 +1,7 @@
{% load humanize %}
{% load i18n %}
{% if total_pages %}
{% blocktrans with page=page|intcomma total_pages=total_pages|intcomma %}page {{ page }} of {{ total_pages }}{% endblocktrans %}
{% else %}
{% blocktrans with page=page|intcomma %}page {{ page }}{% endblocktrans %}
{% endif %}

View file

@ -9,8 +9,18 @@
</dl> </dl>
<ul> <ul>
{% if readthrough.finish_date or readthrough.progress %} {% if readthrough.finish_date or readthrough.progress %}
<li>{% if readthrough.finish_date %} {{ readthrough.finish_date | localtime | naturalday }}: {% trans "finished" %} {% else %}{% if readthrough.progress_mode == 'PG' %}on page {{ readthrough.progress }}{% if book.pages %} of {{ book.pages }}{% endif %} <li>
{% else %}{{ readthrough.progress }}%{% endif %}{% endif %} {% if readthrough.finish_date %}
{{ readthrough.finish_date | localtime | naturalday }}: {% trans "finished" %}
{% else %}
{% if readthrough.progress_mode == 'PG' %}
{% include 'snippets/page_text.html' with page=readthrough.progress total_pages=book.pages %}
{% else %}
{{ readthrough.progress }}%
{% endif %}
{% endif %}
{% if readthrough.progress %} {% if readthrough.progress %}
{% trans "Show all updates" as button_text %} {% trans "Show all updates" as button_text %}
{% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="updates" controls_uid=readthrough.id class="is-small" %} {% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="updates" controls_uid=readthrough.id class="is-small" %}
@ -21,7 +31,7 @@
{% csrf_token %} {% csrf_token %}
{{ progress_update.created_date | naturalday }}: {{ progress_update.created_date | naturalday }}:
{% if progress_update.mode == 'PG' %} {% if progress_update.mode == 'PG' %}
page {{ progress_update.progress }} of {{ book.pages }} {% include 'snippets/page_text.html' with page=progress_update.progress total_pages=book.pages %}
{% else %} {% else %}
{{ progress_update.progress }}% {{ progress_update.progress }}%
{% endif %} {% endif %}

View file

@ -7,17 +7,15 @@
{% block dropdown-list %} {% block dropdown-list %}
{% for shelf in request.user.shelf_set.all %} {% for shelf in request.user.shelf_set.all %}
{% if shelf.identifier != current.identifier %}
<li role="menuitem"> <li role="menuitem">
<form class="dropdown-item pt-0 pb-0" name="shelve" action="/shelve/" method="post"> <form class="dropdown-item pt-0 pb-0" name="shelve" action="/shelve/" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}"> <input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="change-shelf-from" value="{{ current.identifier }}"> <input type="hidden" name="change-shelf-from" value="{{ current.identifier }}">
<input type="hidden" name="shelf" value="{{ shelf.identifier }}"> <input type="hidden" name="shelf" value="{{ shelf.identifier }}">
<button class="button is-fullwidth is-small" type="submit">{{ shelf.name }}</button> <button class="button is-fullwidth is-small shelf-option" type="submit" {% if shelf.identifier == current.identifier %}disabled{% endif %}><span>{{ shelf.name }}</span></button>
</form> </form>
</li> </li>
{% endif %}
{% endfor %} {% endfor %}
<li class="navbar-divider" role="presentation"></li> <li class="navbar-divider" role="presentation"></li>
<li> <li>

View file

@ -38,6 +38,6 @@
{% if status.progress %} {% if status.progress %}
<p class="help"> <p class="help">
({% if status.progress_mode == 'PG' %}page {{ status.progress }}{%else %}{{ status.progress }}%{% endif %}) ({% if status.progress_mode == 'PG' %}{% include 'snippets/page_text.html' with page=status.progress total_pages=status.book.pages %}{% else %}{{ status.progress }}%{% endif %})
</p> </p>
{% endif %} {% endif %}

View file

@ -111,12 +111,14 @@
{% endif %} {% endif %}
{% if shelf.user == request.user %} {% if shelf.user == request.user %}
<td> <td>
{% with right=True %}
{% if not shelf.id %} {% if not shelf.id %}
{% active_shelf book as current %} {% active_shelf book as current %}
{% include 'snippets/shelf_selector.html' with current=current.shelf class="is-small" %} {% include 'snippets/shelf_selector.html' with current=current.shelf class="is-small" %}
{% else %} {% else %}
{% include 'snippets/shelf_selector.html' with current=shelf class="is-small" %} {% include 'snippets/shelf_selector.html' with current=shelf class="is-small" %}
{% endif %} {% endif %}
{% endwith %}
</td> </td>
{% endif %} {% endif %}
</tr> </tr>

View file

@ -247,7 +247,7 @@ class ViewsHelpers(TestCase):
) )
self.assertFalse(views.helpers.object_visible_to_user(self.local_user, obj)) self.assertFalse(views.helpers.object_visible_to_user(self.local_user, obj))
def test_get_suggested_users(self, _): def test_get_annotated_users(self, _):
""" list of people you might know """ """ list of people you might know """
user_1 = models.User.objects.create_user( user_1 = models.User.objects.create_user(
"nutria@local.com", "nutria@local.com",
@ -279,7 +279,7 @@ class ViewsHelpers(TestCase):
user=user_1, book=self.book, shelf=user_1.shelf_set.first() user=user_1, book=self.book, shelf=user_1.shelf_set.first()
) )
result = views.helpers.get_suggested_users(self.local_user) result = views.helpers.get_annotated_users(self.local_user)
self.assertEqual(result.count(), 3) self.assertEqual(result.count(), 3)
self.assertTrue(user_1 in result) self.assertTrue(user_1 in result)
self.assertFalse(user_2 in result) self.assertFalse(user_2 in result)
@ -294,7 +294,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(remote_user_annotated.mutuals, 0) self.assertEqual(remote_user_annotated.mutuals, 0)
self.assertEqual(remote_user_annotated.shared_books, 0) self.assertEqual(remote_user_annotated.shared_books, 0)
def test_get_suggested_users_counts(self, _): def test_get_annotated_users_counts(self, _):
""" correct counting for multiple shared attributed """ """ correct counting for multiple shared attributed """
user_1 = models.User.objects.create_user( user_1 = models.User.objects.create_user(
"nutria@local.com", "nutria@local.com",
@ -330,7 +330,7 @@ class ViewsHelpers(TestCase):
user=user_1, book=book, shelf=user_1.shelf_set.first() user=user_1, book=book, shelf=user_1.shelf_set.first()
) )
result = views.helpers.get_suggested_users( result = views.helpers.get_annotated_users(
self.local_user, self.local_user,
~Q(id=self.local_user.id), ~Q(id=self.local_user.id),
~Q(followers=self.local_user), ~Q(followers=self.local_user),

View file

@ -6,7 +6,7 @@ from django.template.response import TemplateResponse
from django.views import View from django.views import View
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from .helpers import get_suggested_users from .helpers import get_annotated_users
# pylint: disable=no-self-use # pylint: disable=no-self-use
@method_decorator(login_required, name="dispatch") @method_decorator(login_required, name="dispatch")
@ -29,7 +29,7 @@ class Directory(View):
if scope == "local": if scope == "local":
filters["local"] = True filters["local"] = True
users = get_suggested_users(request.user, **filters) users = get_annotated_users(request.user, **filters)
sort = request.GET.get("sort") sort = request.GET.get("sort")
if sort == "recent": if sort == "recent":
users = users.order_by("-last_active_date") users = users.order_by("-last_active_date")

View file

@ -34,16 +34,7 @@ class Feed(View):
paginated = Paginator(activities, PAGE_LENGTH) paginated = Paginator(activities, PAGE_LENGTH)
suggested_users = ( suggested_users = get_suggested_users(request.user)
get_suggested_users(
request.user,
~Q(id=request.user.id),
~Q(followers=request.user),
bookwyrm_user=True,
)
.order_by("-mutuals", "-last_active_date")
.all()[:5]
)
data = { data = {
**feed_page_data(request.user), **feed_page_data(request.user),

View file

@ -120,17 +120,8 @@ class GetStartedUsers(View):
) )
if user_results.count() < 5: if user_results.count() < 5:
suggested_users = ( suggested_users = get_suggested_users(request.user)
get_suggested_users(
request.user,
~Q(id=request.user.id),
~Q(followers=request.user),
~Q(id__in=user_results),
bookwyrm_user=True,
)
.order_by("shared_books", "-mutuals", "-last_active_date")
.all()[: 5 - user_results.count()]
)
data = { data = {
"suggested_users": list(user_results) + list(suggested_users), "suggested_users": list(user_results) + list(suggested_users),
} }

View file

@ -192,7 +192,22 @@ def get_discover_books():
) )
def get_suggested_users(user, *args, **kwargs): def get_suggested_users(user):
""" bookwyrm users you don't already know """
return (
get_annotated_users(
user,
~Q(id=user.id),
~Q(followers=user),
~Q(follower_requests=user),
bookwyrm_user=True,
)
.order_by("-mutuals", "-last_active_date")
.all()[:5]
)
def get_annotated_users(user, *args, **kwargs):
""" Users, annotated with things they have in common """ """ Users, annotated with things they have in common """
return ( return (
models.User.objects.filter(discoverable=True, is_active=True, *args, **kwargs) models.User.objects.filter(discoverable=True, is_active=True, *args, **kwargs)