ltiapi.utils#

Module Contents#

Classes#

Chain

A class for optional chaining in Python.

Functions#

chain

Optional Chain as a function. The most capable getter you have ever seen.

build_absolute_uri_without_request

Gives the absolute URI of a resource after reversing.

generate_key_pair

Generates an RSA key pair. Async because generating a key can be resource intensive.

keys_for_issuer

make_tool_config_from_openid_config_via_link

lti_registration_data

get_launch_url

Method code from https://github.com/dmitry-viskov/pylti1.3-django-example.git

get_roles

is_superior

get_message_data

get_lti_tool

get_lms

get_course_from_launch_data

get_user_from_launch_data

Data#

ChainedObj

user_transform

ROLE_START

CLAIM

API#

ltiapi.utils.ChainedObj#

None

class ltiapi.utils.Chain(obj: ltiapi.utils.ChainedObj)#

Bases: typing.Generic[ltiapi.utils.ChainedObj]

A class for optional chaining in Python.

Contains a tree of dict s, list s and object s, that can be queried via __getitem__ ([...]). The object contained in the class can be retrieved via calling the Chain instance. If any of the items or attributes in the getter chain contains None, the call return value will be None, too.

Initialization

get(key: Any, default=None)#
__getitem__#

None

__call__() ltiapi.utils.ChainedObj#
ltiapi.utils.chain(obj: Any, members: Sequence[Any], default=None)#

Optional Chain as a function. The most capable getter you have ever seen.

:param obj: the object to wrap.

:param args: Sequence of object members that will be used to get into the object’s members.

:returns: the sought member or the default value.

ltiapi.utils.build_absolute_uri_without_request(url: str, query: str = '', host: str = settings.LINK_BASE, protocol: Optional[str] = 'https')#

Gives the absolute URI of a resource after reversing.

request.build_absolute_uri() should be used for this usually, but sometimes the request is not available.

:param url: a site-relative url

:param query: the url query string. Defaults to an empty string.

:param host: the current host. defaults to settings.LINK_BASE.

:param protocol: you can specify a protocol (http(s)) here. Defaults to https.

async ltiapi.utils.generate_key_pair(key_size=4096)#

Generates an RSA key pair. Async because generating a key can be resource intensive.

:param key_size: key bits

:returns: a dict with the keys “public” and “private”, containing PEM-encoded RSA keys. This is not returned as a tuple so that the user of this function never confuses them.

async ltiapi.utils.keys_for_issuer(issuer_name: str) pylti1p3.contrib.django.lti1p3_tool_config.models.LtiToolKey#
ltiapi.utils.lti_registration_data(request: django.http.HttpRequest)#
ltiapi.utils.get_launch_url(request: django.http.HttpRequest)#

Method code from https://github.com/dmitry-viskov/pylti1.3-django-example.git

ltiapi.utils.user_transform#

None

ltiapi.utils.ROLE_START#

‘http://purl.imsglobal.org/vocab/lis/v2/’

ltiapi.utils.get_roles(message_launch_data: dict) List[django.contrib.auth.models.Group]#
ltiapi.utils.is_superior(user: ltiapi.models.LTIUser) bool#
ltiapi.utils.CLAIM#

‘https://purl.imsglobal.org/spec/lti/claim’

ltiapi.utils.get_message_data(message_launch_data: dict, data: str)#
ltiapi.utils.get_lti_tool(tool_conf: pylti1p3.contrib.django.lti1p3_tool_config.DjangoDbToolConf, message_launch_data: dict) dict#
ltiapi.utils.get_lms(message_launch_data: dict)#
ltiapi.utils.get_course_from_launch_data(message_launch_data: dict) ltiapi.models.Course#
ltiapi.utils.get_user_from_launch_data(message_launch_data: dict, lti_tool: pylti1p3.contrib.django.lti1p3_tool_config.models.LtiTool) ltiapi.models.LTIUser#