openedx.core.lib.gating package#

Submodules#

openedx.core.lib.gating.api module#

API for the gating djangoapp

openedx.core.lib.gating.api.add_prerequisite(course_key, prereq_content_key)#

Creates a new Milestone and CourseContentMilestone indicating that the given course content fulfills a prerequisite for gating

Parameters:
  • course_key (str|CourseKey) – The course key

  • prereq_content_key (str|UsageKey) – The prerequisite content usage key

Returns:

None

openedx.core.lib.gating.api.compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False)#

Returns true if the prequiste has been met for a given milestone. Will recalculate the subsection grade if specified and prereq unmet

Parameters:
  • content_id (BlockUsageLocator) – BlockUsageLocator for the content

  • user_id – The id of the user

  • recalc_on_unmet – Recalculate the grade if prereq has not yet been met

Returns:

True|False, prereq_meta_info = { ‘url’: prereq_url|None, ‘display_name’: prereq_name|None}

Return type:

tuple

openedx.core.lib.gating.api.find_gating_milestones(course_key, content_key=None, relationship=None, user=None)#

Finds gating milestone dicts related to the given supplied parameters.

Parameters:
  • course_key (str|CourseKey) – The course key

  • content_key (str|UsageKey) – The content usage key

  • relationship (str) – The relationship type (e.g. ‘requires’)

  • user (dict) – The user dict (e.g. {‘id’: 4})

Returns:

A list of milestone dicts

Return type:

list

openedx.core.lib.gating.api.gating_enabled(default=None)#

Decorator that checks the enable_subsection_gating course flag to see if the subsection gating feature is active for a given course. If not, calls to the decorated function return the specified default value.

Parameters:

default (ANY) – The value to return if the enable_subsection_gating course flag is False

Returns:

The specified default value if the gating feature is off, otherwise the result of the decorated function

Return type:

ANY

openedx.core.lib.gating.api.get_gated_content(course, *args)#
openedx.core.lib.gating.api.get_gating_milestone(course_key, content_key, relationship)#

Gets a single gating milestone dict related to the given supplied parameters.

Parameters:
  • course_key (str|CourseKey) – The course key

  • content_key (str|UsageKey) – The content usage key

  • relationship (str) – The relationship type (e.g. ‘requires’)

Returns:

The gating milestone dict or None

Return type:

dict or None

openedx.core.lib.gating.api.get_prerequisites(course_key)#

Find all the gating milestones associated with a course and the XBlock info associated with those gating milestones.

Parameters:

course_key (str|CourseKey) – The course key

Returns:

A list of dicts containing the milestone and associated XBlock info

Return type:

list

openedx.core.lib.gating.api.get_required_content(course_key, gated_content_key)#

Returns the prerequisite content usage key, minimum score and minimum completion percentage needed for fulfillment of that prerequisite for the given gated_content_key.

Parameters:
  • course_key (str|CourseKey) – The course key

  • gated_content_key (str|UsageKey) – The gated content usage key

Returns:

The prerequisite content usage key, minimum score and minimum completion percentage, (None, None, None) if the content is not gated

Return type:

tuple

openedx.core.lib.gating.api.get_subsection_completion_percentage(subsection_usage_key, user)#

Computes completion percentage for a subsection in a given course for a user :param subsection_usage_key: key of subsection :param user: The user whose completion percentage needs to be computed

Returns:

User’s completion percentage for given subsection

openedx.core.lib.gating.api.get_subsection_grade_percentage(subsection_usage_key, user)#

Computes grade percentage for a subsection in a given course for a user

Parameters:
  • subsection_usage_key – key of subsection

  • user – The user whose grade needs to be computed

Returns:

User’s grade percentage for given subsection

openedx.core.lib.gating.api.is_gate_fulfilled(course_key, gating_content_key, user_id)#

Determines if a prerequisite section specified by gating_content_key has any unfulfilled milestones.

Parameters:
  • course_key (CourseUsageLocator) – Course locator

  • gating_content_key (BlockUsageLocator) – The locator for the section content

  • user_id – The id of the user

Returns:

Returns True if section has no unfufilled milestones or is not a prerequisite. Returns False otherwise

openedx.core.lib.gating.api.is_prerequisite(course_key, prereq_content_key)#

Returns True if there is at least one CourseContentMilestone which the given course content fulfills

Parameters:
  • course_key (str|CourseKey) – The course key

  • prereq_content_key (str|UsageKey) – The prerequisite content usage key

Returns:

True if the course content fulfills a CourseContentMilestone, otherwise False

Return type:

bool

openedx.core.lib.gating.api.remove_prerequisite(prereq_content_key)#

Removes the Milestone and CourseContentMilestones related to the gating prerequisite which the given course content fulfills

Parameters:

prereq_content_key (str|UsageKey) – The prerequisite content usage key

Returns:

None

openedx.core.lib.gating.api.set_required_content(course_key, gated_content_key, prereq_content_key, min_score='', min_completion='')#

Adds a requires milestone relationship for the given gated_content_key if a prerequisite prereq_content_key is provided. If prereq_content_key is None, removes the requires milestone relationship.

Parameters:
  • course_key (str|CourseKey) – The course key

  • gated_content_key (str|UsageKey) – The gated content usage key

  • prereq_content_key (str|UsageKey) – The prerequisite content usage key

  • min_score (str|int) – The minimum score

  • min_completion (str|int) – The minimum completion percentage

Returns:

None

openedx.core.lib.gating.api.update_milestone(milestone, usage_key, prereq_milestone, user, grade_percentage=None, completion_percentage=None)#

Updates the milestone record based on evaluation of prerequisite met.

Parameters:
  • milestone – The gated milestone being evaluated

  • usage_key – Usage key of the prerequisite subsection

  • prereq_milestone – The gating milestone

  • user – The user who has fulfilled milestone

  • grade_percentage – Grade percentage of prerequisite subsection

  • completion_percentage – Completion percentage of prerequisite subsection

Returns:

True if prerequisite has been met, False if not

openedx.core.lib.gating.exceptions module#

Exceptions for the course gating feature

exception openedx.core.lib.gating.exceptions.GatingValidationError#

Bases: Exception

Exception class for validation errors related to course gating information

openedx.core.lib.gating.services module#

A wrapper class to communicate with Gating api

class openedx.core.lib.gating.services.GatingService#

Bases: object

An XBlock service to talk to the Gating api.

compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False)#

Returns true if the prequiste has been met for a given milestone

Parameters:
  • content_id (BlockUsageLocator) – BlockUsageLocator for the content

  • user_id – The id of the user

  • recalc_on_unmet – Recalculate the grade if prereq has not yet been met

Returns:

True|False, prereq_meta_info = { ‘url’: prereq_url|None, ‘display_name’: prereq_name|None}

Return type:

tuple

is_gate_fulfilled(course_key, gating_content_key, user_id)#

Determines if a prerequisite section specified by gating_content_key has any unfulfilled milestones.

Parameters:
  • course_key (CourseUsageLocator) – Course locator

  • gating_content_key (BlockUsageLocator) – The locator for the section content

  • user_id – The id of the user

Returns:

Returns True if section has no unfufilled milestones or is not a prerequisite. Returns False otherwise

required_prereq(course_key, content_key, relationship)#

Returns the prerequisite if one is required

Parameters:
  • course_key (str|CourseKey) – The course key

  • content_key (str|UsageKey) – The content usage key

  • relationship (str) – The relationship type (e.g. ‘requires’)

Returns:

The gating milestone dict or None

Return type:

dict or None

Module contents#