forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds a new custom content jsonfield to ccx model
- Loading branch information
1 parent
be6e128
commit ba49378
Showing
4 changed files
with
47 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,10 @@ def get_valid_input(request_data, ignore_missing=False): | |
elif 'max_students_allowed' in request_data: | ||
field_errors['max_students_allowed'] = {'error_code': 'null_field_max_students_allowed'} | ||
|
||
other_course_settings = request_data.get('other_course_settings') | ||
if other_course_settings and isinstance(other_course_settings, dict): | ||
valid_input['other_course_settings'] = other_course_settings | ||
|
||
course_modules = request_data.get('course_modules') | ||
if course_modules is not None: | ||
if isinstance(course_modules, list): | ||
|
@@ -221,6 +225,7 @@ class CCXListView(GenericAPIView): | |
"display_name": "CCX example title", | ||
"coach_email": "[email protected]", | ||
"max_students_allowed": 123, | ||
"other_course_settings": {"custom_field": "CCX custom content example"}, | ||
"course_modules" : [ | ||
"block-v1:Organization+EX101+RUN-FALL2099+type@chapter+block@week1", | ||
"block-v1:Organization+EX101+RUN-FALL2099+type@chapter+block@week4", | ||
|
@@ -255,6 +260,8 @@ class CCXListView(GenericAPIView): | |
* max_students_allowed: An integer representing he maximum number of students that | ||
can be enrolled in the CCX Course. | ||
* other_course_settings: Optional. A dictionary representation of the custom content. | ||
* course_modules: Optional. A list of course modules id keys. | ||
**GET Response Values** | ||
|
@@ -279,6 +286,8 @@ class CCXListView(GenericAPIView): | |
* max_students_allowed: An integer representing he maximum number of students that | ||
can be enrolled in the CCX Course. | ||
* other_course_settings: A dictionary with the custom content for the CCX Course. | ||
* course_modules: A list of course modules id keys. | ||
* count: An integer representing the total number of records that matched the request parameters. | ||
|
@@ -303,6 +312,7 @@ class CCXListView(GenericAPIView): | |
"start": "2019-01-01", | ||
"due": "2019-06-01", | ||
"max_students_allowed": 123, | ||
"other_course_settings": {"custom_field": "CCX custom content example"}, | ||
"course_modules" : [ | ||
"block-v1:Organization+EX101+RUN-FALL2099+type@chapter+block@week1", | ||
"block-v1:Organization+EX101+RUN-FALL2099+type@chapter+block@week4", | ||
|
@@ -333,6 +343,8 @@ class CCXListView(GenericAPIView): | |
* max_students_allowed: An integer representing he maximum number of students that | ||
can be enrolled in the CCX Course. | ||
* other_course_settings: A dictionary with the custom content for the CCX Course. | ||
* course_modules: A list of course modules id keys. | ||
**Example POST Response** | ||
|
@@ -344,6 +356,7 @@ class CCXListView(GenericAPIView): | |
"start": "2019-01-01", | ||
"due": "2019-06-01", | ||
"max_students_allowed": 123, | ||
"other_course_settings": {"custom_field": "CCX custom content example"}, | ||
"course_modules" : [ | ||
"block-v1:Organization+EX101+RUN-FALL2099+type@chapter+block@week1", | ||
"block-v1:Organization+EX101+RUN-FALL2099+type@chapter+block@week4", | ||
|
@@ -455,12 +468,16 @@ def post(self, request): | |
# prepare the course_modules to be stored in a json stringified field | ||
course_modules_json = json.dumps(valid_input.get('course_modules')) | ||
|
||
# Include the json array to add/storage custom content, if it exist. | ||
custom_content_json = valid_input.get('other_course_settings') | ||
|
||
with transaction.atomic(): | ||
ccx_course_object = CustomCourseForEdX( | ||
course_id=master_course_object.id, | ||
coach=coach, | ||
display_name=valid_input['display_name'], | ||
structure_json=course_modules_json | ||
structure_json=course_modules_json, | ||
other_course_settings=custom_content_json, | ||
) | ||
ccx_course_object.save() | ||
|
||
|
@@ -552,6 +569,7 @@ class CCXDetailView(GenericAPIView): | |
"display_name": "CCX example title modified", | ||
"coach_email": "[email protected]", | ||
"max_students_allowed": 111, | ||
"other_course_settings": {"custom_field": "CCX custom content example"}, | ||
"course_modules" : [ | ||
"block-v1:Organization+EX101+RUN-FALL2099+type@chapter+block@week1", | ||
"block-v1:Organization+EX101+RUN-FALL2099+type@chapter+block@week4", | ||
|
@@ -580,6 +598,8 @@ class CCXDetailView(GenericAPIView): | |
* max_students_allowed: Optional. An integer representing he maximum number of students that | ||
can be enrolled in the CCX Course. | ||
* other_course_settings: Optional. A dictionary representation of the custom content. | ||
* course_modules: Optional. A list of course modules id keys. | ||
**GET Response Values** | ||
|
@@ -602,6 +622,8 @@ class CCXDetailView(GenericAPIView): | |
* max_students_allowed: An integer representing he maximum number of students that | ||
can be enrolled in the CCX Course. | ||
* other_course_settings: A dictionary with the custom content for the CCX Course. | ||
* course_modules: A list of course modules id keys. | ||
**PATCH and DELETE Response Values** | ||
|
@@ -733,6 +755,8 @@ def patch(self, request, ccx_course_id=None): | |
if ccx_course_object.coach.id != coach.id: | ||
old_coach = ccx_course_object.coach | ||
ccx_course_object.coach = coach | ||
if 'other_course_settings' in valid_input: | ||
ccx_course_object.other_course_settings = valid_input.get('other_course_settings') | ||
if 'course_modules' in valid_input: | ||
if valid_input.get('course_modules'): | ||
if not valid_course_modules(valid_input['course_modules'], master_course_key): | ||
|
18 changes: 18 additions & 0 deletions
18
lms/djangoapps/ccx/migrations/0007_customcourseforedx_other_course_settings.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,18 @@ | ||
# Generated by Django 3.2.17 on 2024-10-08 11:22 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('ccx', '0006_set_display_name_as_override'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='customcourseforedx', | ||
name='other_course_settings', | ||
field=models.JSONField(blank=True, default={}, null=True, verbose_name='Custom Json Content'), | ||
), | ||
] |
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