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

Add CMS management command to update course advanced settings in bulk. #197

Conversation

ztraboo
Copy link

@ztraboo ztraboo commented Dec 14, 2022

Description

Needed a way to set course advanced fields through the Django management command line. Instead of call the REST PATCH endpoint here cms/djangoapps/contentstore/rest_api/v0/views/advanced_settings.py we utilized the update_course_advanced_settings method here cms/djangoapps/contentstore/views/course.py to pass JSON override values for one or more courses.

A --force-update-catalog-visibility-about command option was added to include advanced setting. When upgrading from an older release to Maple we had this catalog_visibility set to none which produced the There was an error loading this course message when viewing the course MFE Learning frontend. It was necessary to make sure these courses didn't have the none value and received about or both settings to have the page load properly. This command sets the value to about to prevent the course from uploading to the course-discovery service and out to the marketing frontend.

{
    "catalog_visibility": {
        "value": "about"
    }
}

Supporting information

We’re running into this issue mentioned above for students to be able to view the MFE learning page when Course Visibility in Catalog is set to none. The students receive the There was an error loading this course. message and nothing loads on the Course Home page. Also the LMS log files indicate no error messages so we were lucky to find this discussion article.

Reference: https://discuss.openedx.org/t/how-to-programmatically-set-a-course-advanced-fields/8901

Testing instructions

When upgrading from prior release to Maple we had several courses with course_visibility set to none value. With this setting we traversed to the MFE Learning frontend and saw error message with There was an error loading this course. and a HTTP 404 response from an EdX API endpoint in the JavaScript console was indicated.

So to regenerate this error just set the CMS > Advanced Settings > Catalog Visibility value to none.

image

HTTP 404 Response was at this address.
https://{{ LMS_HOST }}/api/course_home/course_metadata/course-v1:CUCWD+FAA-ACS-AM-ID-FLF+DOCUMENTATION?browser_timezone=America%2FNew_York

Invoking Management Command

WARNING
We added in a --limit-bulk-update-operation {0-N} command option to prevent the command from consuming all server memory and crashing the server. The default number of courses is set to 150. Please make sure that you pay attention to your server resources before running this command in bulk.

The user passed needs to have superuser rights.

# Single Course
# Set the following advanced settings:
# `invitation_only` to `true`
# `catalog_visilibilty` to `about`
python manage.py cms --settings=devstack_docker set_advanced_fields_all_courses \
--fields_json '{"invitation_only": {"value": "true"}}' --user edx@example.com --course course-v1:ORG+COURSENUMBER+COURSERUN --force-update-catalog-visibility-about

# All Courses
# Set the following advanced settings:
# `invitation_only` to `true`
# `catalog_visilibilty` to `about`
# `cerfificate_display_behavior` to `early_no_info`
python manage.py cms --settings=devstack_docker set_advanced_fields_all_courses \
--fields_json '{"invitation_only": {"value": "true"}, "certificates_display_behavior": {"value": "early_no_info"}}' --user edx@example.com --course course-v1:ORG+COURSENUMBER+COURSERUN --force-update-catalog-visibility-about

# All Courses
# Set the following advanced settings:
# `catalog_visilibilty` to `about`
python manage.py cms --settings=devstack_docker set_advanced_fields_all_courses \
--fields_json '{}' --user edx@example.com --course course-v1:ORG+COURSENUMBER+COURSERUN --force-update-catalog-visibility-about

Needed a way to set course advanced fields through the Django management command line. Instead of call the REST PATCH endpoint here cms/djangoapps/contentstore/rest_api/v0/views/advanced_settings.py we utilized the `update_course_advanced_settings` method here  cms/djangoapps/contentstore/views/course.py to pass JSON override values for one or more courses.

A `--force-update-catalog-visibility-about` command option was added to include advanced setting. When upgrading from an older release to `Maple` we had this `catalog_visibility` set to `none` which produced the `There was an error loading this course` message when viewing the course MFE Learning frontend. It was necessary to make sure these courses didn't have the `none` value and received `about` or `both` settings to have the page load properly. This command sets the value to `about` to prevent the course from uploading to the `course-discovery` service and out to the marketing frontend.
```
{
    "catalog_visibility": {
        "value": "about"
    }
}
```

Reference: https://discuss.openedx.org/t/how-to-programmatically-set-a-course-advanced-fields/8901
…fault at 150 courses to avoid memory consumption on server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants