improve login auto completion

This commit is contained in:
Your Name 2023-06-29 16:09:17 -04:00 committed by Henri Dickson
parent 91d85a0a2a
commit 058adf1216
2 changed files with 8 additions and 7 deletions

View file

@ -110,7 +110,7 @@
{% else %}
<section>
<p class="empty">
<span><a href="{% url 'users:login' %}">登录</a>后可管理标记收藏</span>
<span><a href="{% url 'users:login' %}?next={{ request.path }}">登录</a>后可管理标记收藏</span>
</p>
</section>
{% endif %}

View file

@ -24,6 +24,7 @@ from django.contrib import messages
from journal.models import remove_data_by_user
from django.db.models import Q
from django.core.cache import cache
from django.db.models import Count
# the 'login' page that user can see
@ -35,13 +36,13 @@ def login(request):
sites = cache.get(cache_key, [])
if not sites:
sites = list(
MastodonApplication.objects.all()
.exclude(Q(domain_name__contains="@"))
.exclude(Q(domain_name__contains=":"))
.order_by("domain_name")
.values_list("domain_name")
User.objects.filter(is_active=True)
.values("mastodon_site")
.annotate(total=Count("mastodon_site"))
.order_by("-total")
.values_list("mastodon_site", flat=True)
)
cache.set(cache_key, sites, timeout=3600)
cache.set(cache_key, sites, timeout=3600 * 8)
# store redirect url in the cookie
if request.GET.get("next"):
request.session["next_url"] = request.GET.get("next")