diff --git a/blog/models.py b/blog/models.py index c0279c0..64ad0d5 100644 --- a/blog/models.py +++ b/blog/models.py @@ -5,6 +5,7 @@ from django.db import models from modelcluster.fields import ParentalKey, ParentalManyToManyField from modelcluster.contrib.taggit import ClusterTaggableManager from taggit.models import TaggedItemBase +from wagtail.api import APIField from wagtail.models import Page, Orderable from wagtail.fields import RichTextField, StreamField @@ -74,6 +75,13 @@ class BlogPage(SeoMixin, Page): else: return None + # Export fields over the API + api_fields = [ + APIField('gallery_images'), + APIField('body'), + APIField('intro'), + APIField('tags'), + ] search_fields = Page.search_fields + [ index.SearchField('intro'), index.SearchField('body'), @@ -122,6 +130,9 @@ class BlogPageGalleryImage(Orderable): FieldPanel('image'), FieldPanel('caption'), ] + api_fields = [ + APIField('image'), + ] @register_snippet diff --git a/iamkonstantin_web/api.py b/iamkonstantin_web/api.py new file mode 100644 index 0000000..9415198 --- /dev/null +++ b/iamkonstantin_web/api.py @@ -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) \ No newline at end of file diff --git a/iamkonstantin_web/settings/base.py b/iamkonstantin_web/settings/base.py index 44ac0f7..d3cff38 100644 --- a/iamkonstantin_web/settings/base.py +++ b/iamkonstantin_web/settings/base.py @@ -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", @@ -43,6 +44,9 @@ INSTALLED_APPS = [ "wagtail.images", "wagtail.search", "wagtail.admin", + "wagtail.locales", + "wagtail.api.v2", + "rest_framework", "wagtail", "modelcluster", "taggit", @@ -68,6 +72,7 @@ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "wagtail.contrib.redirects.middleware.RedirectMiddleware", "blog.middleware.BlogRedirectMiddleware", + "django.middleware.locale.LocaleMiddleware", "django_browser_reload.middleware.BrowserReloadMiddleware" ] @@ -128,7 +133,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/5.0/topics/i18n/ -LANGUAGE_CODE = "en-us" +LANGUAGE_CODE = "en" TIME_ZONE = "UTC" @@ -136,6 +141,18 @@ USE_I18N = True USE_TZ = True +WAGTAIL_I18N_ENABLED = True + +USE_L10N = True # allows dates to be shown in the user's locale + +WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [ + ('en', "English"), + ('fr', "French"), + ('es', "Spanish"), + ('nl', "Dutch"), +] + +WAGTAILSIMPLETRANSLATION_SYNC_PAGE_TREE = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.0/howto/static-files/ @@ -186,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'), diff --git a/iamkonstantin_web/urls.py b/iamkonstantin_web/urls.py index d53a50e..4b29694 100644 --- a/iamkonstantin_web/urls.py +++ b/iamkonstantin_web/urls.py @@ -1,4 +1,5 @@ from django.conf import settings +from django.conf.urls.i18n import i18n_patterns from django.urls import include, path from django.contrib import admin from django.views.generic.base import TemplateView @@ -8,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 @@ -25,6 +27,17 @@ 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( + path("", include(wagtail_urls)), + prefix_default_language=False, +) + if settings.DEBUG: from django.conf.urls.static import static from django.contrib.staticfiles.urls import staticfiles_urlpatterns @@ -34,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)), +# ] diff --git a/requirements.txt b/requirements.txt index 69558ab..04fcbe1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ Django>=4.2,<5.2 -wagtail>=6.3,<6.4 +wagtail>=6.3.1,<6.4 whitenoise>=6.6,<7.0 wagtailcodeblock>=1.29.0.2,<2.0 django-tailwind>=3.6.0