Hey, as far as I remember, to use your own html template for certificates you need to:
- Turn on the feature flag concerning custom templates (django setting) as it is disabled by default:
lms/envs/common.py
485:# .. toggle_name: settings.CUSTOM_CERTIFICATE_TEMPLATES_ENABLED
494:CUSTOM_CERTIFICATE_TEMPLATES_ENABLED = False
Preferably using a tutor plugin via the openedx-common-settings for example Template patch catalog — Tutor documentation
2) Create a custom certificate template object with attributes like declared in
lms/djangoapps/certificates/models.py
1136:class CertificateTemplate(TimeStampedModel):
Open edX has this system where it looks from most specific to most general when looking for a template to use for a current course (see get_certificate_template(...) in lms/djangoapps/certificates/api.py).
You can do this via the django admin panel at the path Certificates -> Certificate Templates.
If you wanted to automate this upon platform creation I’d make a django app with a command added to tutor’s CLI_DO_INIT_TASKS or something of the sort.
Make sure to set the field Mode to the desired mode (required per Manage Course Certificates — Latest documentation)
- Create a matching
CourseMode object to “offer” the course in the given mode. Also, again can be created from the django panel admin under Course Modes or via a CLI_DO_INIT_TASKS as a command launching python code that interacts with the database.
Note: Make sure the users are enrolled with that same course mode (attr of CourseEnrollment)
common/djangoapps/student/models/course_enrollment.py- mode = models.CharField(default=CourseMode.get_default_mode_slug, max_length=100)
Also I recommend using the pluggable_override decorator from the extensions framework. It is not present in many parts of the code however this is a great place to utilize it! You can very easily add more context into the .html template.
You can wrap or raplce the original html rendering function with any extra logic without touching the source code.
@pluggable_override('OVERRIDE_RENDER_CERTIFICATE_VIEW')
def render_html_view(request, course_id, certificate=None): # pylint: disable=too-many-statements
"""
This public view generates an HTML representation of the specified user and course
If a certificate is not available, we display a "Sorry!" screen instead
It can be overridden by setting `OVERRIDE_RENDER_CERTIFICATE_VIEW` to an alternative implementation.
"""
More on pluggable_override edx-django-utils/edx_django_utils/plugins/pluggable_override.py at master · openedx/edx-django-utils · GitHub
Also, out of curiousity, why migrate this to MFEs? I’d say this is a perfect use case for django’s MVT model - a simple static HTML page, assuming no other functionality is planned.