def tool_launch(): # Parse form and ensure necessary parameters are included for param in ['tool_name', 'launch_url', 'consumer_key', 'consumer_secret']: if request.form.get(param) == None: return redirect(url_for('tool_config?message=Please%20set%20all%values')) # Create a new tool configuration config = ToolConfig(title = request.form.get('tool_name'), launch_url = request.form.get('launch_url')) config.set_custom_param('message_from_flask', 'hey from the flask example consumer') # Create LTI tool consumer consumer = ToolConsumer(request.form.get('consumer_key'), request.form.get('consumer_secret')) consumer.set_config(config) # Set some launch data from: http://www.imsglobal.org/LTI/v1p1pd/ltiIMGv1p1pd.html#_Toc309649684 # Only this first one is required, but the rest are recommended consumer.resource_link_id = 'thisistotallyunique' consumer.launch_presentation_return_url = request.url + '/tool_return' consumer.lis_person_name_given = session['username'] hash = hashlib.md5() hash.update(session['username']) consumer.user_id = hash.hexdigest() consumer.roles = 'learner' consumer.context_id = 'bestcourseever' consumer.context_title = 'Example Flask Tool Consumer' consumer.tool_consumer_instance_name = 'Frankie' if request.form.get('assignment'): consumer.lis_outcome_service_url = request.scheme + '://' + request.host + '/grade_passback' consumer.lis_result_sourcedid = 'oi' autolaunch = True if request.form.get('autolaunch') else False return render_template('tool_launch.html', autolaunch=autolaunch, launch_data=consumer.generate_launch_data(), launch_url=consumer.launch_url)
def tool_config(): host = request.scheme + '://' + request.host secure_host = 'https://' + request.host url = host + '/lti_tool' secure_url = secure_host + '/lti_tool' lti_tool_config = ToolConfig(title='Example Flask Tool Provider', launch_url=url, secure_launch_url=secure_url) lti_tool_config.description = 'This example LTI Tool Provider supports LIS Outcome pass-back' resp = make_response(lti_tool_config.to_xml(), 200) resp.headers['Content-Type'] = 'text/xml' return resp
def piazza_test(request, course_id): # Create a new tool configuration config = ToolConfig(title='Piazza', launch_url=LTI_LAUNCH_URL) # Create tool consumer using LTI! consumer = ToolConsumer(LTI_CONSUMER_KEY, LTI_CONSUMER_SECRET) consumer.set_config(config) #retrieve user and course models user = User.objects.prefetch_related("groups").get(id=request.user.id) userProfile = UserProfile.objects.get(user_id=user.id) course = course_from_id(course_id) #check for permissions to determine what role to pass to Piazza.com through piazza_role = '' if user.groups.filter(name=( 'instructor_' + course_id)).count() != 0 or request.user.is_staff: piazza_role = 'Instructor' elif user.groups.filter(name=('staff_' + course_id)).count() != 0: piazza_role = 'Staff' else: piazza_role = 'Learner' # Set some launch data from: http://www.imsglobal.org/LTI/v1p1pd/ltiIMGv1p1pd.html#_Toc309649684 consumer.resource_link_id = course_id consumer.lis_person_contact_email_primary = user.email consumer.lis_person_name_full = str(userProfile.name) hash = hashlib.md5() hash.update(str(userProfile.user_id)) consumer.user_id = hash.hexdigest() #TODO: check if user is is_staff, student, professor, or staff and set the role appropriately #consumer.roles = 'Learner' consumer.roles = piazza_role consumer.context_id = course_id consumer.context_title = course.display_name_with_default consumer.context_label = course.number.replace('_', ' ') consumer.tool_consumer_instance_guid = 'lms.cvn.columbia.edu' consumer.tool_consumer_instance_description = 'Columbia University' launch_data = consumer.generate_launch_data() launch_url = consumer.launch_url #render a self-submitting form that sends all data to Piazza.com via the LTI standard returnable = '<form id="ltiLaunchFormSubmitArea" action="' + launch_url + '" name="ltiLaunchForm" id="ltiLaunchForm" method="post" encType="application/x-www-form-urlencoded">' for key in launch_data: returnable += '<input type="hidden" name="' + key + '" value="' + str( launch_data[key]) + '"/>' returnable += '<input type="submit" value="Go to Piazza"></input>' returnable += '</form>' returnable += '<script language="javascript">document.getElementById("ltiLaunchFormSubmitArea").style.display = "none";document.ltiLaunchForm.submit();</script>' return HttpResponse(returnable)
def tool_launch(): # Parse form and ensure necessary parameters are included for param in [ 'tool_name', 'launch_url', 'oauth_consumer_key', 'consumer_secret', 'roles' ]: if request.form.get(param) == None: return redirect( url_for('tool_config?message=Please%20set%20all%values')) params = {} custom_params = {} for k, v in request.form.items(): if v != "": if k[:4] == "ext_" or k[:7] == "custom_": custom_params[k] = v elif k != "consumer_secret": params[k] = v if (request.form.get("user_id") != None): hash = hashlib.md5() hash.update(request.form.get("user_id")) params["lis_result_sourcedid"] = hash.hexdigest() # Create a new tool configuration config = ToolConfig(title=request.form.get('tool_name'), launch_url=request.form.get('launch_url'), custom_params=custom_params) # Create tool consumer! Yay LTI! consumer = MyToolConsumer(request.form.get('oauth_consumer_key'), request.form.get('consumer_secret'), params=params) consumer.set_config(config) global consumer_key consumer_key = request.form.get('oauth_consumer_key') global consumer_secret consumer_secret = request.form.get('consumer_secret') global launch_url launch_url = request.form.get('launch_url') autolaunch = True if request.form.get('autolaunch') else False return render_template('tool_launch.html', autolaunch=autolaunch, launch_data=consumer.generate_launch_data(), launch_url=consumer.launch_url)
def test_generate_xml(self): ''' Should generate the expected config xml. ''' config = ToolConfig(title = "Test Config", secure_launch_url = "https://www.example.com/lti", custom_params = {"custom1": "customval1"}) config.description ='Description of boringness' config.launch_url = 'http://www.example.com/lti' config.icon = 'http://wil.to/_/beardslap.gif' config.vendor_code = 'test' config.vendor_name = 'test.tool' config.vendor_description = 'We test things' config.vendor_url = 'http://www.example.com/about' config.vendor_contact_email = '*****@*****.**' config.vendor_contact_name = 'Joe Support' config.set_custom_param('custom2', 'customval2') config.set_ext_params('example.com', { 'extkey1': 'extval1' }) config.set_ext_param('example.com', 'extkey2', 'extval2') config.set_ext_param('example.com', 'extopt1', { 'optkey1': 'optval1', 'optkey2': 'optval2' }) config.set_ext_param('two.example.com', 'ext1key', 'ext1val') config.cartridge_bundle = 'BLTI001_Bundle' xml = config.to_xml() self.assertEqual(xml, cc_lti_xml)
def test_read_xml_config(self): ''' Should read an XML config. ''' config = ToolConfig.create_from_xml(cc_lti_xml) self.assertEqual(config.to_xml(), cc_lti_xml)
def piazza_discussion(request, course_id): ''' Shows the page under the Discussion tab with an iframe containing Piazza ''' # Create a new tool configuration config = ToolConfig(title='Piazza', launch_url=LTI_LAUNCH_URL) # Create tool consumer using LTI! consumer = ToolConsumer(LTI_CONSUMER_KEY, LTI_CONSUMER_SECRET) consumer.set_config(config) #retrieve user and course models user = User.objects.prefetch_related("groups").get(id=request.user.id) userProfile = UserProfile.objects.get(user_id=user.id) course = course_from_id(course_id) #check for permissions to determine what role to pass to Piazza.com through piazza_role = '' if user.groups.filter(name=( 'instructor_' + course_id)).count() != 0 or request.user.is_staff: piazza_role = 'Instructor' elif user.groups.filter(name=('staff_' + course_id)).count() != 0: piazza_role = 'Staff' else: piazza_role = 'Learner' # Set some launch data from: http://www.imsglobal.org/LTI/v1p1pd/ltiIMGv1p1pd.html#_Toc309649684 consumer.resource_link_id = course_id consumer.lis_person_contact_email_primary = user.email consumer.lis_person_name_full = str(userProfile.name) hash = hashlib.md5() hash.update(str(userProfile.user_id)) consumer.user_id = hash.hexdigest() #TODO: check if user is is_staff, student, professor, or staff and set the role appropriately consumer.roles = piazza_role consumer.context_id = course_id consumer.context_title = course.display_name_with_default consumer.context_label = course.number.replace('_', ' ') consumer.tool_consumer_instance_guid = 'lms.cvn.columbia.edu' consumer.tool_consumer_instance_description = 'Columbia University' launch_data = consumer.generate_launch_data() launch_url = consumer.launch_url course = get_course_with_access(request.user, course_id, 'load') staff_access = has_access(request.user, course, 'staff') masq = setup_masquerade( request, staff_access) # allow staff to toggle masquerade on info page return render_to_response( 'courseware/piazza_discussion.html', { 'request': request, 'course_id': course_id, 'cache': None, 'course': course, 'staff_access': staff_access, 'masquerade': masq, 'launch_url': launch_url, 'launch_data': launch_data })
def test_generate_xml(self): ''' Should generate the expected config xml. ''' config = ToolConfig(title="Test Config", secure_launch_url="https://www.example.com/lti", custom_params={"custom1": "customval1"}) config.description = 'Description of boringness' config.launch_url = 'http://www.example.com/lti' config.icon = 'http://wil.to/_/beardslap.gif' config.vendor_code = 'test' config.vendor_name = 'test.tool' config.vendor_description = 'We test things' config.vendor_url = 'http://www.example.com/about' config.vendor_contact_email = '*****@*****.**' config.vendor_contact_name = 'Joe Support' config.set_custom_param('custom2', 'customval2') config.set_ext_params('example.com', {'extkey1': 'extval1'}) config.set_ext_param('example.com', 'extkey2', 'extval2') config.set_ext_param('example.com', 'extopt1', { 'optkey1': 'optval1', 'optkey2': 'optval2' }) config.set_ext_param('two.example.com', 'ext1key', 'ext1val') config.cartridge_bundle = 'BLTI001_Bundle' xml = config.to_xml() self.assertEqual(xml, cc_lti_xml)
def test_invalid_config_xml(self): ''' Should not allow creating invalid config xml. ''' config = ToolConfig(title='Test Config') self.assertRaises(InvalidLTIConfigError, config.to_xml)
def test_allow_suboptions(self): config = ToolConfig(title = "Test Config", secure_launch_url = "https://www.example.com/lti", custom_params = {"custom1": "customval1"}) config.description ='Description of boringness' config.launch_url = 'http://www.example.com/lti' config.icon = 'http://wil.to/_/beardslap.gif' config.vendor_code = 'test' config.vendor_name = 'test.tool' config.vendor_description = 'We test things' config.vendor_url = 'http://www.example.com/about' config.vendor_contact_email = '*****@*****.**' config.vendor_contact_name = 'Joe Support' config.set_custom_param('custom2', 'customval2') config.set_ext_params('example.com', { 'extkey1': 'extval1' }) config.set_ext_param('example.com', 'extkey2', 'extval2') config.set_ext_param('example.com', 'extopt1', { 'optkey1': 'optval1', 'optkey2': 'optval2' }) config.set_ext_param('example.com', 'extopt1', { 'labels':{ 'en':'Image Library', 'es':'Biblioteca de Imagenes' } }) config.set_ext_param('two.example.com', 'ext1key', 'ext1val') config.cartridge_bundle = 'BLTI001_Bundle' xml = config.to_xml() self.assertEqual(self.normalize(xml), self.normalize(cc_lti_with_sub_options))