forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: [AXIMST-26] API endpoint to return components in unit #2486
Closed
ruzniaievdm
wants to merge
5
commits into
ts-develop-old
from
ruzniaievdm/feat/vertical-container-api
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f5eef05
feat: [AXIMST-10] Refactor Unit page view as DRF
ruzniaievdm 507311b
fix: revision of discussions
ruzniaievdm fe2b4aa
fix: linter error
ruzniaievdm 4a09682
Merge pull request #2484 from raccoongang/ruzniaievdm/container-handl…
monteri 9164b5a
feat: [AXIMST-26] API endpoint to return components in unit
ruzniaievdm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
""" | ||
API Serializers for unit page | ||
""" | ||
|
||
from django.urls import reverse | ||
from rest_framework import serializers | ||
|
||
from cms.djangoapps.contentstore.helpers import ( | ||
xblock_studio_url, | ||
xblock_type_display_name, | ||
) | ||
|
||
|
||
class ChildAncestorSerializer(serializers.Serializer): | ||
""" | ||
Serializer for representing child blocks in the ancestor XBlock. | ||
""" | ||
|
||
url = serializers.SerializerMethodField() | ||
display_name = serializers.CharField(source="display_name_with_default") | ||
|
||
def get_url(self, obj): | ||
""" | ||
Method to generate studio URL for the child block. | ||
""" | ||
return xblock_studio_url(obj) | ||
|
||
|
||
class AncestorXBlockSerializer(serializers.Serializer): | ||
""" | ||
Serializer for representing the ancestor XBlock and its children. | ||
""" | ||
|
||
children = ChildAncestorSerializer(many=True) | ||
title = serializers.CharField() | ||
is_last = serializers.BooleanField() | ||
|
||
|
||
class ContainerXBlock(serializers.Serializer): | ||
""" | ||
Serializer for representing XBlock data. Doesn't include all data about XBlock. | ||
""" | ||
|
||
display_name = serializers.CharField(source="display_name_with_default") | ||
display_type = serializers.SerializerMethodField() | ||
category = serializers.CharField() | ||
|
||
def get_display_type(self, obj): | ||
""" | ||
Method to get the display type name for the container XBlock. | ||
""" | ||
return xblock_type_display_name(obj) | ||
|
||
|
||
class ContainerHandlerSerializer(serializers.Serializer): | ||
""" | ||
Serializer for container handler | ||
""" | ||
|
||
language_code = serializers.CharField() | ||
action = serializers.CharField() | ||
xblock = ContainerXBlock() | ||
is_unit_page = serializers.BooleanField() | ||
is_collapsible = serializers.BooleanField() | ||
position = serializers.IntegerField(min_value=1) | ||
prev_url = serializers.CharField(allow_null=True) | ||
next_url = serializers.CharField(allow_null=True) | ||
new_unit_category = serializers.CharField() | ||
outline_url = serializers.CharField() | ||
ancestor_xblocks = AncestorXBlockSerializer(many=True) | ||
component_templates = serializers.ListField(child=serializers.DictField()) | ||
xblock_info = serializers.DictField() | ||
draft_preview_link = serializers.CharField() | ||
published_preview_link = serializers.CharField() | ||
show_unit_tags = serializers.BooleanField() | ||
user_clipboard = serializers.DictField() | ||
is_fullwidth_content = serializers.BooleanField() | ||
assets_url = serializers.SerializerMethodField() | ||
unit_block_id = serializers.CharField(source="unit.location.block_id") | ||
subsection_location = serializers.CharField(source="subsection.location") | ||
|
||
def get_assets_url(self, obj): | ||
""" | ||
Method to get the assets URL based on the course id. | ||
""" | ||
|
||
context_course = obj.get("context_course", None) | ||
if context_course: | ||
return reverse( | ||
"assets_handler", kwargs={"course_key_string": context_course.id} | ||
) | ||
return None | ||
|
||
|
||
class ChildVerticalContainerSerializer(serializers.Serializer): | ||
""" | ||
Serializer for representing a xblock child of vertical container. | ||
""" | ||
|
||
name = serializers.CharField(source="display_name_with_default") | ||
block_id = serializers.CharField(source="location") | ||
|
||
|
||
class VerticalContainerSerializer(serializers.Serializer): | ||
""" | ||
Serializer for representing a vertical container with state and children. | ||
""" | ||
|
||
children = ChildVerticalContainerSerializer(many=True) | ||
is_published = serializers.BooleanField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.