lms.djangoapps.certificates package

Contents

lms.djangoapps.certificates package#

Subpackages#

Submodules#

lms.djangoapps.certificates.api module#

Certificates API

This provides APIs for generating course certificates asynchronously.

Other Django apps should use the API functions defined here in this module; other apps should not import the certificates models or any other certificates modules.

lms.djangoapps.certificates.api.auto_certificate_generation_enabled()#
lms.djangoapps.certificates.api.available_date_for_certificate(course, certificate) datetime#

Returns the available date to use with a certificate

Parameters:
lms.djangoapps.certificates.api.can_be_added_to_allowlist(user, course_key)#

Determines if a student is able to be added to the allowlist in a given course-run.

lms.djangoapps.certificates.api.can_show_certificate_available_date_field(course)#
lms.djangoapps.certificates.api.can_show_certificate_message(course, student, course_grade, certificates_enabled_for_course)#

Returns True if a course certificate message can be shown

lms.djangoapps.certificates.api.certificate_downloadable_status(student, course_key)#

Check the student existing certificates against a given course. if status is not generating and not downloadable or error then user can view the generate button.

Parameters:
  • student (user object) – logged-in user

  • course_key (CourseKey) – ID associated with the course

Returns:

Dict containing student passed status also download url, uuid for cert if available

lms.djangoapps.certificates.api.certificate_info_for_user(user, course_id, grade, user_is_allowlisted, user_certificate)#

Returns the certificate info for a user for grade report.

lms.djangoapps.certificates.api.certificate_status_for_student(student, course_id)#

This returns a dictionary with a key for status, and other information.

lms.djangoapps.certificates.api.certificates_viewable_for_course(course)#

Returns True if certificates are viewable for any student enrolled in the course, False otherwise.

Parameters:

course (CourseOverview or course block) – The course to check if certificates are viewable

Returns:

whether the certificates are viewable or not

Return type:

boolean

lms.djangoapps.certificates.api.clear_pii_from_certificate_records_for_user(user)#

Utility function to remove PII from certificate records when a learner’s account is being retired. Used by the AccountRetirementView in the user_api Django app (invoked by the /api/user/v1/accounts/retire endpoint).

The update is performed using a bulk SQL update via the Django ORM. This will not trigger the GeneratedCertificate model’s custom save() function, nor fire any Django signals (which is desired at the time of writing). There is nothing to update in our external systems by this update.

Parameters:

user (User) – The User instance of the learner actively being retired.

Returns:

None

lms.djangoapps.certificates.api.create_certificate_invalidation_entry(certificate, user_requesting_invalidation, notes)#

Invalidates a certificate with the given certificate id.

lms.djangoapps.certificates.api.create_generated_certificate(cert_args)#

Creates a new GeneratedCertificate object using the provided arguments.

Parameters:
  • cert_args (dict) – A dictionary containing the certificate’s attributes, such as

  • "user"

  • "course_id"

  • "status"

  • etc.

Returns:

The newly created GeneratedCertificate object.

Return type:

GeneratedCertificate

Raises:

ValueError – If any required fields (“user”, “course_id”) are missing from cert_args.

lms.djangoapps.certificates.api.create_or_update_certificate_allowlist_entry(user, course_key, notes, enabled=True)#

Update-or-create an allowlist entry for a student in a given course-run.

lms.djangoapps.certificates.api.create_or_update_certificate_generation_history(course_id, generated_by, instructor_task, is_regeneration)#

Creates a new certificate generation history record or updates an existing one.

Parameters:
  • course_id (CourseKey) – The unique identifier for the course run.

  • generated_by (User) – The user (typically an instructor or admin) who initiated the certificate generation.

  • instructor_task (str) – A descriptor or task identifier for the instructor-related task.

  • is_regeneration (bool) – A flag indicating whether the certificate is being

  • regenerated (True) or newly generated (False)

Returns:

The created or updated CertificateGenerationHistory instance.

Return type:

CertificateGenerationHistory

lms.djangoapps.certificates.api.create_or_update_eligible_certificate_for_user(user, course_id, status)#

Create or update an eligible GeneratedCertificate for a user in a specific course.

Parameters:
  • user (User) – The user for whom the certificate is being created or updated.

  • course_id (CourseKey) – The unique identifier for the course the certificate applies to.

  • status (str) – The status of the certificate (e.g., “downloadable”, “issued”).

Returns:

A tuple containing:
  • GeneratedCertificate: The created or updated certificate.

  • bool: A boolean indicating whether the certificate was created (True) or updated (False).

Return type:

tuple

lms.djangoapps.certificates.api.display_date_for_certificate(course, certificate)#

Returns the date that should be displayed on a certificate when rendered.

If the certificate has a certificate date override associated with it, display the override date.

Otherwise, if the course has a display behavior of “END_WITH_DATE”, display the associated certificate available date. If the course has a display behavior of “END”, we should display the end date of the course. Lastly, when the display behavior is “EARLY_NO_INFO” or when the course run is self-paced, we display the modified date of the certificate instance.

Parameters:

course (CourseOverview or course block) – The course we’re getting the date for

Returns:

datetime.date

lms.djangoapps.certificates.api.example_certificates_status(course_key)#

Check the status of example certificates for a course.

This will check the latest example certificate task. This is generally what we care about in terms of enabling/disabling self-generated certificates for a course.

Parameters:

course_key (CourseKey) – The course identifier.

Returns:

list

Example Usage:

>>> from lms.djangoapps.certificates import api as certs_api
>>> certs_api.example_certificates_status(course_key)
[
    {
        'description': 'honor',
        'status': 'success',
        'download_url': 'https://www.example.com/abcd/honor_cert.pdf'
    },
    {
        'description': 'verified',
        'status': 'error',
        'error_reason': 'No template found!'
    }
]
lms.djangoapps.certificates.api.generate_certificate_task(user, course_key, generation_mode=None)#

Create a task to generate a certificate for this user in this course run, if the user is eligible and a certificate can be generated.

If the allowlist is enabled for this course run and the user is on the allowlist, the allowlist logic will be used. Otherwise, the regular course certificate generation logic will be used.

Parameters:
  • user – user for whom to generate a certificate

  • course_key – course run key for which to generate a certificate

  • generation_mode – Used when emitting an events. Options are “self” (implying the user generated the cert themself) and “batch” for everything else.

lms.djangoapps.certificates.api.get_active_web_certificate(course, is_preview_mode=None)#

Retrieves the active web certificate configuration for the specified course

lms.djangoapps.certificates.api.get_allowlist(course_key)#

Return the certificate allowlist for the given course run

lms.djangoapps.certificates.api.get_allowlist_entry(user, course_key)#

Retrieves and returns an allowlist entry for a given learner and course-run.

lms.djangoapps.certificates.api.get_allowlisted_users(course_key)#

Return the users who are on the allowlist for this course run

lms.djangoapps.certificates.api.get_asset_url_by_slug(asset_slug)#

Returns certificate template asset url for given asset_slug.

lms.djangoapps.certificates.api.get_cert_history_for_course_id(course_id)#

Retrieve all certificate generation history records for the specified course.

Parameters:

