added wagtail v2 api
This commit is contained in:
parent
515f01c450
commit
2a93c05bc2
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
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 (eg. 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)
|
||||
|
|
@ -99,6 +99,7 @@ THIRD_PARTY_APPS = [
|
|||
'wagtail.admin',
|
||||
'wagtail.core',
|
||||
'wagtail.locales',
|
||||
'wagtail.api.v2',
|
||||
|
||||
'modelcluster',
|
||||
'taggit',
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ from wagtail.admin import urls as wagtailadmin_urls
|
|||
from wagtail.core import urls as wagtail_urls
|
||||
from wagtail.documents import urls as wagtaildocs_urls
|
||||
from grapple import urls as grapple_urls
|
||||
from .api import api_router
|
||||
|
||||
|
||||
|
||||
def raise_example_error(request):
|
||||
|
|
@ -57,6 +59,8 @@ if settings.ALLOW_LOCAL_LOGIN:
|
|||
urlpatterns += [
|
||||
# API base url
|
||||
path("api/", include("config.api_router")),
|
||||
path('api/v2/', api_router.urls),
|
||||
|
||||
# DRF auth token
|
||||
path("auth-token/", obtain_auth_token),
|
||||
path("api/schema/", SpectacularAPIView.as_view(), name="api-schema"),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from django.utils.text import slugify
|
|||
from wagtail.core.blocks import StreamBlock
|
||||
from wagtail.core.fields import StreamField
|
||||
from wagtail.core.models import Page, Orderable
|
||||
from wagtail.api import APIField
|
||||
|
||||
from vbv_lernwelt.learnpath.models_competences import *
|
||||
from vbv_lernwelt.learnpath.models_learning_unit_content import WebBasedTrainingBlock, VideoBlock
|
||||
|
|
@ -57,6 +58,12 @@ class Topic(Orderable):
|
|||
GraphQLBoolean("is_visible"),
|
||||
]
|
||||
|
||||
api_fields = [
|
||||
APIField('title'),
|
||||
APIField('is_visible'),
|
||||
]
|
||||
|
||||
|
||||
# content_panels = Page.content_panels + [
|
||||
# FieldPanel('is_visible', classname="full"),
|
||||
# PageChooserPanel('learning_path', 'learnpath.LearningPath'),
|
||||
|
|
@ -102,6 +109,13 @@ class Circle(Page, Orderable):
|
|||
GraphQLString("goals"),
|
||||
]
|
||||
|
||||
# Export fields over the API
|
||||
api_fields = [
|
||||
APIField('title'),
|
||||
APIField('description'),
|
||||
APIField('learning_sequences'),
|
||||
]
|
||||
|
||||
|
||||
def full_clean(self, *args, **kwargs):
|
||||
self.slug = find_available_slug(Circle, slugify(self.title, allow_unicode=True))
|
||||
|
|
@ -147,6 +161,12 @@ class LearningSequence(Orderable):
|
|||
GraphQLBoolean("category"),
|
||||
]
|
||||
|
||||
api_fields = [
|
||||
APIField('title'),
|
||||
APIField('category'),
|
||||
APIField('learning_packages'),
|
||||
]
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Learning Sequence"
|
||||
|
|
@ -176,6 +196,11 @@ class LearningPackage(Orderable):
|
|||
GraphQLString("title", required=False),
|
||||
]
|
||||
|
||||
api_fields = [
|
||||
APIField('title'),
|
||||
APIField('learning_units'),
|
||||
]
|
||||
|
||||
|
||||
def full_clean(self, *args, **kwargs):
|
||||
self.slug = find_available_slug(LearningPackage, slugify(self.title, allow_unicode=True))
|
||||
|
|
@ -216,6 +241,13 @@ class LearningUnit(Page, Orderable):
|
|||
GraphQLStreamfield('contents')
|
||||
]
|
||||
|
||||
|
||||
api_fields = [
|
||||
APIField('title'),
|
||||
|
||||
|
||||
]
|
||||
|
||||
subpage_types = []
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
Loading…
Reference in New Issue