feat: enable translations and rest api

This commit is contained in:
Konstantin 2024-11-23 14:59:51 +01:00
parent e98db55a16
commit 310fd5ed7a
Signed by: konstantin
GPG key ID: A128B78773E41ACE
4 changed files with 48 additions and 9 deletions

15
iamkonstantin_web/api.py Normal file
View file

@ -0,0 +1,15 @@
from wagtail.api.v2.views import PagesAPIViewSet
from wagtail.api.v2.router import WagtailAPIRouter
from wagtail.images.api.v2.views import ImagesAPIViewSet
from wagtail.documents.api.v2.views import DocumentsAPIViewSet
# Create the router. "wagtailapi" is the URL namespace
api_router = WagtailAPIRouter('wagtailapi')
# Add the three endpoints using the "register_endpoint" method.
# The first parameter is the name of the endpoint (such as pages, images). This
# is used in the URL of the endpoint
# The second parameter is the endpoint class that handles the requests
api_router.register_endpoint('pages', PagesAPIViewSet)
api_router.register_endpoint('images', ImagesAPIViewSet)
api_router.register_endpoint('documents', DocumentsAPIViewSet)

View file

@ -35,6 +35,7 @@ INSTALLED_APPS = [
"wagtail.contrib.settings",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.contrib.simple_translation",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
@ -44,6 +45,8 @@ INSTALLED_APPS = [
"wagtail.search",
"wagtail.admin",
"wagtail.locales",
"wagtail.api.v2",
"rest_framework",
"wagtail",
"modelcluster",
"taggit",
@ -149,6 +152,8 @@ WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [
('nl', "Dutch"),
]
WAGTAILSIMPLETRANSLATION_SYNC_PAGE_TREE = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
@ -198,6 +203,9 @@ WAGTAILSEARCH_BACKENDS = {
# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
WAGTAILADMIN_BASE_URL = "https://iamkonstantin.eu"
WAGTAILAPI_BASE_URL = "https://iamkonstantin.eu"
WAGTAILAPI_SEARCH_ENABLED = True
WAGTAIL_CODE_BLOCK_LANGUAGES = (
('bash', 'Bash/Shell'),

View file

@ -9,6 +9,7 @@ from wagtail import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
from blog.feeds import RssBlogFeed
from iamkonstantin_web.api import api_router
from newsletter import views as newsletter_views
from search import views as search_views
from wagtail.contrib.sitemaps.views import sitemap
@ -26,6 +27,10 @@ urlpatterns = [
path('newsletter/thanks', newsletter_views.thanks, name='thanks')
]
urlpatterns += [
path('api/v2/', api_router.urls),
]
# Translatable URLs
# These will be available under a language code prefix. For example /en/search/
urlpatterns += i18n_patterns(
@ -42,12 +47,12 @@ if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += path("__reload__/", include("django_browser_reload.urls")),
urlpatterns = urlpatterns + [
# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in
# the list:
path("", include(wagtail_urls)),
# Alternatively, if you want Wagtail pages to be served from a subpath
# of your site, rather than the site root:
# path("pages/", include(wagtail_urls)),
]
# urlpatterns = urlpatterns + [
# # For anything not caught by a more specific rule above, hand over to
# # Wagtail's page serving mechanism. This should be the last pattern in
# # the list:
# path("", include(wagtail_urls)),
# # Alternatively, if you want Wagtail pages to be served from a subpath
# # of your site, rather than the site root:
# # path("pages/", include(wagtail_urls)),
# ]