course_id (CourseLocator | CourseKey) – The unique identifier for the course.

Returns:

A queryset of all certificate generation history records associated with the specified course.

Return type:

QuerySet[CertificateGenerationHistory]

lms.djangoapps.certificates.api.get_cert_invalidations_for_course(course_key)#

Retrieves all certificate invalidations associated with the specified course.

Parameters:

course_key (CourseKey) – The unique identifier for the course run.

Returns:

A queryset containing all invalidations for the specified course.

Return type:

QuerySet[CertificateInvalidation]

Return data to be used in Certificate Footer, data returned should be customized according to the site configuration.

lms.djangoapps.certificates.api.get_certificate_for_user(username, course_key, format_results=True)#

Retrieve certificate information for a particular user for a specific course.

Parameters:
  • username (unicode) – The identifier of the user.

  • course_key (CourseKey) – A Course Key.

  • format_results (boolean) – Default True. If False, return the GeneratedCertificate object instead of the serialized dict representation.

Returns:

A dict containing a serialized representation of the certificate or, optionally, the GeneratedCertificate object itself. If there is no GeneratedCertificate object for the user and course combination, returns None.

lms.djangoapps.certificates.api.get_certificate_for_user_id(user, course_id)#

Retrieve certificate information for a user in a specific course.

Parameters:
  • user (User) – A Django User.

  • course_id (CourseKey) – Course ID

Returns:

A GeneratedCertificate object.

lms.djangoapps.certificates.api.get_certificate_generation_history(course_id=None, generated_by=None, instructor_task=None, is_regeneration=None)#

Retrieves a queryset of CertificateGenerationHistory records, filtered by the provided criteria.

Parameters:
  • course_id (Optional[CourseKey]) – The unique ID of the course (if filtering by course).

  • generated_by (Optional[User]) – The user who generated the certificate (if filtering by user).

  • instructor_task (Optional[bool]) – Whether the certificate generation was triggered by an instructor task.

  • is_regeneration (Optional[bool]) – Whether the certificate was regenerated.

Returns:

A queryset of filtered CertificateGenerationHistory records.

Return type:

QuerySet[CertificateGenerationHistory]

lms.djangoapps.certificates.api.get_certificate_header_context(is_secure=True)#

Return data to be used in Certificate Header, data returned should be customized according to the site configuration.

lms.djangoapps.certificates.api.get_certificate_invalidation_entry(generated_certificate, invalidated_by=None, notes=None, active=None)#

Retrieve a certificate invalidation entry for a specified certificate.

Optionally filter the invalidation entry by who invalidated it, notes, and whether the invalidation is active.

Parameters:
  • generated_certificate (GeneratedCertificate) – The certificate to find the invalidation entry for.

  • invalidated_by (User, optional) – User who invalidated the certificate. Defaults to None.

  • notes (str, optional) – Notes associated with the invalidation. Defaults to None.

  • active (bool, optional) – Whether the invalidation entry is currently active. Defaults to None.

Returns:

The matching invalidation entry if found, else None.

Return type:

CertificateInvalidationEntry or None

lms.djangoapps.certificates.api.get_certificate_template(course_key, mode, language)#

Retrieves the custom certificate template based on course_key, mode, and language.

lms.djangoapps.certificates.api.get_certificate_url(user_id=None, course_id=None, uuid=None, user_certificate=None)#
lms.djangoapps.certificates.api.get_certificates_by_course_and_status(course_id, status)#

Retrieves all eligible certificates for a specific course and status.

Parameters:
  • course_id (CourseKey) – The unique identifier for the course run.

  • status (str) – The status of the certificates to filter by (e.g., “downloadable”, “issued”).

Returns:

A queryset containing the eligible certificates matching the provided course ID and status.

Return type:

QuerySet[GeneratedCertificate]

lms.djangoapps.certificates.api.get_certificates_for_course_and_users(course_id, users)#

Retrieves all GeneratedCertificate records for a specific course and a list of users.

Parameters:
  • course_id (CourseKey) – The unique identifier for the course run.

  • users (Iterable[User]) – A list or queryset of User instances to filter certificates by.

Returns:

A queryset containing the matching certificate records.

Return type:

QuerySet[GeneratedCertificate]

lms.djangoapps.certificates.api.get_certificates_for_user(username)#

Retrieve certificate information for a particular user.

Parameters:

username (unicode) – The identifier of the user.

Returns: list

Example Usage: >>> get_certificates_for_user(“bob”) [

{

“username”: “bob”, “course_key”: CourseLocator(‘edX’, ‘DemoX’, ‘Demo_Course’, None, None), “type”: “verified”, “status”: “downloadable”, “download_url”: “https://www.example.com/cert.pdf”, “grade”: “0.98”, “created”: 2015-07-31T00:00:00Z, “modified”: 2015-07-31T00:00:00Z

}

]

lms.djangoapps.certificates.api.get_certificates_for_user_by_course_keys(user, course_keys)#

Retrieve certificate information for a particular user for a set of courses.

Parameters:
  • user (User)

  • course_keys (set[CourseKey])

Returns: dict[CourseKey: dict]

Mapping from course keys to dict of certificate data. Course keys for courses for which the user does not have a certificate will be omitted.

lms.djangoapps.certificates.api.get_certs_with_modified_overrides(course_keys=None, start_date=None, end_date=None, user_ids=None)#

Returns a QuerySet of certificates with a CertificateDateOverride modified within the given start_date and end_date. Uses the history table to catch deleted overrides too.

lms.djangoapps.certificates.api.get_course_ids_from_certs_for_user(username)#

Retrieves a list of course IDs for which the given user has generated certificates.

Parameters:

username (str) – The username of the user whose course IDs are being retrieved.

Returns:

A list of course IDs for which the user has generated certificates.

If no certificates are found, an empty list is returned.

Return type:

list

lms.djangoapps.certificates.api.get_eligible_and_available_certificates(user)#

Retrieves all eligible and available certificates for the specified user.

Parameters:

user (User) – The user whose eligible and available certificates are being retrieved.

Returns:

A queryset containing all eligible and available certificates for the specified user.

Return type:

QuerySet[GeneratedCertificate]

lms.djangoapps.certificates.api.get_eligible_certificate(user, course_id)#

Retrieves the eligible GeneratedCertificate for a given user and course.

Parameters:
  • user (User) – The user object for whom the certificate is being retrieved.

  • course_id (CourseKey) – The unique identifier for the course run.

Returns:

The eligible certificate instance if one exists; otherwise, None.

Return type:

GeneratedCertificate or None

lms.djangoapps.certificates.api.get_enrolled_allowlisted_not_passing_users(course_key)#

Get all users who: - are enrolled in this course run - are allowlisted in this course run - do not have a course certificate with a passing status

lms.djangoapps.certificates.api.get_enrolled_allowlisted_users(course_key)#

Get all users who: - are enrolled in this course run - are allowlisted in this course run

lms.djangoapps.certificates.api.get_generated_certificate(user, course_id)#

Retrieves the GeneratedCertificateData for the given user and course.

Parameters:
  • user (User) – The user for whom the certificate is being fetched.

  • course_id (CourseKey) – The unique identifier for the course.

Returns:

