bookwyrm-mastodon/bookwyrm/urls.py

291 lines
11 KiB
Python
Raw Normal View History

2021-03-08 11:49:10 -05:00
""" url routing for the app and api """
2020-01-28 14:45:27 -05:00
from django.conf.urls.static import static
2020-09-21 13:25:26 -04:00
from django.contrib import admin
2020-01-29 14:45:19 -05:00
from django.urls import path, re_path
2021-03-29 17:12:15 -04:00
from django.views.generic.base import TemplateView
2021-01-20 17:15:15 -05:00
from bookwyrm import settings, views
2020-12-30 20:36:35 -05:00
from bookwyrm.utils import regex
2020-01-28 14:45:27 -05:00
2021-03-08 11:49:10 -05:00
user_path = r"^user/(?P<username>%s)" % regex.username
local_user_path = r"^user/(?P<username>%s)" % regex.localname
2020-10-16 22:13:18 -04:00
status_types = [
2021-03-08 12:48:25 -05:00
"status",
"review",
"reviewrating",
"comment",
"quotation",
"boost",
"generatednote",
2020-10-16 22:13:18 -04:00
]
2021-03-08 11:49:10 -05:00
status_path = r"%s/(%s)/(?P<status_id>\d+)" % (user_path, "|".join(status_types))
2021-03-08 11:49:10 -05:00
book_path = r"^book/(?P<book_id>\d+)"
2020-01-25 01:32:41 -05:00
urlpatterns = [
2021-03-08 11:49:10 -05:00
path("admin/", admin.site.urls),
2021-03-29 17:12:15 -04:00
path(
"robots.txt",
TemplateView.as_view(template_name="robots.txt", content_type="text/plain"),
),
2020-01-28 03:44:51 -05:00
# federation endpoints
2021-03-08 11:49:10 -05:00
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()),
2021-03-29 17:36:24 -04:00
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),
2021-01-18 19:32:02 -05:00
# polling updates
2021-03-23 15:52:38 -04:00
re_path("^api/updates/notifications/?$", views.get_notification_count),
re_path("^api/updates/stream/(?P<stream>[a-z]+)/?$", views.get_unread_status_count),
2021-01-12 11:19:08 -05:00
# authentication
2021-03-08 11:49:10 -05:00
re_path(r"^login/?$", views.Login.as_view()),
re_path(r"^register/?$", views.Register.as_view()),
re_path(r"^logout/?$", views.Logout.as_view()),
re_path(r"^password-reset/?$", views.PasswordResetRequest.as_view()),
re_path(
r"^password-reset/(?P<code>[A-Za-z0-9]+)/?$", views.PasswordReset.as_view()
),
2021-01-29 18:38:42 -05:00
# admin
2021-03-08 11:49:10 -05:00
re_path(r"^settings/site-settings", views.Site.as_view(), name="settings-site"),
re_path(
r"^settings/email-preview",
views.site.email_preview,
name="settings-email-preview",
),
2021-03-28 17:20:49 -04:00
re_path(r"^settings/users", views.UserAdmin.as_view(), name="settings-users"),
2021-03-08 11:49:10 -05:00
re_path(
2021-03-28 15:34:55 -04:00
r"^settings/federation/?$",
views.Federation.as_view(),
name="settings-federation",
),
re_path(
r"^settings/federation/(?P<server>\d+)/?$",
views.FederatedServer.as_view(),
name="settings-federated-server",
2021-03-08 11:49:10 -05:00
),
2021-04-11 13:36:40 -04:00
re_path(
r"^settings/federation/(?P<server>\d+)/block?$",
views.federation.block_server,
name="settings-federated-server-block",
),
2021-04-10 14:06:28 -04:00
re_path(
r"^settings/federation/(?P<server>\d+)/unblock?$",
views.federation.unblock_server,
name="settings-federated-server-unblock",
),
2021-04-07 16:06:29 -04:00
re_path(
r"^settings/federation/add/?$",
views.AddFederatedServer.as_view(),
name="settings-add-federated-server",
2021-04-07 16:17:51 -04:00
),
re_path(
r"^settings/federation/import/?$",
views.ImportServerBlocklist.as_view(),
name="settings-import-blocklist",
),
2021-03-08 11:49:10 -05:00
re_path(
r"^settings/invites/?$", views.ManageInvites.as_view(), name="settings-invites"
),
2021-03-20 22:39:08 -04:00
re_path(
r"^settings/requests/?$",
views.ManageInviteRequests.as_view(),
name="settings-invite-requests",
),
re_path(
r"^settings/requests/ignore?$",
views.ignore_invite_request,
name="settings-invite-requests-ignore",
),
2021-03-20 22:14:41 -04:00
re_path(
r"^invite-request/?$", views.InviteRequest.as_view(), name="invite-request"
),
2021-03-08 11:49:10 -05:00
re_path(r"^invite/(?P<code>[A-Za-z0-9]+)/?$", views.Invite.as_view()),
2021-03-08 18:49:44 -05:00
# moderation
re_path(r"^settings/reports/?$", views.Reports.as_view(), name="settings-reports"),
re_path(
2021-03-08 21:36:34 -05:00
r"^settings/reports/(?P<report_id>\d+)/?$",
2021-03-08 18:49:44 -05:00
views.Report.as_view(),
name="settings-report",
),
2021-03-12 14:13:53 -05:00
re_path(
r"^settings/reports/(?P<report_id>\d+)/deactivate/?$",
views.deactivate_user,
name="settings-report-deactivate",
),
2021-03-12 13:22:03 -05:00
re_path(
r"^settings/reports/(?P<report_id>\d+)/resolve/?$",
views.resolve_report,
name="settings-report-resolve",
),
2021-03-08 21:36:34 -05:00
re_path(r"^report/?$", views.make_report, name="report"),
2021-01-13 15:03:27 -05:00
# landing pages
re_path(r"^about/?$", views.About.as_view(), name="about"),
path("", views.Home.as_view(), name="landing"),
2021-03-08 11:49:10 -05:00
re_path(r"^discover/?$", views.Discover.as_view()),
re_path(r"^notifications/?$", views.Notifications.as_view()),
2021-03-21 19:37:52 -04:00
re_path(r"^directory/?", views.Directory.as_view(), name="directory"),
2021-03-31 16:56:26 -04:00
# Get started
re_path(
2021-04-01 12:22:43 -04:00
r"^get-started/profile/?$",
views.GetStartedProfile.as_view(),
name="get-started-profile",
),
re_path(
r"^get-started/books/?$",
views.GetStartedBooks.as_view(),
name="get-started-books",
),
re_path(
r"^get-started/users/?$",
views.GetStartedUsers.as_view(),
name="get-started-users",
),
2021-01-29 13:25:31 -05:00
# feeds
2021-03-08 11:49:10 -05:00
re_path(r"^(?P<tab>home|local|federated)/?$", views.Feed.as_view()),
2021-03-12 13:37:52 -05:00
re_path(
r"^direct-messages/?$", views.DirectMessage.as_view(), name="direct-messages"
),
2021-03-08 11:49:10 -05:00
re_path(
r"^direct-messages/(?P<username>%s)?$" % regex.username,
views.DirectMessage.as_view(),
2021-03-12 13:37:52 -05:00
name="direct-messages-user",
2021-03-08 11:49:10 -05:00
),
2021-01-13 15:03:27 -05:00
# search
2021-03-08 11:49:10 -05:00
re_path(r"^search/?$", views.Search.as_view()),
2021-01-12 14:28:03 -05:00
# imports
2021-03-08 11:49:10 -05:00
re_path(r"^import/?$", views.Import.as_view()),
re_path(r"^import/(\d+)/?$", views.ImportStatus.as_view()),
2020-03-13 20:57:36 -04:00
# users
2021-03-08 11:49:10 -05:00
re_path(r"%s/?$" % user_path, views.User.as_view(), name="user-feed"),
re_path(r"%s\.json$" % user_path, views.User.as_view()),
re_path(r"%s/rss" % user_path, views.rss_feed.RssFeed(), name="user-rss"),
re_path(
r"%s/followers(.json)?/?$" % user_path,
views.Followers.as_view(),
name="user-followers",
),
re_path(
r"%s/following(.json)?/?$" % user_path,
views.Following.as_view(),
name="user-following",
),
2021-01-31 00:33:41 -05:00
# lists
2021-03-31 12:34:16 -04:00
re_path(r"%s/lists/?$" % user_path, views.UserLists.as_view(), name="user-lists"),
2021-03-08 11:49:10 -05:00
re_path(r"^list/?$", views.Lists.as_view(), name="lists"),
re_path(r"^list/(?P<list_id>\d+)(.json)?/?$", views.List.as_view(), name="list"),
2021-03-15 18:33:05 -04:00
re_path(r"^list/add-book/?$", views.list.add_book, name="list-add-book"),
2021-03-08 11:49:10 -05:00
re_path(
r"^list/(?P<list_id>\d+)/remove/?$",
views.list.remove_book,
name="list-remove-book",
),
2021-04-08 12:05:21 -04:00
re_path(
r"^list-item/(?P<list_item_id>\d+)/set-position$",
views.list.set_book_position,
name="list-set-book-position",
),
2021-03-08 11:49:10 -05:00
re_path(
r"^list/(?P<list_id>\d+)/curate/?$", views.Curate.as_view(), name="list-curate"
),
2021-03-31 13:23:20 -04:00
# Uyser books
re_path(r"%s/books/?$" % user_path, views.Shelf.as_view(), name="user-shelves"),
2021-03-31 12:34:16 -04:00
re_path(
r"^%s/(helf|books)/(?P<shelf_identifier>[\w-]+)(.json)?/?$" % user_path,
2021-03-31 12:34:16 -04:00
views.Shelf.as_view(),
name="shelf",
),
re_path(
r"^%s/(books|shelf)/(?P<shelf_identifier>[\w-]+)(.json)?/?$" % local_user_path,
2021-03-31 12:34:16 -04:00
views.Shelf.as_view(),
2021-03-31 12:54:52 -04:00
name="shelf",
2021-03-31 12:34:16 -04:00
),
re_path(r"^create-shelf/?$", views.create_shelf, name="shelf-create"),
re_path(r"^delete-shelf/(?P<shelf_id>\d+)?$", views.delete_shelf),
re_path(r"^shelve/?$", views.shelve),
re_path(r"^unshelve/?$", views.unshelve),
# goals
re_path(
r"%s/goal/(?P<year>\d{4})/?$" % user_path,
views.Goal.as_view(),
name="user-goal",
),
re_path(r"^hide-goal/?$", views.hide_goal, name="hide-goal"),
2021-01-29 12:28:00 -05:00
# preferences
2021-03-08 11:49:10 -05:00
re_path(r"^preferences/profile/?$", views.EditUser.as_view(), name="prefs-profile"),
re_path(r"^preferences/password/?$", views.ChangePassword.as_view()),
re_path(r"^preferences/block/?$", views.Block.as_view()),
re_path(r"^block/(?P<user_id>\d+)/?$", views.Block.as_view()),
re_path(r"^unblock/(?P<user_id>\d+)/?$", views.unblock),
2020-03-13 20:57:36 -04:00
# statuses
2021-04-03 15:38:12 -04:00
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(
r"%s/replies(.json)?/?$" % status_path, views.Replies.as_view(), name="replies"
),
2021-04-03 17:32:34 -04:00
re_path(
r"^post/?$",
views.CreateStatus.as_view(),
name="create-status",
),
2021-04-03 15:38:12 -04:00
re_path(
r"^post/(?P<status_type>\w+)/?$",
views.CreateStatus.as_view(),
name="create-status",
),
re_path(
r"^delete-status/(?P<status_id>\d+)/?$",
views.DeleteStatus.as_view(),
name="delete-status",
),
re_path(
r"^redraft-status/(?P<status_id>\d+)/?$",
views.DeleteAndRedraft.as_view(),
name="redraft",
),
2021-01-12 16:47:00 -05:00
# interact
2021-03-08 11:49:10 -05:00
re_path(r"^favorite/(?P<status_id>\d+)/?$", views.Favorite.as_view()),
re_path(r"^unfavorite/(?P<status_id>\d+)/?$", views.Unfavorite.as_view()),
re_path(r"^boost/(?P<status_id>\d+)/?$", views.Boost.as_view()),
re_path(r"^unboost/(?P<status_id>\d+)/?$", views.Unboost.as_view()),
2020-03-13 20:57:36 -04:00
# books
2021-03-08 11:49:10 -05:00
re_path(r"%s(.json)?/?$" % book_path, views.Book.as_view()),
re_path(r"%s/edit/?$" % book_path, views.EditBook.as_view()),
2021-03-08 13:10:30 -05:00
re_path(r"%s/confirm/?$" % book_path, views.ConfirmEditBook.as_view()),
re_path(r"^create-book/?$", views.EditBook.as_view()),
re_path(r"^create-book/confirm?$", views.ConfirmEditBook.as_view()),
2021-03-08 11:49:10 -05:00
re_path(r"%s/editions(.json)?/?$" % book_path, views.Editions.as_view()),
2021-03-18 13:03:53 -04:00
re_path(
r"^upload-cover/(?P<book_id>\d+)/?$", views.upload_cover, name="upload-cover"
),
2021-03-08 11:49:10 -05:00
re_path(r"^add-description/(?P<book_id>\d+)/?$", views.add_description),
re_path(r"^resolve-book/?$", views.resolve_book),
re_path(r"^switch-edition/?$", views.switch_edition),
2021-03-01 15:09:21 -05:00
# isbn
2021-03-08 11:49:10 -05:00
re_path(r"^isbn/(?P<isbn>\d+)(.json)?/?$", views.Isbn.as_view()),
2021-01-13 12:54:35 -05:00
# author
2021-03-08 11:49:10 -05:00
re_path(r"^author/(?P<author_id>\d+)(.json)?/?$", views.Author.as_view()),
re_path(r"^author/(?P<author_id>\d+)/edit/?$", views.EditAuthor.as_view()),
2021-01-13 13:24:24 -05:00
# tags
2021-03-08 11:49:10 -05:00
re_path(r"^tag/(?P<tag_id>.+)\.json/?$", views.Tag.as_view()),
re_path(r"^tag/(?P<tag_id>.+)/?$", views.Tag.as_view()),
re_path(r"^tag/?$", views.AddTag.as_view()),
re_path(r"^untag/?$", views.RemoveTag.as_view()),
2021-01-13 15:33:48 -05:00
# reading progress
2021-03-20 20:18:18 -04:00
re_path(r"^edit-readthrough/?$", views.edit_readthrough, name="edit-readthrough"),
2021-03-08 11:49:10 -05:00
re_path(r"^delete-readthrough/?$", views.delete_readthrough),
re_path(r"^create-readthrough/?$", views.create_readthrough),
re_path(r"^delete-progressupdate/?$", views.delete_progressupdate),
re_path(r"^start-reading/(?P<book_id>\d+)/?$", views.start_reading),
re_path(r"^finish-reading/(?P<book_id>\d+)/?$", views.finish_reading),
2021-01-13 15:33:48 -05:00
# following
2021-03-13 17:48:15 -05:00
re_path(r"^follow/?$", views.follow, name="follow"),
re_path(r"^unfollow/?$", views.unfollow, name="unfollow"),
2021-03-08 11:49:10 -05:00
re_path(r"^accept-follow-request/?$", views.accept_follow_request),
re_path(r"^delete-follow-request/?$", views.delete_follow_request),
2020-01-28 01:49:56 -05:00
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)