From 5af863fb6cdb912e5d3e13d7fd210725a026e96b Mon Sep 17 00:00:00 2001 From: Lorenz Padberg Date: Mon, 23 May 2022 14:35:05 +0200 Subject: [PATCH] added api stuff to readme --- server/README.md | 22 +++++++++++++++++ .../learnpath/models_learning_unit_content.py | 24 +++++++++++++------ .../tests/create_default_learning_path.py | 4 ++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/server/README.md b/server/README.md index eadebd29..2f1d4337 100644 --- a/server/README.md +++ b/server/README.md @@ -48,3 +48,25 @@ npm run dev * In the .idea/vbv_lernwelt.iml file change the module type to "PYTHON_MODULE". * Add django facet in "Project Structure". * Run configuration with "Python -> server.py" to have async debugging support. + + +## Wagtail API intro + +get all pages: + + http://localhost:8000/api/v2/pages/ + +get Analyse Circle (the one with the most demo data) + + http://localhost:8000/api/v2/pages/?title=Analyse + + +Get Circles only + + http://localhost:8000/api/v2/pages/?type=learnpath.Circle + +Get All Contents from that circle: + + http://localhost:8000/api/v2/pages/?child_of=11 + + diff --git a/server/vbv_lernwelt/learnpath/models_learning_unit_content.py b/server/vbv_lernwelt/learnpath/models_learning_unit_content.py index 9a1277e7..763d1668 100644 --- a/server/vbv_lernwelt/learnpath/models_learning_unit_content.py +++ b/server/vbv_lernwelt/learnpath/models_learning_unit_content.py @@ -1,5 +1,6 @@ from django.db import models from wagtail.core import blocks +from wagtail.api import APIField # 'video_block' @@ -12,26 +13,35 @@ class VideoBlock(blocks.StructBlock): class Meta: icon = 'media' + def get_api_representation(self, value, context=None): + return {'sdfsdf': 1, + 'sldkfm': 3} +RISE = 'rise' + +CONTENT_TYPE_CHOICES = ( + (RISE, 'Rise'), +) # 'Web based training Block' class WebBasedTrainingBlock(blocks.StructBlock): - RISE = 'rise' - - WBT_TYPE_CHOICES = ( - (RISE, 'Rise'), - ) url = blocks.URLBlock() - type = models.CharField( + content_type = models.CharField( max_length=100, - choices=WBT_TYPE_CHOICES, + choices=CONTENT_TYPE_CHOICES, default=RISE ) class Meta: icon = 'media' + def get_api_representation(self, value, context=None): + + return {'sdfsdf': 1, + 'sldkfm': 3} + + # 'Transver Task' class TranverTaskBlock(blocks.StructBlock): title = models.CharField(max_length=128, default="") diff --git a/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py b/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py index 253d1873..5e8a7527 100644 --- a/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py +++ b/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py @@ -81,13 +81,13 @@ von Neukunden zu benützen video_url = "https://www.vbv.ch/fileadmin/vbv/Videos/Statements_Externe/Janos_M/Testimonial_Janos_Mischler_PositiveEffekte.mp4" video_title = "Ausbildung ist pflicht" video_description = "Erfahren Sie, was für Janos Mischler die positiven Aspekte von ständiger Weiterbildung sind – aus fachlicher und aus persönlicher Sicht." - video_block = VideoBlockFactory(type="video", url=video_url, title=video_title, description=video_description) + video_block = VideoBlockFactory(content_type="video", url=video_url, title=video_title, description=video_description) learning_unit.contents.append(('video', video_block)) learning_unit.save() learning_unit = LearningUnitFactory.create(title='** Web Based Training"', parent=circle_4, learning_package=lpck_1) wbt_url = "web_based_trainings/rise_cmi5_test_export/scormcontent/index.html" - wbt_block = WebBasedTrainingBlockFactory(type="web_based_training", url=wbt_url) + wbt_block = WebBasedTrainingBlockFactory(content_type="web_based_training", url=wbt_url) learning_unit.contents.append(('web_based_training', wbt_block)) learning_unit.save()