A GeneratedCertificateData object if found, otherwise None.

Return type:

Optional[GeneratedCertificateData]

lms.djangoapps.certificates.api.get_recently_modified_certificates(course_keys=None, start_date=None, end_date=None, user_ids=None)#

Returns a QuerySet of GeneratedCertificate objects filtered by the input parameters and ordered by modified_date.

lms.djangoapps.certificates.api.get_unique_certificate_statuses(course_key)#

Retrieves the unique certificate statuses for the specified course.

Parameters:

course_key (CourseKey) – The unique identifier for the course run.

Returns:

A queryset containing the unique certificate statuses for the specified course.

Return type:

QuerySet[str]

lms.djangoapps.certificates.api.has_html_certificates_enabled(course_overview)#
lms.djangoapps.certificates.api.has_self_generated_certificates_enabled(course_key)#

Check whether the self-generated certificates feature is enabled for a given course.

There are two “switches” that control whether self-generated certificates are enabled for a course:

  1. Whether the self-generated certificates feature is enabled.

  2. Whether self-generated certificates have been enabled for this particular course.

Certificates are enabled for a course only when both switches are set to True.

Parameters:

course_key (CourseKey) – The course identifier.

Returns:

Whether self-generated certificates are enabled

for the course.

Return type:

boolean

lms.djangoapps.certificates.api.invalidate_certificate(user_id, course_key_or_id, source)#

Invalidate the user certificate in a given course if it exists and the user is not on the allowlist for this course run.

This function is called in services.py and signals.py within the certificates folder. As of now, The call in services.py occurs when an exam attempt is rejected in the legacy exams backend, edx-proctoring. The call in signals.py is occurs when an exam attempt is rejected in the newer exams backend, edx-exams.

lms.djangoapps.certificates.api.is_certificate_generation_enabled()#

Checks if certificate generation is currently enabled.

This function queries the CertificateGenerationConfiguration model to retrieve the current configuration and returns whether certificate generation is enabled or not.

Returns:

True if certificate generation is enabled, False otherwise.

Return type:

bool

lms.djangoapps.certificates.api.is_certificate_invalidated(student, course_key)#

Check whether the certificate belonging to the given student (in given course) has been invalidated.

Parameters:
  • student (user object) – logged-in user

  • course_key (CourseKey) – The course identifier.

Returns:

Boolean denoting whether the certificate has been invalidated for this learner.

lms.djangoapps.certificates.api.is_on_allowlist(user, course_key)#

Determines if a learner has an active allowlist entry for a given course-run.

lms.djangoapps.certificates.api.is_valid_pdf_certificate(cert_data)#
lms.djangoapps.certificates.api.remove_allowlist_entry(user, course_key)#

Removes an allowlist entry for a user in a given course-run. If a certificate exists for the student in the course-run we will also attempt to invalidate the it before removing them from the allowlist.

Returns the result of the removal operation as a bool.

lms.djangoapps.certificates.api.set_cert_generation_enabled(course_key, is_enabled)#

Enable or disable self-generated certificates for a course.

There are two “switches” that control whether self-generated certificates are enabled for a course:

  1. Whether the self-generated certificates feature is enabled.

  2. Whether self-generated certificates have been enabled for this particular course.

The second flag should be enabled only when someone has successfully generated example certificates for the course. This helps avoid configuration errors (for example, not having a template configured for the course installed on the workers). The UI for the instructor dashboard enforces this constraint.

Parameters:

course_key (CourseKey) – The course identifier.

Keyword Arguments:

is_enabled (boolean) – If provided, enable/disable self-generated certificates for this course.

lms.djangoapps.certificates.api.set_certificate_generation_config(enabled=True)#

Configures the certificate generation settings.

Parameters:

enabled (bool) – If True, enables certificate generation; if False, disables it. Default is True.

Returns:

The created or updated certificate generation configuration object.

Return type:

CertificateGenerationConfiguration

lms.djangoapps.certificates.apps module#

Certificates Application Configuration

Signal handlers are connected here.

class lms.djangoapps.certificates.apps.CertificatesConfig(app_name, app_module)#

Bases: AppConfig

Application Configuration for Certificates.

name = 'lms.djangoapps.certificates'#
ready()#

Connect handlers to signals.

lms.djangoapps.certificates.config module#

This module contains various configuration settings via waffle switches for the Certificates app.

lms.djangoapps.certificates.data module#

Certificates Data

This provides Data models to represent Certificates data.

class lms.djangoapps.certificates.data.CertificateStatuses#

Bases: object

Enum for certificate statuses.

Not all of these statuses are currently used. Some are kept for historical reasons and because existing course certificates may have been granted that status.

audit_notpassing - User is in the audit track and has not achieved a passing grade. audit_passing - User is in the audit track and has achieved a passing grade. deleted - The PDF certificate has been deleted. deleting - A request has been made to delete the PDF certificate. downloadable - The user has been granted this certificate and the certificate is ready and available. error - An error occurred during PDF certificate generation. generating - A request has been made to generate a PDF certificate, but it has not been generated yet. honor_passing - User is in the honor track and has achieved a passing grade. invalidated - Certificate is not valid. notpassing - The user has not achieved a passing grade. requesting - A request has been made to generate the PDF certificate. restricted - The user is restricted from receiving a certificate. unavailable - Certificate has been invalidated. unverified - The user does not have an approved, unexpired identity verification.

The following statuses are set by the current course certificates code:

downloadable - See generation.py notpassing - See GeneratedCertificate.mark_notpassing() unavailable - See GeneratedCertificate.invalidate() unverified - See GeneratedCertificate.mark_unverified()

NON_REFUNDABLE_STATUSES = ('downloadable', 'generating', 'unavailable')#
PASSED_STATUSES = ('downloadable', 'generating')#
audit_notpassing = 'audit_notpassing'#
audit_passing = 'audit_passing'#
auditing = 'auditing'#
deleted = 'deleted'#
deleting = 'deleting'#
downloadable = 'downloadable'#
error = 'error'#
generating = 'generating'#
honor_passing = 'honor_passing'#
invalidated = 'invalidated'#
classmethod is_passing_status(status)#

Given the status of a certificate, return a boolean indicating whether the student passed the course.

classmethod is_refundable_status(status)#

Given the status of a certificate, check to see if that certificate status can be refunded.

Parameters:

status (str) – The status of the certificate that you are checking

Returns:

True if the status is refundable.

Return type:

bool

notpassing = 'notpassing'#
readable_statuses = {'audit_notpassing': 'Audit - Not Passing', 'audit_passing': 'Audit - Passing', 'downloadable': 'Received', 'error': 'Error State', 'notpassing': 'Not Received', 'unavailable': 'Invalidated'}#
requesting = 'requesting'#
restricted = 'restricted'#
unavailable = 'unavailable'#
unverified = 'unverified'#
class lms.djangoapps.certificates.data.GeneratedCertificateData(user: User, course_id: CourseKey, verify_uuid: str = '', grade: str = '', key: str = '', distinction: bool = False, status: str = 'unavailable', mode: str = 'honor', name: str = '', created_date: str = None, modified_date: str = None, download_uuid: str = '', download_url: str = '', error_reason: str = '')#

