openedx.core.djangoapps.credit.api package#

Submodules#

openedx.core.djangoapps.credit.api.eligibility module#

APIs for configuring credit eligibility requirements and tracking whether a user has satisfied those requirements.

openedx.core.djangoapps.credit.api.eligibility.get_credit_requirement_status(course_key, username, namespace=None, name=None)#

Retrieve the user’s status for each credit requirement in the course.

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

  • username (str) – The identifier of the user

Example

>>> get_credit_requirement_status("course-v1-edX-DemoX-1T2015", "john")
[
{

“namespace”: “proctored_exam”, “name”: “i4x://edX/DemoX/proctoring-block/final_uuid”, “display_name”: “Proctored Mid Term Exam”, “criteria”: {}, “reason”: {}, “status”: “satisfied”, “status_date”: “2015-06-26 11:07:42”, “order”: 1,

}, {

“namespace”: “grade”, “name”: “i4x://edX/DemoX/proctoring-block/final_uuid”, “display_name”: “Minimum Passing Grade”, “criteria”: {“min_grade”: 0.8}, “reason”: {“final_grade”: 0.95}, “status”: “satisfied”, “status_date”: “2015-06-26 11:07:44”, “order”: 2,

},

]

Returns:

list of requirement statuses

openedx.core.djangoapps.credit.api.eligibility.get_credit_requirements(course_key, namespace=None)#

Get credit eligibility requirements of a given course and namespace.

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

  • namespace (str) – Namespace of requirements

Example

>>> get_credit_requirements("course-v1-edX-DemoX-1T2015")
    {
        requirements =
        [
            {
                "namespace": "proctored_exam",
                "name": "i4x://edX/DemoX/proctoring-block/final_uuid",
                "display_name": "Final Exam",
                "criteria": {},
            },
            {
                "namespace": "grade",
                "name": "grade",
                "display_name": "Grade",
                "criteria": {"min_grade": 0.8},
            },
        ]
    }
Returns:

Dict of requirements in the given namespace

openedx.core.djangoapps.credit.api.eligibility.get_eligibilities_for_user(username, course_key=None)#

Retrieve all courses or particular course for which the user is eligible for credit.

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

  • course_key (unicode) – Identifier of the course.

Example

>>> get_eligibilities_for_user("ron")
[
    {
        "course_key": "edX/Demo_101/Fall",
        "deadline": "2015-10-23"
    },
    {
        "course_key": "edX/Demo_201/Spring",
        "deadline": "2015-11-15"
    },
    ...
]

Returns: list

openedx.core.djangoapps.credit.api.eligibility.is_credit_course(course_key)#

Check whether the course has been configured for credit.

Parameters:

course_key (CourseKey) – Identifier of the course.

Returns:

True iff this is a credit course.

Return type:

bool

openedx.core.djangoapps.credit.api.eligibility.is_user_eligible_for_credit(username, course_key)#

Returns a boolean indicating if the user is eligible for credit for the given course

Parameters:
  • username (str) – The identifier for user

  • course_key (CourseKey) – The identifier for course

Returns:

True if user is eligible for the course else False

openedx.core.djangoapps.credit.api.eligibility.remove_credit_requirement_status(username, course_key, req_namespace, req_name)#

Remove the user’s requirement status.

This will remove the record from the credit requirement status table. The user will still be eligible for the credit in a course.

Parameters:
  • username (str) – Username of the user

  • course_key (CourseKey) – Identifier for the course associated with the requirement.

  • req_namespace (str) – Namespace of the requirement (e.g. “grade” or “reverification”)

  • req_name (str) – Name of the requirement (e.g. “grade” or the location of the ICRV XBlock)

openedx.core.djangoapps.credit.api.eligibility.set_credit_requirement_status(user, course_key, req_namespace, req_name, status='satisfied', reason=None)#

Update the user’s requirement status.

This will record whether the user satisfied or failed a particular requirement in a course. If the user has satisfied all requirements, the user will be marked as eligible for credit in the course.

Parameters:
  • user (User) – User object to set credit requirement for.

  • course_key (CourseKey) – Identifier for the course associated with the requirement.

  • req_namespace (str) – Namespace of the requirement (e.g. “grade” or “reverification”)

  • req_name (str) – Name of the requirement (e.g. “grade” or the location of the ICRV XBlock)

Keyword Arguments:
  • status (str) – Status of the requirement (either “satisfied” or “failed”)

  • reason (dict) – Reason of the status

openedx.core.djangoapps.credit.api.eligibility.set_credit_requirements(course_key, requirements)#

Add requirements to given course.

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

  • requirements (list) – List of requirements to be added

Example

>>> set_credit_requirements(
        "course-v1-edX-DemoX-1T2015",
        [
            {
                "namespace": "proctored_exam",
                "name": "i4x://edX/DemoX/proctoring-block/final_uuid",
                "display_name": "Final Exam",
                "criteria": {},
            },
            {
                "namespace": "grade",
                "name": "grade",
                "display_name": "Grade",
                "criteria": {"min_grade": 0.8},
            },
        ])
Raises:

InvalidCreditRequirements

Returns:

None

openedx.core.djangoapps.credit.api.provider module#

API for initiating and tracking requests for credit from a provider.

openedx.core.djangoapps.credit.api.provider.check_keys_exist(shared_secret_key, provider_id)#

Verify that a key is available for single or multiple key support scenarios.

Raise CreditProviderNotConfigured if no key available.

openedx.core.djangoapps.credit.api.provider.create_credit_request(course_key, provider_id, username)#

