forked from mirrors/bookwyrm
Merge pull request #1714 from joachimesque/handle-user-at-urls
Redirect /@<username> to /user/<username>
This commit is contained in:
commit
ec7c1e75fe
4 changed files with 16 additions and 1 deletions
|
@ -186,3 +186,11 @@ class UserViews(TestCase):
|
||||||
|
|
||||||
self.local_user.refresh_from_db()
|
self.local_user.refresh_from_db()
|
||||||
self.assertFalse(self.local_user.show_suggested_users)
|
self.assertFalse(self.local_user.show_suggested_users)
|
||||||
|
|
||||||
|
def test_user_redirect(self):
|
||||||
|
"""test the basic redirect"""
|
||||||
|
request = self.factory.get("@mouse")
|
||||||
|
request.user = self.anonymous_user
|
||||||
|
result = views.user_redirect(request, "mouse")
|
||||||
|
|
||||||
|
self.assertEqual(result.status_code, 302)
|
||||||
|
|
|
@ -276,6 +276,7 @@ urlpatterns = [
|
||||||
# users
|
# users
|
||||||
re_path(rf"{USER_PATH}\.json$", views.User.as_view()),
|
re_path(rf"{USER_PATH}\.json$", views.User.as_view()),
|
||||||
re_path(rf"{USER_PATH}/?$", views.User.as_view(), name="user-feed"),
|
re_path(rf"{USER_PATH}/?$", views.User.as_view(), name="user-feed"),
|
||||||
|
re_path(rf"^@(?P<username>{regex.USERNAME})$", views.user_redirect),
|
||||||
re_path(rf"{USER_PATH}/rss/?$", views.rss_feed.RssFeed(), name="user-rss"),
|
re_path(rf"{USER_PATH}/rss/?$", views.rss_feed.RssFeed(), name="user-rss"),
|
||||||
re_path(
|
re_path(
|
||||||
rf"{USER_PATH}/followers(.json)?/?$",
|
rf"{USER_PATH}/followers(.json)?/?$",
|
||||||
|
|
|
@ -94,7 +94,7 @@ from .search import Search
|
||||||
from .status import CreateStatus, EditStatus, DeleteStatus, update_progress
|
from .status import CreateStatus, EditStatus, DeleteStatus, update_progress
|
||||||
from .status import edit_readthrough
|
from .status import edit_readthrough
|
||||||
from .updates import get_notification_count, get_unread_status_count
|
from .updates import get_notification_count, get_unread_status_count
|
||||||
from .user import User, Followers, Following, hide_suggestions
|
from .user import User, Followers, Following, hide_suggestions, user_redirect
|
||||||
from .wellknown import *
|
from .wellknown import *
|
||||||
from .annual_summary import (
|
from .annual_summary import (
|
||||||
AnnualSummary,
|
AnnualSummary,
|
||||||
|
|
|
@ -151,3 +151,9 @@ def hide_suggestions(request):
|
||||||
request.user.show_suggested_users = False
|
request.user.show_suggested_users = False
|
||||||
request.user.save(broadcast=False, update_fields=["show_suggested_users"])
|
request.user.save(broadcast=False, update_fields=["show_suggested_users"])
|
||||||
return redirect(request.headers.get("Referer", "/"))
|
return redirect(request.headers.get("Referer", "/"))
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def user_redirect(request, username):
|
||||||
|
"""redirect to a user's feed"""
|
||||||
|
return redirect("user-feed", username=username)
|
||||||
|
|
Loading…
Reference in a new issue