lms.djangoapps.badges package#

Subpackages#

Submodules#

lms.djangoapps.badges.apps module#

Badges Application Configuration

Signal handlers are connected here.

class lms.djangoapps.badges.apps.BadgesConfig(app_name, app_module)#

Bases: AppConfig

Application Configuration for Badges.

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

Connect signal handlers.

lms.djangoapps.badges.handlers module#

Badges related signal handlers.

lms.djangoapps.badges.handlers.award_badge_on_enrollment(sender, event=None, user=None, **kwargs)#

Awards enrollment badge to the given user on new enrollments.

lms.djangoapps.badges.models module#

Database models for the badges app

class lms.djangoapps.badges.models.BadgeAssertion(*args, **kwargs)#

Bases: TimeStampedModel

Tracks badges on our side of the badge baking transaction

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

assertion_url#

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

classmethod assertions_for_user(user, course_id=None)#

Get all assertions for a user, optionally constrained to a course.

backend#

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

badge_class#

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.

badge_class_id#
created#

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

data#

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.

image_url#

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>#
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.badges.models.BadgeClass(*args, **kwargs)#

Bases: Model

Specifies a badge class to be registered with a backend.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

award(user, evidence_url=None)#

Contacts the backend to have a badge assertion created for this badge class for this user.

backend()#

Loads the badging backend.

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

badgr_server_slug#

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.

criteria#

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.

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 get_badge_class(slug, issuing_component, display_name=None, description=None, criteria=None, image_file_handle=None, mode='', course_id=None, create=True)#

Looks up a badge class by its slug, issuing component, and course_id and returns it should it exist. If it does not exist, and create is True, creates it according to the arguments. Otherwise, returns None.

The expectation is that an XBlock or platform developer should not need to concern themselves with whether or not a badge class has already been created, but should just feed all requirements to this function and it will ‘do the right thing’. It should be the exception, rather than the common case, that a badge class would need to be looked up without also being created were it missing.

get_for_user(user)#

Get the assertion for this badge class for this user, if it has been awarded.

id#

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

image#

Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.

issuing_component#

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.

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

Slugs must always be lowercase.

slug#

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

exception lms.djangoapps.badges.models.CourseBadgesDisabledError#

Bases: Exception

Exception raised when Course Badges aren’t enabled, but an attempt to fetch one is made anyway.

class lms.djangoapps.badges.models.CourseCompleteImageConfiguration(*args, **kwargs)#

Bases: Model

Contains the icon configuration for badges for a specific course mode.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

clean()#

Make sure there’s not more than one default.

default#

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

icon#

Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.

id#

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

classmethod image_for_mode(mode)#

Get the image for a particular mode.

mode#

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.badges.models.CourseEventBadgesConfiguration(*args, **kwargs)#

Bases: ConfigurationModel

Determines the settings for meta course awards– such as completing a certain number of courses or enrolling in a certain number of them.

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_fields(exclude=())#

Verify the settings are parseable.

property completed_settings#

Parses the settings from the courses_completed field.

property course_group_settings#

Parses the course group settings. In example, the format is:

slug_for_compsci_courses_group_badge,course-v1:CompSci+Course+First,course-v1:CompsSci+Course+Second

course_groups#

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

courses_completed#

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

courses_enrolled#

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.

property enrolled_settings#

Parses the settings from the courses_completed field.

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.badges.models.validate_badge_image(image)#

Validates that a particular image is small enough to be a badge and square.

lms.djangoapps.badges.models.validate_lowercase(string)#

Validates that a string is lowercase.

lms.djangoapps.badges.service module#

Badging service for XBlocks

class lms.djangoapps.badges.service.BadgingService(course_id=None, modulestore=None)#

Bases: object

A class that provides functions for managing badges which XBlocks can use.

If course_enabled is True, course-level badges are permitted for this course.

If it is False, any badges that are awarded should be non-course specific.

course_badges_enabled = False#
classmethod get_badge_class(slug, issuing_component, display_name=None, description=None, criteria=None, image_file_handle=None, mode='', course_id=None, create=True)#

Looks up a badge class by its slug, issuing component, and course_id and returns it should it exist. If it does not exist, and create is True, creates it according to the arguments. Otherwise, returns None.

The expectation is that an XBlock or platform developer should not need to concern themselves with whether or not a badge class has already been created, but should just feed all requirements to this function and it will ‘do the right thing’. It should be the exception, rather than the common case, that a badge class would need to be looked up without also being created were it missing.

lms.djangoapps.badges.utils module#

Utility functions used by the badging app.

lms.djangoapps.badges.utils.badges_enabled()#

returns a boolean indicating whether or not openbadges are enabled.

lms.djangoapps.badges.utils.deserialize_count_specs(text)#
Takes a string in the format of:

int,course_key int,course_key

And returns a dictionary with the keys as the numbers and the values as the course keys.

lms.djangoapps.badges.utils.requires_badges_enabled(function)#

Decorator that bails a function out early if badges aren’t enabled.

lms.djangoapps.badges.utils.site_prefix()#

Get the prefix for the site URL– protocol and server name.

Module contents#