Initiate a request for credit from a credit provider.

This will return the parameters that the user’s browser will need to POST to the credit provider. It does NOT calculate the signature.

Only users who are eligible for credit (have satisfied all credit requirements) are allowed to make requests.

A provider can be configured either with integration enabled or not. If automatic integration is disabled, this method will simply return a URL to the credit provider and method set to “GET”, so the student can visit the URL and request credit directly. No database record will be created to track these requests.

If automatic integration is enabled, then this will also return the parameters that the user’s browser will need to POST to the credit provider. These parameters will be digitally signed using a secret key shared with the credit provider.

A database record will be created to track the request with a 32-character UUID. The returned dictionary can be used by the user’s browser to send a POST request to the credit provider.

If a pending request already exists, this function should return a request description with the same UUID. (Other parameters, such as the user’s full name may be different than the original request).

If a completed request (either accepted or rejected) already exists, this function will raise an exception. Users are not allowed to make additional requests once a request has been completed.

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

  • provider_id (str) – The identifier of the credit provider.

  • username (str) – The user initiating the request.

Returns: dict

Raises:
Example Usage:
>>> create_credit_request(course.id, "hogwarts", "ron")
{
    "url": "https://credit.example.com/request",
    "method": "POST",
    "parameters": {
        "request_uuid": "557168d0f7664fe59097106c67c3f847",
        "timestamp": 1434631630,
        "course_org": "HogwartsX",
        "course_num": "Potions101",
        "course_run": "1T2015",
        "final_grade": "0.95",
        "user_username": "ron",
        "user_email": "ron@example.com",
        "user_full_name": "Ron Weasley",
        "user_mailing_address": "",
        "user_country": "US",
        "signature": "cRCNjkE4IzY+erIjRwOQCpRILgOvXx4q2qvx141BCqI="
    }
}
openedx.core.djangoapps.credit.api.provider.get_credit_provider_info(request, provider_id)#
Retrieve the ‘CreditProvider’ model data against provided

credit provider.

Parameters:

provider_id (str) – The identifier for the credit provider

Returns: ‘CreditProvider’ data dictionary

Example Usage:
>>> get_credit_provider_info("hogwarts")
{
    "provider_id": "hogwarts",
    "display_name": "Hogwarts School of Witchcraft and Wizardry",
    "provider_url": "https://credit.example.com/",
    "provider_status_url": "https://credit.example.com/status/",
    "provider_description: "A new model for the Witchcraft and Wizardry School System.",
    "enable_integration": False,
    "fulfillment_instructions": "
        <p>In order to fulfill credit, Hogwarts School of Witchcraft and Wizardry requires learners to:</p>
        <ul>
        <li>Sample instruction abc</li>
        <li>Sample instruction xyz</li>
        </ul>",
    "thumbnail_url": "https://credit.example.com/logo.png"
}
openedx.core.djangoapps.credit.api.provider.get_credit_providers(providers_list=None)#

Retrieve all available credit providers or filter on given providers_list.

Parameters:
  • providers_list (list of strings or None) – contains list of ids of credit providers

  • None. (or)

Returns:

list of credit providers represented as dictionaries

Response Values:
>>> get_credit_providers(['hogwarts'])
[
    {
        "id": "hogwarts",
        "name": "Hogwarts School of Witchcraft and Wizardry",
        "url": "https://credit.example.com/",
        "status_url": "https://credit.example.com/status/",
        "description: "A new model for the Witchcraft and Wizardry School System.",
        "enable_integration": false,
        "fulfillment_instructions": "
        <p>In order to fulfill credit, Hogwarts School of Witchcraft and Wizardry requires learners to:</p>
        <ul>
        <li>Sample instruction abc</li>
        <li>Sample instruction xyz</li>
        </ul>",
    },
    ...
]
openedx.core.djangoapps.credit.api.provider.get_credit_request_status(username, course_key)#

Get the credit request status.

This function returns the status of credit request of user for given course. It returns the latest request status for the any credit provider. The valid status are ‘pending’, ‘approved’ or ‘rejected’.

Parameters:
  • username (str) – The username of user

  • course_key (CourseKey) – The course locator key

Returns:

A dictionary of credit request user has made if any

openedx.core.djangoapps.credit.api.provider.get_credit_requests_for_user(username)#

Retrieve the status of a credit request.

Returns either “pending”, “approved”, or “rejected”

Parameters:

username (unicode) – The username of the user who initiated the requests.

Returns: list

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

{

“uuid”: “557168d0f7664fe59097106c67c3f847”, “timestamp”: 1434631630, “course_key”: “course-v1:HogwartsX+Potions101+1T2015”, “provider”: {

“id”: “HogwartsX”, “display_name”: “Hogwarts School of Witchcraft and Wizardry”,

}, “status”: “pending” # or “approved” or “rejected”

}

]

openedx.core.djangoapps.credit.api.provider.update_credit_request_status(request_uuid, provider_id, status)#

Update the status of a credit request.

Approve or reject a request for a student to receive credit in a course from a particular credit provider.

This function does NOT check that the status update is authorized. The caller needs to handle authentication and authorization (checking the signature of the message received from the credit provider)

The function is idempotent; if the request has already been updated to the status, the function does nothing.

Parameters:
  • request_uuid (str) – The unique identifier for the credit request.

  • provider_id (str) – Identifier for the credit provider.

  • status (str) – Either “approved” or “rejected”

Returns: None

Raises:

Module contents#

Credit Python API.

This module aggregates the API functions from the eligibility and provider APIs.