Bases: object

A data representation of a generated course certificate.

This class encapsulates the essential fields related to a user’s generated certificate, including course information, user identity, certificate status, grade, and download metadata.

user#

The user who earned the certificate.

Type:

User

course_id#

Identifier for the course associated with the certificate.

Type:

CourseKey

verify_uuid#

UUID used to verify the certificate.

Type:

str

grade#

The grade achieved in the course.

Type:

str

key#

Internal key identifier for the certificate.

Type:

str

distinction#

Whether the certificate was issued with distinction.

Type:

bool

status#

Current status of the certificate (e.g., ‘downloadable’, ‘unavailable’).

Type:

str

mode#

Enrollment mode at the time of certificate issuance (e.g., ‘honor’, ‘verified’).

Type:

str

name#

Full name as it appears on the certificate.

Type:

str

created_date#

Timestamp for when the certificate was created.

Type:

str

modified_date#

Timestamp for when the certificate was last modified.

Type:

str

download_uuid#

UUID used for generating the download URL.

Type:

str

download_url#

Direct URL to download the certificate.

Type:

str

error_reason#

Reason for any certificate generation failure, if applicable.

Type:

str

validate_mode()#

Validates that the mode is within the supported set of enrollment modes.

course_id: CourseKey#
created_date: str = None#
distinction: bool = False#
download_url: str = ''#
download_uuid: str = ''#
error_reason: str = ''#
grade: str = ''#
key: str = ''#
mode: str = 'honor'#
modified_date: str = None#
name: str = ''#
status: str = 'unavailable'#
user: User#
validate_mode()#
verify_uuid: str = ''#

lms.djangoapps.certificates.generation module#

Course certificate generation

These methods generate course certificates (they create a new course certificate if it does not yet exist, or update the existing cert if it does already exist).

These methods should be called from tasks.

lms.djangoapps.certificates.generation.generate_course_certificate(user, course_key, status, enrollment_mode, course_grade, generation_mode)#

Generate a course certificate for this user, in this course run. If the certificate has a passing status, also emit a certificate event.

Note that the certificate could be either an allowlist certificate or a “regular” course certificate; the content will be the same either way.

Parameters:
  • user – user for whom to generate a certificate

  • course_key – course run key for which to generate a certificate

  • status – certificate status (value from the CertificateStatuses model)

  • enrollment_mode – user’s enrollment mode (ex. verified)

  • course_grade – user’s course grade

  • generation_mode – used when emitting an event. Options are “self” (implying the user generated the cert themself) and “batch” for everything else.

lms.djangoapps.certificates.generation_handler module#

Course certificate generation handler.

These methods check to see if a certificate can be generated (created if it does not already exist, or updated if it exists but its state can be altered). If so, a celery task is launched to do the generation. If the certificate cannot be generated, a message is logged and no further action is taken.

exception lms.djangoapps.certificates.generation_handler.CertificateGenerationNotAllowed#

Bases: GeneratedCertificateException

exception lms.djangoapps.certificates.generation_handler.GeneratedCertificateException#

Bases: Exception

lms.djangoapps.certificates.generation_handler.generate_allowlist_certificate_task(user, course_key, generation_mode=None, delay_seconds=2)#

Create a task to generate an allowlist certificate for this user in this course run.

lms.djangoapps.certificates.generation_handler.generate_certificate_task(user, course_key, generation_mode=None, delay_seconds=2)#

Create a task to generate a certificate for this user in this course run, if the user is eligible and a certificate can be generated.

If the allowlist is enabled for this course run and the user is on the allowlist, the allowlist logic will be used. Otherwise, the regular course certificate generation logic will be used.

lms.djangoapps.certificates.generation_handler.is_on_certificate_allowlist(user, course_key)#

Check if the user is on the allowlist, and is enabled for the allowlist, for this course run

lms.djangoapps.certificates.models module#

Course certificates are created for a student and an offering of a course (a course run).

class lms.djangoapps.certificates.models.CertificateAllowlist(*args, **kwargs)#

Bases: TimeStampedModel

Tracks students who are on the certificate allowlist for a given course run.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

allowlist#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

course_id#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod get_certificate_allowlist(course_id, student=None)#

Return the certificate allowlist for the given course as a list of dict objects with the following key-value pairs:

[{

id: ‘id (pk) of CertificateAllowlist item’ user_id: ‘User Id of the student’ user_name: ‘name of the student’ user_email: ‘email of the student’ course_id: ‘Course key of the course to whom certificate exception belongs’ created: ‘Creation date of the certificate exception’ notes: ‘Additional notes for the certificate exception’

}, {…}, …]

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

notes#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <openedx.core.djangoapps.xmodule_django.models.NoneToEmptyManager object>#
save_without_historical_record(*args, **kwargs)#

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

user#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id#
class lms.djangoapps.certificates.models.CertificateDateOverride(*args, **kwargs)#

Bases: TimeStampedModel

Model to manually override a given certificate date with the given date.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

generated_certificate#

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

