跳转到主要内容

一个用于构建和/或消费LTI应用的Python库

项目描述

https://travis-ci.org/pylti/lti.svg?branch=master https://codecov.io/gh/pylti/lti/branch/master/graph/badge.svg Join the chat at https://gitter.im/pylti/lti Requirements Status

lti是一个实现学习工具互操作性(LTI)标准的Python库。它基于dce_lti_py,而dce_lti_py又基于ims_lti_py

安装

pip install lti

依赖

用法

此库的主要目标是提供用于构建Python LTI工具提供者(LTI应用)的类。为此,您需要的功能可能位于ToolConfigToolProvider类中(如果您想消费LTI提供者,也提供了ToolConsumer)。

工具配置示例(Django)

以下是一个Django视图的示例,您可能将其用作注册应用时LTI消费者的配置URL。

from lti import ToolConfig
from django.http import HttpResponse


def tool_config(request):

    # basic stuff
    app_title = 'My App'
    app_description = 'An example LTI App'
    launch_view_name = 'lti_launch'
    launch_url = request.build_absolute_uri(reverse('lti_launch'))

    # maybe you've got some extensions
    extensions = {
        'my_extensions_provider': {
            # extension settings...
        }
    }

    lti_tool_config = ToolConfig(
        title=app_title,
        launch_url=launch_url,
        secure_launch_url=launch_url,
        extensions=extensions,
        description = app_description
    )

    # or you may need some additional LTI parameters
    lti_tool_config.cartridge_bundle = 'BLTI001_Bundle'
    lti_tool_config.cartridge_icon = 'BLTI001_Icon'
    lti_tool_config.icon = 'http://www.example.com/icon.png'

    return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')

工具提供者OAuth请求验证示例(Django)

from lti.contrib.django import DjangoToolProvider
from my_app import RequestValidator


# create the tool provider instance
tool_provider = DjangoToolProvider.from_django_request(request=request)

# the tool provider uses the 'oauthlib' library which requires an instance
# of a validator class when doing the oauth request signature checking.
# see https://oauthlib.readthedocs.org/en/latest/oauth1/validator.html for
# info on how to create one
validator = RequestValidator()

# validate the oauth request signature
ok = tool_provider.is_valid_request(validator)

# do stuff if ok / not ok

工具消费者示例(Django)

在您的视图中

def index(request):
    consumer = ToolConsumer(
        consumer_key='my_key_given_from_provider',
        consumer_secret='super_secret',
        launch_url='provider_url',
        params={
            'lti_message_type': 'basic-lti-launch-request'
        }
    )

    return render(
        request,
        'lti_consumer/index.html',
        {
            'launch_data': consumer.generate_launch_data(),
            'launch_url': consumer.launch_url
        }
    )

在模板中

<form action="{{ launch_url }}"
      name="ltiLaunchForm"
      id="ltiLaunchForm"
      method="POST"
      encType="application/x-www-form-urlencoded">
  {% for key, value in launch_data.items %}
    <input type="hidden" name="{{ key }}" value="{{ value }}"/>
  {% endfor %}
  <button type="submit">Launch the tool</button>
</form>

正在测试

可以通过执行来运行单元测试

tox

这使用 tox 来设置和运行测试环境。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

lti-0.9.5.tar.gz (16.5 kB 查看哈希值)

上传时间

构建分布

lti-0.9.5-py2.py3-none-any.whl (21.0 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下机构支持

AWSAWS 云计算和安全赞助商 DatadogDatadog 监控 FastlyFastly CDN GoogleGoogle 下载分析 MicrosoftMicrosoft PSF赞助商 PingdomPingdom 监控 SentrySentry 错误记录 StatusPageStatusPage 状态页面