From 5cc7eff94f4e878f74e9a8824e518349a999a228 Mon Sep 17 00:00:00 2001 From: tleb Date: Thu, 24 Oct 2019 14:18:29 +0200 Subject: [PATCH] pedagogy: uv autofill finishing touches --- api/views/uv.py | 27 ++++++++++++++--------- core/static/core/js/script.js | 7 ++++++ pedagogy/templates/pedagogy/uv_edit.jinja | 1 + sith/settings.py | 5 +---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/api/views/uv.py b/api/views/uv.py index 9cf46a2b..d1099475 100644 --- a/api/views/uv.py +++ b/api/views/uv.py @@ -35,8 +35,8 @@ def find_uv(lang, year, code): full_uv is the detailed representation of an UV. """ # query the UV list - uvs_url = settings.SITH_PEDAGOGY_UTBM_API_UVS_URL - response = urllib.request.urlopen(uvs_url.format(lang=lang, year=year)) + uvs_url = settings.SITH_PEDAGOGY_UTBM_API + "/uvs/{}/{}".format(lang, year) + response = urllib.request.urlopen(uvs_url) uvs = json.loads(response.read().decode("utf-8")) try: @@ -46,11 +46,10 @@ def find_uv(lang, year, code): return (None, None) # get detailed information about the UV - response = urllib.request.urlopen( - settings.SITH_PEDAGOGY_UTBM_API_UV_URL.format( - lang=lang, year=year, code=code, formation=short_uv["codeFormation"] - ) + uv_url = settings.SITH_PEDAGOGY_UTBM_API + "/uv/{}/{}/{}/{}".format( + lang, year, code, short_uv["codeFormation"] ) + response = urllib.request.urlopen(uv_url) full_uv = json.loads(response.read().decode("utf-8")) return (short_uv, full_uv) @@ -112,9 +111,17 @@ def make_clean_uv(short_uv, full_uv): res["title"] = full_uv["libelle"] - res["objectives"] = full_uv["objectifs"] - res["program"] = full_uv["programme"] - res["skills"] = full_uv["acquisitionCompetences"] - res["key_concepts"] = full_uv["acquisitionNotions"] + descriptions = { + "objectives": "objectifs", + "program": "programme", + "skills": "acquisitionCompetences", + "key_concepts": "acquisitionNotions", + } + + for res_key, full_uv_key in descriptions.items(): + res[res_key] = full_uv[full_uv_key] + # if not found or the API did not return a string + if type(res[res_key]) != str: + res[res_key] = "" return res diff --git a/core/static/core/js/script.js b/core/static/core/js/script.js index a8f41b31..671785fe 100644 --- a/core/static/core/js/script.js +++ b/core/static/core/js/script.js @@ -47,6 +47,13 @@ function createQuickNotif(msg) { document.getElementById('quick_notif').appendChild(el) } +function deleteQuickNotifs() { + const el = document.getElementById('quick_notif') + while (el.firstChild) { + el.removeChild(el.firstChild) + } +} + function display_notif() { $('#header_notif').toggle().parent().toggleClass("white"); } diff --git a/pedagogy/templates/pedagogy/uv_edit.jinja b/pedagogy/templates/pedagogy/uv_edit.jinja index 533f6454..a47e10e6 100644 --- a/pedagogy/templates/pedagogy/uv_edit.jinja +++ b/pedagogy/templates/pedagogy/uv_edit.jinja @@ -52,6 +52,7 @@ year-- } const url = "{{ url('api:uv_endpoint') }}?year=" + year + "&code=" + codeInput.value + deleteQuickNotifs() $.ajax({ dataType: "json", diff --git a/sith/settings.py b/sith/settings.py index 6bc270c8..75fd63e8 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -445,10 +445,7 @@ SITH_PEDAGOGY_UV_RESULT_GRADE = [ ("ABS", _("Abs")), ] -base_url = "https://extranet1.utbm.fr/gpedago/api/guide" -SITH_PEDAGOGY_UTBM_API_UVS_URL = base_url + "/uvs/{lang}/{year}" -SITH_PEDAGOGY_UTBM_API_UV_URL = base_url + "/uv/{lang}/{year}/{code}/{formation}" -del base_url +SITH_PEDAGOGY_UTBM_API = "https://extranet1.utbm.fr/gpedago/api/guide" SITH_ECOCUP_CONS = 1152