generated_certificate_id#
get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_date(*, field=<django.db.models.fields.DateTimeField: date>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_date(*, field=<django.db.models.fields.DateTimeField: date>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
overridden_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

overridden_by_id#
reason#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save(*args, **kwargs)#

After the base save() method finishes, fire the COURSE_CERT_CHANGED signal.

save_without_historical_record(*args, **kwargs)#

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

send_course_cert_changed_signal()#
class lms.djangoapps.certificates.models.CertificateGenerationCommandConfiguration(*args, **kwargs)#

Bases: ConfigurationModel

Manages configuration for a run of the cert_generation management command.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

arguments#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

change_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

changed_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

changed_by_id#
enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.certificates.models.CertificateGenerationConfiguration(*args, **kwargs)#

Bases: ConfigurationModel

Configure certificate generation.

Enable or disable the self-generated certificates feature. When this flag is disabled, the “generate certificate” button will be hidden on the progress page.

When the feature is enabled, the “generate certificate” button will appear for courses that have enabled self-generated certificates.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

change_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

changed_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

changed_by_id#
enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.certificates.models.CertificateGenerationCourseSetting(*args, **kwargs)#

Bases: TimeStampedModel

Enable or disable certificate generation for a particular course.

In general, we should only enable self-generated certificates for a course once we successfully generate example certificates for the course. This is enforced in the UI layer, but not in the data layer.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

course_key#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod get(course_key)#

Retrieve certificate generation settings for a course.

Parameters:

course_key (CourseKey) – The identifier for the course.

Returns:

CertificateGenerationCourseSetting

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

include_hours_of_effort#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod is_self_generation_enabled_for_course(course_key)#

Check whether self-generated certificates are enabled for a course.

Parameters:

course_key (CourseKey) – The identifier for the course.

Returns:

boolean

language_specific_templates_enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
self_generation_enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod set_self_generation_enabled_for_course(course_key, is_enabled)#

Enable or disable self-generated certificates for a course.

Parameters:
  • course_key (CourseKey) – The identifier for the course.

  • is_enabled (boolean) – Whether to enable or disable self-generated certificates.

class lms.djangoapps.certificates.models.CertificateGenerationHistory(*args, **kwargs)#

Bases: TimeStampedModel

Model for storing Certificate Generation History.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

course_id#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

generated_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

generated_by_id#
get_certificate_generation_candidates()#

Return the candidates for certificate generation task. It could either be students or certificate statuses depending upon the nature of certificate generation task. Returned value could be one of the following,

  1. “All learners” Certificate Generation task was initiated for all learners of the given course.

  2. Comma separated list of certificate statuses, This usually happens when instructor regenerates certificates.

  3. “for exceptions”, This is the case when instructor generates certificates for allowlisted

    students.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
get_task_name()#

Return “regenerated” if record corresponds to Certificate Regeneration task, otherwise returns ‘generated’

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

instructor_task#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

instructor_task_id#
is_regeneration#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
class lms.djangoapps.certificates.models.CertificateHtmlViewConfiguration(*args, **kwargs)#

Bases: ConfigurationModel

Static values for certificate HTML view context parameters. Default values will be applied across all certificate types (course modes) Matching ‘mode’ overrides will be used instead of defaults, where applicable Example configuration :

{
“default”: {

“url”: “https://www.edx.org”, “logo_src”: “https://www.edx.org/static/images/logo.png

}, “honor”: {

}

}

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

change_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

changed_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

changed_by_id#
clean()#

Ensures configuration field contains valid JSON.

configuration#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod get_config()#

Retrieves the configuration field value from the database

get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.certificates.models.CertificateInvalidation(*args, **kwargs)#

Bases: TimeStampedModel

Model for storing Certificate Invalidation.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

active#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

deactivate()#

Deactivate certificate invalidation by setting active to False.

generated_certificate#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

generated_certificate_id#
classmethod get_certificate_invalidations(course_key, student=None)#

Return certificate invalidations filtered based on the provided course and student (if provided),

Returned value is JSON serializable list of dicts, dict element would have the following key-value pairs.
  1. id: certificate invalidation id (primary key)

  2. user: username of the student to whom certificate belongs

  3. invalidated_by: user id of the instructor/support user who invalidated the certificate

  4. created: string containing date of invalidation in the following format “December 29, 2015”

  5. notes: string containing notes regarding certificate invalidation.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
classmethod has_certificate_invalidation(student, course_key)#

Check that whether the student in the course has been invalidated for receiving certificates.

Parameters:
  • student (user) – logged-in user

  • course_key (CourseKey) – The course associated with the certificate.

Returns:

Boolean denoting whether the student in the course is invalidated to receive certificates

history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

invalidated_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

invalidated_by_id#
modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

notes#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
save_without_historical_record(*args, **kwargs)#

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

class lms.djangoapps.certificates.models.CertificateSocialNetworks#

Bases: object

Enum for certificate social networks

facebook = 'Facebook'#
linkedin = 'LinkedIn'#
twitter = 'Twitter'#
class lms.djangoapps.certificates.models.CertificateTemplate(*args, **kwargs)#

Bases: TimeStampedModel

A set of custom web certificate templates.

Web certificate templates are Django web templates to replace PDF certificate.

A particular course may have several kinds of certificate templates (e.g. honor and verified).

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

course_key#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

description#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_mode_display(*, field=<django.db.models.fields.CharField: mode>)#
get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_active#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

language#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

mode#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
organization_id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

template#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.certificates.models.CertificateTemplateAsset(*args, **kwargs)#

Bases: TimeStampedModel

A set of assets to be used in custom web certificate templates.

This model stores assets used in custom web certificate templates such as image, css files.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

asset#

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
asset_slug#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

description#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
save(*args, **kwargs)#

save the certificate template asset

class lms.djangoapps.certificates.models.EligibleAvailableCertificateManager(*args, **kwargs)#

Bases: EligibleCertificateManager

A manager for GeneratedCertificate models that automatically filters out ineligible certs and any linked to nonexistent courses.

Adds to the super class filtering to also exclude certificates for courses that do not have a corresponding CourseOverview.

get_queryset()#

Return a queryset for GeneratedCertificate models, filtering out ineligible certificates and any linked to nonexistent courses.

class lms.djangoapps.certificates.models.EligibleCertificateManager(*args, **kwargs)#

Bases: Manager

A manager for GeneratedCertificate models that automatically filters out ineligible certs.

The idea is to prevent accidentally granting certificates to students who have not enrolled in a cert-granting mode. The alternative is to filter by eligible_for_certificate=True every time certs are searched for, which is verbose and likely to be forgotten.

get_queryset()#

Return a queryset for GeneratedCertificate models, filtering out ineligible certificates.

class lms.djangoapps.certificates.models.ExampleCertificate(*args, **kwargs)#

Bases: TimeStampedModel

Example certificate.

Example certificates are used to verify that certificate generation is working for a particular course.

An example certificate is similar to an ordinary certificate, except that:

  1. Example certificates are not associated with a particular user,

    and are never displayed to students.

  2. We store the “inputs” for generating the example certificate

    to make it easier to debug when certificate generation fails.

  3. We use dummy values.

exception DoesNotExist#

Bases: ObjectDoesNotExist

EXAMPLE_FULL_NAME = 'John Doë'#
exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

STATUS_ERROR = 'error'#
STATUS_STARTED = 'started'#
STATUS_SUCCESS = 'success'#
access_key#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property course_key#

The course key associated with the example certificate.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

description#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

download_url#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

error_reason#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

example_cert_set#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

example_cert_set_id#
full_name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
get_status_display(*, field=<django.db.models.fields.CharField: status>)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
status#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property status_dict#

Summarize the status of the example certificate.

Returns:

dict

template#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

update_status(status, error_reason=None, download_url=None)#

Update the status of the example certificate.

This will usually be called either: 1) When an error occurs adding the certificate to the queue. 2) When we receive a response from the queue (either error or success).

If an error occurs, we store the error message; if certificate generation is successful, we store the URL for the generated certificate.

Parameters:

status (str) – Either STATUS_SUCCESS or STATUS_ERROR

Keyword Arguments:
  • error_reason (unicode) – A description of the error that occurred.

  • download_url (unicode) – The URL for the generated certificate.

Raises:

ValueError – The status is not a valid value.

uuid#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.certificates.models.ExampleCertificateSet(*args, **kwargs)#

Bases: TimeStampedModel

A set of example certificates.

Example certificates are used to verify that certificate generation is working for a particular course.

A particular course may have several kinds of certificates (e.g. honor and verified), in which case we generate multiple example certificates for the course.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

course_key#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

classmethod create_example_set(course_key)#

Create a set of example certificates for a course.

Parameters:

course_key (CourseKey)

Returns:

ExampleCertificateSet

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

examplecertificate_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod latest_status(course_key)#

Summarize the latest status of example certificates for a course.

Parameters:

course_key (CourseKey)

Returns:

List of status dictionaries. If no example certificates

have been started yet, returns None.

Return type:

list

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
class lms.djangoapps.certificates.models.GeneratedCertificate(*args, **kwargs)#

Bases: Model

Base model for generated course certificates

