Disabling enroll option in course home page

Hi

I wonder if it is possible to customize the attached course home page.
We would like to remove “Enroll now” options from this page.

When I set “Course Visibility In Catalog”, I get internal server error.
“Invitation Only”, we want to keep as False as we are enrolling students using manage script from backend.

Any tips or hints, please?

Thanks!

you need to set “Invitation Only” option, it will stop the user from enrolling course from the front-end screen but you can do enrollment from the backend through the script anyway.

With “Invitation Only” and using script below error is thrown.

2023-03-06 09:06:05,170 WARNING 3462 [common.djangoapps.student.models] [user None] [ip None] models.py:1667 - User xxxx failed to enroll in course yyyyyyQ+2023_H1 because enrollment is closed

If you are using enrol method then that method has the parameter “check_access” where you can set false from your script. Then you can able to enrol users in the course. if this is not the case then please mention your branch and copy of the code which you have written inside the script to enrol the user.

I am using tutor

tutor, version 14.0.3 - nutmeg

Which enroll method you are referring to, please clarify. The one in data.py?

app@0c73994f3662:~/edx-platform/openedx/core/djangoapps/enrollments$ pwd
/openedx/edx-platform/openedx/core/djangoapps/enrollments
app@0c73994f3662:~/edx-platform/openedx/core/djangoapps/enrollments$ grep -ir "check_access" .
./api.py:    enrollment = _data_api().create_course_enrollment(username, course_id, mode, is_active, enterprise_uuid, check_access=False)
./data.py:        enrollment = CourseEnrollment.enroll(user, course_key, check_access=True, enterprise_uuid=enterprise_uuid)

I am using below script, tried with skip-checks but same error.

app@0c73994f3662:~/edx-platform$ ./manage.py lms --settings production  enroll_user_in_course --help

optional arguments:
  -h, --help            show this help message and exit
  -e EMAIL, --email EMAIL
                        Email for user
  -c COURSE, --course COURSE
                        course ID to enroll the user in
  -m MODE, --mode MODE  course mode to enroll the user in
  --version             show program's version number and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output
  --settings SETTINGS   The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions
  --no-color            Don't colorize the command output.
  --force-color         Force colorization of the command output.
  --skip-checks         Skip system checks.

method which is being called in api.py

def add_enrollment(username, course_id, mode=None, is_active=True, enrollment_attributes=None, enterprise_uuid=None):
    """Enrolls a user in a course.

...

validate_course_mode(course_id, mode, is_active=is_active)
    enrollment = _data_api().create_course_enrollment(username, course_id, mode, is_active, enterprise_uuid, check_access=False)

do you really need to run the command? you can do enrollment from the instructor > membership tab as well.

1 Like

Yes, we have automated the enrollment step using this script.

Thanks for the hint. With invitation only set to “true” and “check_access” flag set to False in data.py did the trick.

course_id, mode, is_active, enterprise_uuid, check_access=False)
./data.py:        enrollment = CourseEnrollment.enroll(user, course_key, check_access=True, enterprise_uuid=enterprise_uuid)
1 Like