-
Notifications
You must be signed in to change notification settings - Fork 0
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
PADV-1418 feat: adds a new custom content jsonfield to ccx model #133
Conversation
lms/djangoapps/ccx/models.py
Outdated
@@ -32,6 +32,8 @@ class CustomCourseForEdX(models.Model): | |||
# if not empty, this field contains a json serialized list of | |||
# the master course modules | |||
structure_json = models.TextField(verbose_name='Structure JSON', blank=True, null=True) | |||
# Custom Json field to add any additional information to the CCX model | |||
custom_content = models.JSONField(default=dict, blank=True, null=True, verbose_name="Custom Json Content") |
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.
I think we should name it the same as "other course settings", as they both have the same purpose and having the same name could easily guide the people who will work with this. What do you think? @JuanDavidBuitrago
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.
@Squirrel18 I think it's a good idea, and it makes a lot of sense. Variable name changed.
@@ -52,3 +54,10 @@ def get_course_modules(obj): | |||
Getter for the Course Modules. The list is stored in a compressed field. | |||
""" | |||
return obj.structure or [] | |||
|
|||
@staticmethod | |||
def get_custom_content(obj): |
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.
I think this is not necessary, you could use a DictField, why do you need this? @JuanDavidBuitrago
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.
@Squirrel18 I have updated the serializer to remove the static method get_custom_content
, as other_course_settings
is a JSONField
in the model that already handles default values and ensures it will always return a dictionary. Thanks for the suggestion!
ffff35f
to
23ac007
Compare
On Friday we held a meeting to try to test this PR, the migrations are not recognized by my environment in devstack, in fact it affected the CCX configuration in a negative way. I suggest reviewing and updating the How to Test. |
@nandodev-net The problem is in your local environment, so I shouldn't modify my instructions because there is nothing else I can do from my side. |
It's not a branch problem. Once the configuration for the CCX was redone, the migrations ran without problem. Thanks for the postman collection, I think it's an excellent idea to facilitate testing in PRs! :) |
lms/djangoapps/ccx/models.py
Outdated
@@ -32,6 +32,8 @@ class CustomCourseForEdX(models.Model): | |||
# if not empty, this field contains a json serialized list of | |||
# the master course modules | |||
structure_json = models.TextField(verbose_name='Structure JSON', blank=True, null=True) | |||
# Custom Json field to add any additional information to the CCX model |
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.
Period at the end of the line. @JuanDavidBuitrago
lms/djangoapps/ccx/models.py
Outdated
@@ -32,6 +32,8 @@ class CustomCourseForEdX(models.Model): | |||
# if not empty, this field contains a json serialized list of | |||
# the master course modules | |||
structure_json = models.TextField(verbose_name='Structure JSON', blank=True, null=True) | |||
# Custom Json field to add any additional information to the CCX model | |||
other_course_settings = models.JSONField(default=dict, blank=True, null=True, verbose_name="Custom Json Content") |
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.
other_course_settings = models.JSONField(default=dict, blank=True, null=True, verbose_name="Custom Json Content") | |
other_course_settings = models.JSONField(default=dict(), blank=True, null=True, verbose_name='Custom Json Content') |
lms/djangoapps/ccx/api/v0/views.py
Outdated
@@ -733,6 +761,10 @@ 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: | |||
existing_content = ccx_course_object.other_course_settings | |||
existing_content.update(valid_input.get('other_course_settings')) |
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.
Please, remove this update. @JuanDavidBuitrago
lms/djangoapps/ccx/api/v0/views.py
Outdated
@@ -152,6 +152,13 @@ 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 is not None: |
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.
@Squirrel18 at the end we need to validate if exist in a different level, because when the request doesn't have the value, it returns the field error even though we don't need to add/change it
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.
In this case can't we use: if other_course_settings: and process it if it's present? @JuanDavidBuitrago
baa9ac9
to
2fc55c1
Compare
lms/djangoapps/ccx/api/v0/views.py
Outdated
@@ -152,6 +152,13 @@ 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 is not None: |
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.
In this case can't we use: if other_course_settings: and process it if it's present? @JuanDavidBuitrago
@@ -19,6 +19,7 @@ class CCXCourseSerializer(serializers.ModelSerializer): | |||
due = serializers.CharField(allow_blank=True) | |||
max_students_allowed = serializers.IntegerField(source='max_student_enrollments_allowed') | |||
course_modules = serializers.SerializerMethodField() | |||
other_course_settings = serializers.JSONField() |
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.
As it's now, this field is required: https://www.django-rest-framework.org/api-guide/fields/#required @JuanDavidBuitrago
d0b9885
to
5381560
Compare
5381560
to
5fc8db7
Compare
5fc8db7
to
f995679
Compare
47fbb31
into
pearson-release/olive.stage
Description
This PR adds a new custom content
JSONField
to the CCXCustomCourseForEdX
model, in order to use this field to storage any additional information that we need to associate with.Testing instructions
other_course_settings
field for the CCX in the list.other_course_settings
fieldother_course_settings
field.Note: Here is a Postman collection to import and test easily
Custom content XL-local.postman_collection.json
Jira issue