course_id - Course run key created_date - Date and time the certificate was created distinction - Indicates whether the user passed the course with distinction. Currently unused. download_url - URL where the PDF version of the certificate, if any, can be found download_uuid - UUID associated with a PDF certificate error_reason - Reason a PDF certificate could not be created grade - User’s grade in this course run. This grade is set at the same time as the status. This

GeneratedCertificate grade is not updated whenever the user’s course grade changes and so it should not be considered the source of truth. It is suggested that the PersistentCourseGrade be used instead of the GeneratedCertificate grade.

key - Certificate identifier, used for PDF certificates mode - Course run mode (ex. verified) modified_date - Date and time the certificate was last modified name - User’s name status - Certificate status value; see the CertificateStatuses model user - User associated with the certificate verify_uuid - Unique identifier for the certificate

class CourseMode(*args, **kwargs)#

Bases: Model

We would like to offer a course in a variety of modes.

ALL_MODES = ['audit', 'credit', 'honor', 'no-id-professional', 'professional', 'verified', 'masters', 'executive-education', 'paid-executive-education', 'unpaid-executive-education', 'paid-bootcamp', 'unpaid-bootcamp']#
AUDIT = 'audit'#
AUDIT_MODES = ['audit', 'honor', 'unpaid-executive-education', 'unpaid-bootcamp']#
CACHE_NAMESPACE = 'course_modes.CourseMode.cache.'#
CERTIFICATE_RELEVANT_MODES = ['credit', 'verified', 'professional', 'no-id-professional', 'executive-education', 'paid-executive-education', 'paid-bootcamp', 'masters']#
CREDIT_ELIGIBLE_MODES = ['verified', 'professional', 'no-id-professional', 'executive-education', 'paid-executive-education', 'paid-bootcamp']#
CREDIT_MODE = 'credit'#
CREDIT_MODES = ['credit']#
DEFAULT_MODE = ('audit', 'Audit', 0, '', 'usd', None, None, None, None, None, None)#
DEFAULT_MODE_SLUG = 'audit'#
exception DoesNotExist#

Bases: ObjectDoesNotExist

EXECUTIVE_EDUCATION = 'executive-education'#
HONOR = 'honor'#
MASTERS = 'masters'#
exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

NON_VERIFIED_MODES = ['honor', 'audit', 'no-id-professional']#
NO_ID_PROFESSIONAL_MODE = 'no-id-professional'#
PAID_BOOTCAMP = 'paid-bootcamp'#
PAID_EXECUTIVE_EDUCATION = 'paid-executive-education'#
PROFESSIONAL = 'professional'#
UNPAID_BOOTCAMP = 'unpaid-bootcamp'#
UNPAID_EXECUTIVE_EDUCATION = 'unpaid-executive-education'#
UPSELL_TO_VERIFIED_MODES = ['honor', 'audit']#
VERIFIED = 'verified'#
VERIFIED_MODES = ['verified', 'professional', 'masters', 'executive-education', 'paid-executive-education', 'paid-bootcamp']#
classmethod all_and_unexpired_modes_for_courses(course_id_list)#

Retrieve course modes for a list of courses.

To reduce the number of database queries, this function loads all course modes, then creates a second list of unexpired course modes.

Parameters:

course_id_list (list of CourseKey) – List of courses for which to retrieve course modes.

Returns:

Tuple of (all_course_modes, unexpired_course_modes), where the first is a list of all `Mode`s (including expired ones), and the second is a list of only unexpired `Mode`s.

classmethod all_modes_for_courses(course_id_list)#

Find all modes for a list of course IDs, including expired modes.

Courses that do not have a course mode will be given a default mode.

Parameters:

course_id_list (list) – List of `CourseKey`s

Returns:

dict mapping CourseKey to lists of Mode

android_sku#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod auto_enroll_mode(course_id, modes_dict=None)#

return the auto-enrollable mode from given dict

Parameters:

modes_dict (dict) – course modes.

Returns:

Mode name

Return type:

String

bulk_sku#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod can_auto_enroll(course_id, modes_dict=None)#

Check whether students should be auto-enrolled in the course.

If a course is behind a paywall (e.g. professional ed or white-label), then users should NOT be auto-enrolled. Instead, the user will be enrolled when he/she completes the payment flow.

Otherwise, users can be enrolled in the default mode “honor” with the option to upgrade later.

Parameters:

course_id (CourseKey) – The course to check.

Keyword Arguments:

modes_dict (dict) – If provided, use these course modes. Useful for avoiding unnecessary database queries.

Returns:

bool

clean()#

Object-level validation - implemented in this method so DRF serializers catch errors in advance of a save() attempt.

classmethod contains_audit_mode(modes_dict)#

Check whether the modes_dict contains an audit mode.

Parameters:

modes_dict (dict) – a dict of course modes

Returns:

whether modes_dict contains an audit mode

Return type:

bool

classmethod contains_masters_mode(modes_dict)#

Check whether the modes_dict contains a Master’s mode.

Parameters:

modes_dict (dict) – a dict of course modes

Returns:

whether modes_dict contains a Master’s mode

Return type:

bool

course#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

course_id#
coursemodetarget_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

currency#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

description#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

expiration_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property expiration_datetime#

Return _expiration_datetime.

expiration_datetime_is_explicit#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod get_default_mode_slug()#

Returns the default mode slug to be used in the CourseEnrollment model mode field as the default value.

classmethod has_payment_options(course_id)#

Determines if there is any mode that has payment options

Check the dict of course modes and see if any of them have a minimum price or suggested prices. Returns True if any course mode has a payment option.

Parameters:

course_mode_dict (dict) – Dictionary mapping course mode slugs to Modes

Returns:

True if any course mode has a payment option.

classmethod has_professional_mode(modes_dict)#

check the course mode is profession or no-id-professional

Parameters:

modes_dict (dict) – course modes.

Returns:

bool

classmethod has_verified_mode(course_mode_dict)#

Check whether the modes for a course allow a student to pursue a verified certificate.

Parameters:

course_mode_dict (dictionary mapping course mode slugs to Modes)

Returns:

True iff the course modes contain a verified track.

Return type:

bool

history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ios_sku#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod is_credit_eligible_slug(mode_slug)#

Check whether the given mode_slug is credit eligible or not.

Parameters:

mode_slug (str) – Mode Slug

Returns:

True iff the course mode slug is credit eligible else False.

Return type:

bool

classmethod is_credit_mode(course_mode_tuple)#

Check whether this is a credit mode.

Students enrolled in a credit mode are eligible to receive university credit upon completion of a course.

classmethod is_eligible_for_certificate(mode_slug, status=None)#

Returns whether or not the given mode_slug is eligible for a certificate. Currently all modes other than ‘audit’ grant a certificate. Note that audit enrollments which existed prior to December 2015 were given certificates, so there will be GeneratedCertificate records with mode=’audit’ which are eligible.

classmethod is_masters_only(course_id)#

Check whether the course contains only a Master’s mode.

Parameters:

course_id (CourseKey) – course key of course to check

Returns: bool: whether the course contains only a Master’s mode

classmethod is_mode_upgradeable(mode_slug)#

Returns True if the given mode can be upgraded to another.

Note: Although, in practice, learners “upgrade” from verified to credit, that particular upgrade path is excluded by this method.

classmethod is_professional_mode(course_mode_tuple)#

checking that tuple is professional mode. :param course_mode_tuple: course mode tuple :type course_mode_tuple: tuple

Returns:

bool

classmethod is_professional_slug(slug)#

checking slug is professional :param slug: course mode string :type slug: str

Returns:

bool

classmethod is_verified_mode(course_mode_tuple)#

Check whether the given modes is_verified or not.

Parameters:

course_mode_tuple (Mode) – Mode tuple

Returns:

True iff the course modes is verified else False.

Return type:

bool

classmethod is_verified_slug(mode_slug)#

Check whether the given mode_slug is_verified or not.

Parameters:

mode_slug (str) – Mode Slug

Returns:

True iff the course mode slug is verified else False.

Return type:

bool

classmethod is_white_label(course_id, modes_dict=None)#

Check whether a course is a “white label” (paid) course.

By convention, white label courses have a course mode slug “honor” and a price.

Parameters:

course_id (CourseKey) – The course to check.

Keyword Arguments:

modes_dict (dict) – If provided, use these course modes. Useful for avoiding unnecessary database queries.

Returns:

bool

classmethod min_course_price_for_currency(course_id, currency)#

Returns the minimum price of the course in the appropriate currency over all the course’s non-expired modes. If there is no mode found, will return the price of DEFAULT_MODE, which is 0

classmethod min_course_price_for_verified_for_currency(course_id, currency)#

Returns the minimum price of the course in the appropriate currency over all the course’s verified, non-expired modes.

Assuming all verified courses have a minimum price of >0, this value should always be >0.

If no verified mode is found, 0 is returned.

min_price#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

mode_display_name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod mode_for_course(course_id, mode_slug, modes=None, include_expired=False)#

Returns the mode for the course corresponding to mode_slug.

Returns only non-expired modes.

If this particular mode is not set for the course, returns None

Parameters:
  • course_id (CourseKey) – Search for course modes for this course.

  • mode_slug (str) – Search for modes with this slug.

Keyword Arguments:
  • modes (list of Mode) – If provided, search through this list of course modes. This can be used to avoid an additional database query if you have already loaded the modes list.

  • include_expired (bool) – If True, expired course modes will be included in the returned values. If False, these modes will be omitted.

Returns:

Mode

mode_slug#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod modes_for_course(course_id=None, include_expired=False, only_selectable=True, course=None)#

Returns a list of the non-expired modes for a given course id

If no modes have been set in the table, returns the default mode

Keyword Arguments:
  • course_id (CourseKey) – Search for course modes for this course.

  • include_expired (bool) – If True, expired course modes will be included

  • omitted. (in the returned JSON data. If False, these modes will be)

  • only_selectable (bool) – If True, include only modes that are shown to users on the track selection page. (Currently, “credit” modes aren’t available to users until they complete the course, so they are hidden in track selection.)

  • course (CourseOverview) – The course to select course modes from.

Returns:

list of Mode tuples

classmethod modes_for_course_dict(course_id=None, modes=None, **kwargs)#

Returns the non-expired modes for a particular course.

Parameters:

course_id (CourseKey) – Search for course modes for this course.

Keyword Arguments:
  • modes (list of Mode) – If provided, search through this list of course modes. This can be used to avoid an additional database query if you have already loaded the modes list.

  • include_expired (bool) – If True, expired course modes will be included in the returned values. If False, these modes will be omitted.

  • only_selectable (bool) – If True, include only modes that are shown to users on the track selection page. (Currently, “credit” modes aren’t available to users until they complete the course, so they are hidden in track selection.)

Returns:

Keys are mode slugs, values are lists of Mode namedtuples.

Return type:

dict

objects = <django.db.models.manager.Manager object>#
classmethod paid_modes_for_course(course_id)#

Returns a list of non-expired modes for a course ID that have a set minimum price.

If no modes have been set, returns an empty list.

Parameters:

course_id (CourseKey) – The course to find paid modes for.

Returns:

A list of CourseModes with a minimum price.

save(force_insert=False, force_update=False, using=None)#

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

save_without_historical_record(*args, **kwargs)#

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

sku#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property slug#

Returns mode_slug

NOTE (CCB): This is a silly hack needed because all of the class methods use tuples with a property named slug instead of mode_slug.

suggested_prices#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

to_tuple()#

Takes a mode model and turns it into a model named tuple.

Returns:

A ‘Mode’ namedtuple with all the same attributes as the model.

classmethod verified_mode_for_course(course_id=None, modes=None, include_expired=False, course=None)#

Find a verified mode for a particular course.

Since we have multiple modes that can go through the verify flow, we want to be able to select the ‘correct’ verified mode for a given course.

Currently, we prefer to return the professional mode over the verified one if both exist for the given course.

Parameters:

course_id (CourseKey) – Search for course modes for this course.

Keyword Arguments:

modes (list of Mode) – If provided, search through this list of course modes. This can be used to avoid an additional database query if you have already loaded the modes list.

Returns:

Mode or None

exception DoesNotExist#

Bases: ObjectDoesNotExist

MODES = Choices(('verified', 'verified', 'verified'), ('honor', 'honor', 'honor'), ('audit', 'audit', 'audit'), ('professional', 'professional', 'professional'), ('no-id-professional', 'no-id-professional', 'no-id-professional'), ('masters', 'masters', 'masters'), ('executive-education', 'executive-education', 'executive-education'), ('paid-executive-education', 'paid-executive-education', 'paid-executive-education'), ('paid-bootcamp', 'paid-bootcamp', 'paid-bootcamp'))#
exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

VERIFIED_CERTS_MODES = ['verified', 'credit', 'masters', 'executive-education', 'paid-executive-education', 'paid-bootcamp']#
classmethod certificate_for_student(student, course_id)#

This returns the certificate for a student for a particular course or None if no such certificate exits.

certificateinvalidation_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

course_id#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

classmethod course_ids_with_certs_for_user(user)#

Return a set of CourseKeys for which the user has certificates.

Sometimes we just want to check if a user has already been issued a certificate for a given course (e.g. to test refund eligibility). Instead of checking if certificate_for_student returns None on each course_id individually, we instead just return a set of all CourseKeys for which this student has certificates all at once.

created_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date_override#

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

distinction#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

download_url#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

download_uuid#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

eligible_available_certificates = <lms.djangoapps.certificates.models.EligibleAvailableCertificateManager object>#
eligible_certificates = <lms.djangoapps.certificates.models.EligibleCertificateManager object>#
error_reason#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_mode_display(*, field=<django.db.models.fields.CharField: mode>)#
get_next_by_created_date(*, field=<django.db.models.fields.DateTimeField: created_date>, is_next=True, **kwargs)#
get_next_by_modified_date(*, field=<django.db.models.fields.DateTimeField: modified_date>, is_next=True, **kwargs)#
get_previous_by_created_date(*, field=<django.db.models.fields.DateTimeField: created_date>, is_next=False, **kwargs)#
get_previous_by_modified_date(*, field=<django.db.models.fields.DateTimeField: modified_date>, is_next=False, **kwargs)#
classmethod get_unique_statuses(course_key=None, flat=False)#
1 - Return unique statuses as a list of dictionaries containing the following key value pairs

