diff --git a/bookwyrm/migrations/0123_alter_user_preferred_language.py b/bookwyrm/migrations/0123_alter_user_preferred_language.py new file mode 100644 index 00000000..db4c50c6 --- /dev/null +++ b/bookwyrm/migrations/0123_alter_user_preferred_language.py @@ -0,0 +1,34 @@ +# Generated by Django 3.2.5 on 2022-01-04 22:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0122_alter_annualgoal_year"), + ] + + operations = [ + migrations.AlterField( + model_name="user", + name="preferred_language", + field=models.CharField( + blank=True, + choices=[ + ("en-us", "English"), + ("de-de", "Deutsch (German)"), + ("es-es", "Español (Spanish)"), + ("gl-es", "Galego (Galician)"), + ("fr-fr", "Français (French)"), + ("lt-lt", "Lietuvių (Lithuanian)"), + ("pt-br", "Português do Brasil (Brazilian Portuguese)"), + ("pt-pt", "Português Europeu (European Portuguese)"), + ("zh-hans", "简体中文 (Simplified Chinese)"), + ("zh-hant", "繁體中文 (Traditional Chinese)"), + ], + max_length=255, + null=True, + ), + ), + ] diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 0a8e8328..f2068a16 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -168,7 +168,8 @@ LANGUAGES = [ ("gl-es", _("Galego (Galician)")), ("fr-fr", _("Français (French)")), ("lt-lt", _("Lietuvių (Lithuanian)")), - ("pt-br", _("Português - Brasil (Brazilian Portuguese)")), + ("pt-br", _("Português do Brasil (Brazilian Portuguese)")), + ("pt-pt", _("Português Europeu (European Portuguese)")), ("zh-hans", _("简体中文 (Simplified Chinese)")), ("zh-hant", _("繁體中文 (Traditional Chinese)")), ] diff --git a/bookwyrm/suggested_users.py b/bookwyrm/suggested_users.py index a4b7ca65..eb03ceae 100644 --- a/bookwyrm/suggested_users.py +++ b/bookwyrm/suggested_users.py @@ -3,7 +3,7 @@ import math import logging from django.dispatch import receiver from django.db import transaction -from django.db.models import signals, Count, Q +from django.db.models import signals, Count, Q, Case, When, IntegerField from bookwyrm import models from bookwyrm.redis_store import RedisStore, r @@ -85,24 +85,17 @@ class SuggestedUsers(RedisStore): def get_suggestions(self, user, local=False): """get suggestions""" values = self.get_store(self.store_id(user), withscores=True) - results = [] + annotations = [ + When(pk=int(pk), then=self.get_counts_from_rank(score)["mutuals"]) + for (pk, score) in values + ] # annotate users with mutuals and shared book counts - for user_id, rank in values: - counts = self.get_counts_from_rank(rank) - try: - user = models.User.objects.get( - id=user_id, is_active=True, bookwyrm_user=True - ) - except models.User.DoesNotExist as err: - # if this happens, the suggestions are janked way up - logger.exception(err) - continue - user.mutuals = counts["mutuals"] - if (local and user.local) or not local: - results.append(user) - if len(results) >= 5: - break - return results + users = models.User.objects.filter( + is_active=True, bookwyrm_user=True, id__in=[pk for (pk, _) in values] + ).annotate(mutuals=Case(*annotations, output_field=IntegerField(), default=0)) + if local: + users = users.filter(local=True) + return users[:5] def get_annotated_users(viewer, *args, **kwargs): diff --git a/bookwyrm/templates/groups/find_users.html b/bookwyrm/templates/groups/find_users.html index 377e3a0b..1b0d5433 100644 --- a/bookwyrm/templates/groups/find_users.html +++ b/bookwyrm/templates/groups/find_users.html @@ -2,8 +2,5 @@ {% load i18n %} {% block searchresults %} -
+ {% trans "Members of this group can create group-curated lists." %} +
+{% trans "This group has no lists" %}
{% else %} @@ -45,19 +49,17 @@ {{ list.name }} {% include 'snippets/privacy-icons.html' with item=list %} - {% with list_books=list.listitem_set.all|slice:5 %} - {% if list_books %} -{% trans "Members can add and remove books on a group's book lists" %}
- +{% if group.user == request.user %} +