Commit 943638d1d60862a81c1d59488f579a9e67568852

  • Tree SHA1: 607c196
  • Parent SHA1: 559927f (Refactor default parameters for LTI. Remove duplicates in parameter list and change a couple of defaults.)
  • raw diff | raw patch
Clean up CreateConsumer and comment out unused LTI params.
Comment out offending print line in http_params.py that causes an error.
timApp/modules/lti/lti.py
(10 / 34)
  
3232 'consumer_secret': '__lti_secret__',
3333 'consumer_key': '__consumer_key__',
3434 'resource_link_id': 'tim.jyu.fi',
35 'lis_outcome_service_url': "http://timstack.it.jyu.fi/grades/",
3635 'lis_person_sourcedid': 'sis:111',
3736 'lis_result_sourcedid': '__sourcedid__',
3837 'lis_course_offering_sourcedid': 'JYU-MATA123',
3938 'lis_course_section_sourcedid': 'JYU-MATA123-Kappale1-Teht15',
40 'roles': 'Learner',
41 'ext_ims_lis_basic_outcome_url': 'http://timstack.it.jyu.fi/lti/grades/',
42 'ext_ims_lis_resultvalue_sourcedids': 'decimal'
39 'roles': 'Learner'
40 # Outcomes params (commented out because they don't work)
41 #'lis_outcome_service_url': "http://timstack.it.jyu.fi/grades/",
42 #'ext_ims_lis_basic_outcome_url': 'http://timstack.it.jyu.fi/lti/grades/',
43 #'ext_ims_lis_resultvalue_sourcedids': 'decimal'
4344}
4445
4546
7575 'http://timstack.it.jyu.fi:8080/moodle/local/ltiprovider/tool.php?id=11' # Testaus 3
7676}
7777
78
79# Get question ID from URL
80def getQID(url):
81 for qid in qid_lookup:
82 if qid_lookup[qid] == url:
83 return qid
84 print("getQID returned None!")
85 return None
86
87
8878def CreateConsumer(query: QueryParams = None):
8979
90 if query:
91 # key = query.get_param('consumer_key', default='Query exists but no KEY')
92 # secret = query.get_param('consumer_secret', default='Query exists but no SECRET')
93 # TODO: placeholders
94 key = '__consumer_key__'
95 secret = '__lti_secret__'
96 tim_id = query.get_param('user_id', 'Query exists but no USER_ID')
97 tool_url = query.get_param('tool_url', 'DEFAULT_tool_url')
98 view_url = query.get_param('view_url', 'DEFAULT_view_url')
99 else:
100 key = '__consumer_key__'
101 secret = '__lti_secret__'
102 tim_id = 'Query does not exist: using default ID'
103 tool_url = 'http://timstack.it.jyu.fi' # Should actually be some 404 page...
104 view_url = 'http://timstack.it.jyu.fi' # Should actually be some 404 page...
105
106 # Get question ID that matches given Moodle question URL
107 # qid = getQID(question_url)
108 # qid = question_url
80 key = '__consumer_key' if query else 'DEFAULT_key'
81 secret = '__lti_secret__' if query else 'DEFAULT_secret'
82 tim_id = query.get_param('user_id', 'Query exists but no USER_ID')
83 tool_url = query.get_param('tool_url', 'DEFAULT_tool_url')
84 view_url = query.get_param('view_url', 'DEFAULT_view_url')
10985 qid = tool_url
11086
11187 LTI_params = fixed_lti_params
9494 LTI_params['lis_person_name_full'] = 'user_id: ' + tim_id
9595 LTI_params['lis_result_sourcedid'] = tim_id + '_' + qid
9696
97 tool_url = LTI_params['tool_url']
9897 LTI_credentials = {'consumer_key': key, 'consumer_secret': secret}
9998
10099 NewConsumer = Consumer(credentials=LTI_credentials, lti_params=LTI_params, tp_url=tool_url)
timApp/modules/py/http_params.py
(18 / 19)
  
291291 for jso in jsons:
292292 results.append(QueryParams(jso))
293293
294 print(str(results))
294 #print(str(results))
295295 return results
296296 # tai:
297297 # return {QueryParams(jso) for jso in jsons]
434434 result.update(b)
435435 return result
436436
437
437
438438LAZYSTART="<!--lazy "
439439LAZYEND =" lazy-->"
440440NOLAZY = "<!--nolazy-->"
441441NEVERLAZY = "NEVERLAZY"
442
443
442
443
444444def is_lazy(query: QueryParams) -> bool:
445445 """
446446 Tells if plugins need to be done in lazy-mode
447 :param query: query params where lazy options can be read
447 :param query: query params where lazy options can be read
448448 :return true if lazy plugin is needed
449449 """
450450 caller_lazy = query.get_param("doLazy", NEVERLAZY)
457457 if str(lazy).lower() == "true": do_lazy = True
458458 if str(lazy).lower() == "false": do_lazy = False
459459 # print("do_lazy=",do_lazy)
460 return do_lazy
461
462
460 return do_lazy
461
462
463463def make_lazy(plugin_html: str, query: QueryParams, htmlfunc) -> str:
464464 """
465465 Makes plugin string to lazy
466466 :param plugin_html: ready html for the plugin
467 :param query: query params where lazy options can be read
467 :param query: query params where lazy options can be read
468468 :param htmlfunc: function to generate the lazy version of plugin html
469469 :return true if lazy plugin is needed
470470 """
472472 lazy_html = htmlfunc(query)
473473 lazy_plugin_html = LAZYSTART + plugin_html + LAZYEND + lazy_html
474474 return lazy_plugin_html
475
476
475
476
477477def replace_template_params(query: QueryParams, template: str, cond_itemname: str, itemnames=None) -> str:
478478 """
479479 Replaces all occurances of itemnames and cond_item_name in template by their value in query
480 if cond_itemname exists in query.
481 :param query: query params where items can be read
480 if cond_itemname exists in query.
481 :param query: query params where items can be read
482482 :param template: string that may include items like {{userword}} that are replaced
483483 :param cond_itemname: name for the item that decides if the template is non empty. None means no condition
484484 :param itemnames: list of other item names that are replaced by their value in Query
485485 :return true if lazy plugin is needed
486486 """
487 items = []
487 items = []
488488 if cond_itemname:
489489 item = query.get_param(cond_itemname, "")
490490 if not item: return ""
491491 items = [cond_itemname]
492
492
493493 if itemnames: items += itemnames
494494 result = template
495
495
496496 for name in items:
497497 n,d,dummy = (name+"::").split(":",2)
498498 item = str(query.get_param(n, d))
499499 result = result.replace("{{"+n+"}}", item)
500
501 return result
502
500
501 return result