[ {‘status’: ‘status value from db’, ‘count’: ‘occurrence count of the status’}, {…}, …, ]

2 - if flat is ‘True’ then return unique statuses as a list 3 - if course_key is given then return unique statuses associated with the given course

Parameters:
  • course_key – Course Key identifier

  • flat – boolean showing whether to return statuses as a list of values or a list of dictionaries.

grade#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

invalidate(mode=None, source=None)#

Invalidate Generated Certificate by marking it ‘unavailable’. For additional information see the _revoke_certificate() function.

Parameters:
  • mode (String) – evaluate the mode before deciding to invalidate the cert.

  • source (String)

is_valid()#

Return True if certificate is valid else return False.

key#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

mark_notpassing(mode, grade, source=None)#

Invalidates a Generated Certificate by marking it as ‘notpassing’. For additional information see the _revoke_certificate() function.

Parameters:
  • mode (String)

  • grade (float)

  • source (String)

mark_unverified(mode, source=None)#

Invalidates a Generated Certificate by marking it as ‘unverified’. For additional information see the _revoke_certificate() function.

Parameters:
  • mode (String)

  • source (String)

mode#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
save(*args, **kwargs)#

After the base save() method finishes, fire the COURSE_CERT_CHANGED signal. If the learner is currently passing the course we also fire the COURSE_CERT_AWARDED signal.

The COURSE_CERT_CHANGED signal helps determine if a Course Certificate can be awarded to a learner in the Credentials IDA.

The COURSE_CERT_AWARDED signal helps determine if a Program Certificate can be awarded to a learner in the Credentials IDA.

save_without_historical_record(*args, **kwargs)#

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

status#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id#
verify_uuid#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.certificates.models.ModifiedCertificateTemplateCommandConfiguration(*args, **kwargs)#

Bases: ConfigurationModel

Manages configuration for a run of the modify_cert_template management command.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

arguments#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

change_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

changed_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

changed_by_id#
enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.certificates.models.PurgeReferencestoPDFCertificatesCommandConfiguration(*args, **kwargs)#

Bases: ConfigurationModel

Manages configuration for a run of the purge_references_to_pdf_certificates management command.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

arguments#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

change_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

changed_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

changed_by_id#
enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lms.djangoapps.certificates.models.handle_certificate_date_override_delete(sender, instance, **kwargs)#

After a CertificateDateOverride is deleted, fire the COURSE_CERT_CHANGED signal.

We do this in a signal handler instead of overriding the CertificateDateOverride delete method so that this will be executed for both individual and bulk deletes from the Django admin. (The delete() method for an object is not necessarily called when deleting objects in bulk.)

lms.djangoapps.certificates.models.handle_course_cert_awarded(sender, user, course_key, **kwargs)#

Mark a milestone entry if user has passed the course.

lms.djangoapps.certificates.models.template_assets_path(instance, filename)#

Delete the file if it already exist and returns the certificate template asset file path.

Parameters:
  • instance – CertificateTemplateAsset object

  • filename – file to upload

Return path:

path of asset file e.g. certificate_template_assets/1/filename

lms.djangoapps.certificates.permissions module#

Permission definitions for the certificates djangoapp

lms.djangoapps.certificates.services module#

Certificate service

class lms.djangoapps.certificates.services.CertificateService#

Bases: object

User Certificate service

invalidate_certificate(user_id, course_key_or_id)#

lms.djangoapps.certificates.signals module#

Signal handler for enabling/disabling self-generated certificates based on the course-pacing.

lms.djangoapps.certificates.signals.handle_exam_attempt_rejected_event(sender, signal, **kwargs)#

Consume EXAM_ATTEMPT_REJECTED events from the event bus. Pass the received data to invalidate_certificate in the services.py file in this folder.

lms.djangoapps.certificates.signals.listen_for_passing_grade(sender, user, course_id, **kwargs)#

Listen for a signal indicating that the user has passed a course run.

If needed, generate a certificate task.

lms.djangoapps.certificates.tasks module#

Tasks that operate on course certificates for a user

lms.djangoapps.certificates.tasks.get_changed_cert_templates(options: Dict[str, Any]) List[CertificateTemplate]#

Loop through the templates and return instances with changed template text.

Parameters:
  • old_text (string) – Text in the template of which the first instance should be changed

  • new_text (string) – Replacement text for old_text

  • template_ids (list[string]) – List of template IDs for this run.

  • dry_run (boolean) – Don’t do the work, just report the changes that would happen

lms.djangoapps.certificates.urls module#

URLs for the certificates app.

lms.djangoapps.certificates.utils module#

Certificates utilities

lms.djangoapps.certificates.utils.certificate_status(generated_certificate)#

This returns a dictionary with a key for status, and other information.

If the status is “downloadable”, the dictionary also contains “download_url”.

If the student has been graded, the dictionary also contains their grade for the course with the key “grade”.

lms.djangoapps.certificates.utils.certificate_status_for_student(student, course_id)#

This returns a dictionary with a key for status, and other information. See certificate_status for more information.

lms.djangoapps.certificates.utils.emit_certificate_event(event_name, user, course_id, course_overview=None, event_data=None)#

Utility function responsible for emitting certificate events.

We currently track the following events: - edx.certificate.created - Emit when a course certificate with the downloadable status has been awarded to a

learner.

  • edx.certificate.revoked- Emit when a course certificate with the downloadable status has been taken away from

    a learner.

  • edx.certificate.shared - Emit when a learner shares their course certificate to social media (LinkedIn,

    Facebook, or Twitter).

  • edx.certificate.evidence_visited - Emit when a user (other than the learner who owns a certificate) views a

    course certificate (e.g., someone views a course certificate shared on a LinkedIn profile).

Parameters:
  • event_name (String) – created, etc.

  • user (User)

  • course_id (CourseLocator)

  • course_overview (CourseOverview)

  • event_data (dictionary) – event.

lms.djangoapps.certificates.utils.get_certificate_url(user_id=None, course_id=None, uuid=None, user_certificate=None)#

Returns the certificate URL

lms.djangoapps.certificates.utils.get_preferred_certificate_name(user)#

If the verified name feature is enabled and the user has their preference set to use their verified name for certificates, return their verified name. Else, return the user’s profile name, or an empty string if it doesn’t exist.

lms.djangoapps.certificates.utils.has_html_certificates_enabled(course_overview)#

Returns True if HTML certificates are enabled in a course run.

lms.djangoapps.certificates.utils.should_certificate_be_visible(certificates_display_behavior, certificates_show_before_end, has_ended, certificate_available_date, self_paced)#

Returns whether it is acceptable to show the student a certificate download link for a course, based on provided attributes of the course. :param certificates_display_behavior: string describing the course’s

certificate display behavior. See CourseFields.certificates_display_behavior.help for more detail.

Parameters:
  • certificates_show_before_end (bool) – whether user can download the course’s certificates before the course has ended.

  • has_ended (bool) – Whether the course has ended.

  • certificate_available_date (datetime) – the date the certificate is available on for the course.

  • self_paced (bool) – Whether the course is self-paced.

Module contents#