Certificate template

Hi,

I managed to enable certificates, now I want to tweak the default template. I don’t want to edit the EdX platform template, as forking the platform would be a maintainability nightmare.

I manage to get some custom text through the Django admin panel by following here:

However, I cannot figure out how to customize while starting from the existing template. What is the code that I should copy to start from the existing template ? Where is the code ?

Now that I dug deeper into this, I wonder what is the ETA for porting certificates to MFEs ? I wonder if it is worth it to try to figure out how to customize certificates or if they will be ported to MFEs with some plugin slots for customization any time soon.

Hey, as far as I remember, to use your own html template for certificates you need to:

  1. 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)


  1. 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.

Because using existing plugin slots is much easier than writing your own classes and templates from scratch.