Merge branch 'main' into search-refactor

This commit is contained in:
Mouse Reeve
2021-09-30 10:40:57 -07:00
218 changed files with 8892 additions and 6942 deletions

View File

@ -7,8 +7,8 @@ from django.views.generic.base import TemplateView
from bookwyrm import settings, views
from bookwyrm.utils import regex
USER_PATH = r"^user/(?P<username>%s)" % regex.USERNAME
LOCAL_USER_PATH = r"^user/(?P<username>%s)" % regex.LOCALNAME
USER_PATH = rf"^user/(?P<username>{regex.USERNAME})"
LOCAL_USER_PATH = rf"^user/(?P<username>{regex.LOCALNAME})"
status_types = [
"status",
@ -19,7 +19,9 @@ status_types = [
"boost",
"generatednote",
]
STATUS_PATH = r"%s/(%s)/(?P<status_id>\d+)" % (USER_PATH, "|".join(status_types))
STATUS_TYPES_STRING = "|".join(status_types)
STATUS_PATH = rf"{USER_PATH}/({STATUS_TYPES_STRING})/(?P<status_id>\d+)"
BOOK_PATH = r"^book/(?P<book_id>\d+)"
@ -33,14 +35,15 @@ urlpatterns = [
),
# federation endpoints
re_path(r"^inbox/?$", views.Inbox.as_view()),
re_path(r"%s/inbox/?$" % LOCAL_USER_PATH, views.Inbox.as_view()),
re_path(r"%s/outbox/?$" % LOCAL_USER_PATH, views.Outbox.as_view()),
re_path(rf"{LOCAL_USER_PATH}/inbox/?$", views.Inbox.as_view()),
re_path(rf"{LOCAL_USER_PATH}/outbox/?$", views.Outbox.as_view()),
re_path(r"^\.well-known/webfinger/?$", views.webfinger),
re_path(r"^\.well-known/nodeinfo/?$", views.nodeinfo_pointer),
re_path(r"^\.well-known/host-meta/?$", views.host_meta),
re_path(r"^nodeinfo/2\.0/?$", views.nodeinfo),
re_path(r"^api/v1/instance/?$", views.instance_info),
re_path(r"^api/v1/instance/peers/?$", views.peers),
re_path(r"^opensearch.xml$", views.opensearch, name="opensearch"),
# polling updates
re_path("^api/updates/notifications/?$", views.get_notification_count),
re_path("^api/updates/stream/(?P<stream>[a-z]+)/?$", views.get_unread_status_count),
@ -54,7 +57,7 @@ urlpatterns = [
views.ConfirmEmailCode.as_view(),
name="confirm-email-code",
),
re_path(r"resend-link", views.resend_link, name="resend-link"),
re_path(r"^resend-link/?$", views.resend_link, name="resend-link"),
re_path(r"^logout/?$", views.Logout.as_view(), name="logout"),
re_path(
r"^password-reset/?$",
@ -154,6 +157,16 @@ urlpatterns = [
views.EmailBlocklist.as_view(),
name="settings-email-blocks-delete",
),
re_path(
r"^settings/ip-blocklist/?$",
views.IPBlocklist.as_view(),
name="settings-ip-blocks",
),
re_path(
r"^settings/ip-blocks/(?P<block_id>\d+)/delete/?$",
views.IPBlocklist.as_view(),
name="settings-ip-blocks-delete",
),
# moderation
re_path(r"^settings/reports/?$", views.Reports.as_view(), name="settings-reports"),
re_path(
@ -210,12 +223,12 @@ urlpatterns = [
name="get-started-users",
),
# feeds
re_path(r"^(?P<tab>{:s})/?$".format(STREAMS), views.Feed.as_view()),
re_path(rf"^(?P<tab>{STREAMS})/?$", views.Feed.as_view()),
re_path(
r"^direct-messages/?$", views.DirectMessage.as_view(), name="direct-messages"
),
re_path(
r"^direct-messages/(?P<username>%s)?$" % regex.USERNAME,
rf"^direct-messages/(?P<username>{regex.USERNAME})?$",
views.DirectMessage.as_view(),
name="direct-messages-user",
),
@ -226,22 +239,22 @@ urlpatterns = [
re_path(r"^import/?$", views.Import.as_view(), name="import"),
re_path(r"^import/(\d+)/?$", views.ImportStatus.as_view(), name="import-status"),
# users
re_path(r"%s\.json$" % USER_PATH, views.User.as_view()),
re_path(r"%s/?$" % USER_PATH, views.User.as_view(), name="user-feed"),
re_path(r"%s/rss" % USER_PATH, views.rss_feed.RssFeed(), name="user-rss"),
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}/rss/?$", views.rss_feed.RssFeed(), name="user-rss"),
re_path(
r"%s/followers(.json)?/?$" % USER_PATH,
rf"{USER_PATH}/followers(.json)?/?$",
views.Followers.as_view(),
name="user-followers",
),
re_path(
r"%s/following(.json)?/?$" % USER_PATH,
rf"{USER_PATH}/following(.json)?/?$",
views.Following.as_view(),
name="user-following",
),
re_path(r"^hide-suggestions/?$", views.hide_suggestions, name="hide-suggestions"),
# lists
re_path(r"%s/lists/?$" % USER_PATH, views.UserLists.as_view(), name="user-lists"),
re_path(rf"{USER_PATH}/lists/?$", views.UserLists.as_view(), name="user-lists"),
re_path(r"^list/?$", views.Lists.as_view(), name="lists"),
re_path(r"^list/saved/?$", views.SavedLists.as_view(), name="saved-lists"),
re_path(r"^list/(?P<list_id>\d+)(.json)?/?$", views.List.as_view(), name="list"),
@ -263,14 +276,14 @@ urlpatterns = [
re_path(r"^save-list/(?P<list_id>\d+)/?$", views.save_list, name="list-save"),
re_path(r"^unsave-list/(?P<list_id>\d+)/?$", views.unsave_list, name="list-unsave"),
# User books
re_path(r"%s/books/?$" % USER_PATH, views.Shelf.as_view(), name="user-shelves"),
re_path(rf"{USER_PATH}/books/?$", views.Shelf.as_view(), name="user-shelves"),
re_path(
r"^%s/(helf|books)/(?P<shelf_identifier>[\w-]+)(.json)?/?$" % USER_PATH,
rf"^{USER_PATH}/(shelf|books)/(?P<shelf_identifier>[\w-]+)(.json)?/?$",
views.Shelf.as_view(),
name="shelf",
),
re_path(
r"^%s/(books|shelf)/(?P<shelf_identifier>[\w-]+)(.json)?/?$" % LOCAL_USER_PATH,
rf"^{LOCAL_USER_PATH}/(books|shelf)/(?P<shelf_identifier>[\w-]+)(.json)?/?$",
views.Shelf.as_view(),
name="shelf",
),
@ -280,7 +293,7 @@ urlpatterns = [
re_path(r"^unshelve/?$", views.unshelve),
# goals
re_path(
r"%s/goal/(?P<year>\d{4})/?$" % USER_PATH,
rf"{LOCAL_USER_PATH}/goal/(?P<year>\d+)/?$",
views.Goal.as_view(),
name="user-goal",
),
@ -297,10 +310,10 @@ urlpatterns = [
re_path(r"^block/(?P<user_id>\d+)/?$", views.Block.as_view()),
re_path(r"^unblock/(?P<user_id>\d+)/?$", views.unblock),
# statuses
re_path(r"%s(.json)?/?$" % STATUS_PATH, views.Status.as_view(), name="status"),
re_path(r"%s/activity/?$" % STATUS_PATH, views.Status.as_view(), name="status"),
re_path(rf"{STATUS_PATH}(.json)?/?$", views.Status.as_view(), name="status"),
re_path(rf"{STATUS_PATH}/activity/?$", views.Status.as_view(), name="status"),
re_path(
r"%s/replies(.json)?/?$" % STATUS_PATH, views.Replies.as_view(), name="replies"
rf"{STATUS_PATH}/replies(.json)?/?$", views.Replies.as_view(), name="replies"
),
re_path(
r"^post/?$",
@ -330,17 +343,17 @@ urlpatterns = [
re_path(r"^boost/(?P<status_id>\d+)/?$", views.Boost.as_view()),
re_path(r"^unboost/(?P<status_id>\d+)/?$", views.Unboost.as_view()),
# books
re_path(r"%s(.json)?/?$" % BOOK_PATH, views.Book.as_view(), name="book"),
re_path(rf"{BOOK_PATH}(.json)?/?$", views.Book.as_view(), name="book"),
re_path(
r"%s/(?P<user_statuses>review|comment|quote)/?$" % BOOK_PATH,
rf"{BOOK_PATH}/(?P<user_statuses>review|comment|quote)/?$",
views.Book.as_view(),
name="book-user-statuses",
),
re_path(r"%s/edit/?$" % BOOK_PATH, views.EditBook.as_view(), name="edit-book"),
re_path(r"%s/confirm/?$" % BOOK_PATH, views.ConfirmEditBook.as_view()),
re_path(rf"{BOOK_PATH}/edit/?$", views.EditBook.as_view(), name="edit-book"),
re_path(rf"{BOOK_PATH}/confirm/?$", views.ConfirmEditBook.as_view()),
re_path(r"^create-book/?$", views.EditBook.as_view(), name="create-book"),
re_path(r"^create-book/confirm?$", views.ConfirmEditBook.as_view()),
re_path(r"%s/editions(.json)?/?$" % BOOK_PATH, views.Editions.as_view()),
re_path(rf"{BOOK_PATH}/editions(.json)?/?$", views.Editions.as_view()),
re_path(
r"^upload-cover/(?P<book_id>\d+)/?$", views.upload_cover, name="upload-cover"
),
@ -358,6 +371,11 @@ urlpatterns = [
re_path(r"^create-readthrough/?$", views.create_readthrough),
re_path(r"^delete-progressupdate/?$", views.delete_progressupdate),
# shelve actions
re_path(
r"^reading-status/update/(?P<book_id>\d+)/?$",
views.update_progress,
name="reading-status-update",
),
re_path(
r"^reading-status/(?P<status>want|start|finish)/(?P<book_id>\d+)/?$",
views.ReadingStatus.as_view(),