Skip to content
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

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

JuanDavidBuitrago
Copy link

@JuanDavidBuitrago JuanDavidBuitrago commented Oct 4, 2024

Description

This PR adds a new custom content JSONField to the CCX CustomCourseForEdX model, in order to use this field to storage any additional information that we need to associate with.

Testing instructions

  1. Using your local environment with this branch, go to the LMS container and run the commands.
python manage.py lms makemigrations
python manage.py lms migrate
  1. Go to http://{base_url}/api/ccx/v0/ccx/?master_course_id={master_course_id} to see the list of CCX courses associate to your master course. Look for the other_course_settings field for the CCX in the list.
{
   "next":null,
   "previous":null,
   "count":7,
   "num_pages":1,
   "current_page":1,
   "start":0,
   "results":[
   {
      "ccx_course_id":"ccx-v1:demo+cs100+2024-t2+ccx@1",
      "master_course_id":"course-v1:demo+cs100+2024-t2",
      "display_name":"skillable edunext test ccx",
      "coach_email":"[email protected]",
      "start":"2024-09-24 13:17:07+00:00",
      "due":null,
      "max_students_allowed":200,
      "course_modules":[],
      "other_course_settings":{}
   }, ...]}
  1. Go to http://{base_url}/api/ccx/v0/ccx/{ccx_course_id} to see the details for a specific CCX course. Again, look for the other_course_settings field
  2. Using Postman, you can test PUT and PATCH request to add/modify the other_course_settings field.

Note: Here is a Postman collection to import and test easily
Custom content XL-local.postman_collection.json

Jira issue

@@ -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")

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

Copy link
Author

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):

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

Copy link
Author

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!

@nandodev-net
Copy link

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.

@JuanDavidBuitrago
Copy link
Author

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.

@nandodev-net
Copy link

nandodev-net commented Oct 7, 2024

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! :)

@@ -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

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

@@ -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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/serializers.py Show resolved Hide resolved
@@ -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'))

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

@@ -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:
Copy link
Author

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

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

@@ -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:

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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuanDavidBuitrago JuanDavidBuitrago merged commit 47fbb31 into pearson-release/olive.stage Oct 8, 2024
13 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants