Handling a Launch#
The django-lti
library aims to make the handling of LTI launch messages as
straightforward as possible, while still allowing the flexibility to implement required
application-specific functionality.
Implementing a Launch view#
To aid tool development django-lti
provides
LtiLaunchBaseView
, a base view which handles many of the tasks
that a typical Django-based LTI tool will need to address on every launch.
Clearing any preexisting session data
Validating the launch data
Synchronizing any launch data from the platform with the tools internal data model
Adding a launch ID to the session so that launch data can be retrieved during future requests
This still leaves any application-specific details, which can be implemented by
overriding the handle_resource_launch()
method.
class ApplicationLaunchView(LtiLaunchBaseView):
def handle_resource_launch(self, request, lti_launch):
... # Application-specific launch handling can happen here.
Each application will handle a launch differently, but common tasks include:
Associating the launch user with an application user account
Starting an asynchronous task to fetch course members from the platform
Redirecting to an appropriate page based on launch data
Handling Deployments#
By default, LtiLaunchBaseView
will return an error if the
LtiDeployment
associated with the launch is inactive. In this
case, a tool administrator will need to manually activate each new deployment using the
Django admin or a custom built interface.
To implement custom behavior for handling inactive deployments, tools may
override the handle_inactive_deployment()
method and return a custom response.
class ApplicationLaunchView(LtiLaunchBaseView):
def handle_inactive_deployment(self, request, lti_launch):
return HttpResponseRedirect(custom_deployment_activation_url)
Tools wishing to automatically activate new deployments (either universally, or based
on specific criteria) may do so by implementing the
launch_setup()
method.
class ApplicationLaunchView(LtiLaunchBaseView):
def launch_setup(self, request, lti_launch):
if not lti_launch.deployment.is_active:
lti_launch.deployment.is_active = True
lti_launch.deployment.save()
Other Launch Messages#
While the majority of LTI launches will be LtiResourceLinkRequest
messages handled
through handle_resource_launch
, LtiLaunchBaseView
provides other methods for
handling launches with different messages.
LTI message type |
|
---|---|
|
|
|
|
|
|
|
By default, all messages other than LtiResourceLinkRequest
return a message
indicating that the message type is not supported.
Resources#
LTI launch definition from the LTI 1.3 Core Specification.
Resource link launch request message description from the LTI 1.3 Core Specification.