From f516ccdfe7daa8915f028c4b628a450d7a72c72d Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 21 Sep 2021 15:53:33 +0200 Subject: [PATCH] retire arguments REQUEST de sendResult et sendPDFFile --- app/scodoc/sco_bulletins.py | 2 +- app/scodoc/sco_formations.py | 4 +--- app/scodoc/sco_groups.py | 2 +- app/scodoc/sco_pvjury.py | 4 ++-- app/scodoc/sco_report.py | 2 +- app/scodoc/sco_trombino.py | 2 +- app/scodoc/sco_trombino_tours.py | 4 ++-- app/scodoc/sco_utils.py | 26 +++++++------------------- app/views/absences.py | 6 +++--- app/views/notes.py | 15 +++++++-------- app/views/scolar.py | 8 +++----- app/views/users.py | 2 +- 12 files changed, 30 insertions(+), 47 deletions(-) diff --git a/app/scodoc/sco_bulletins.py b/app/scodoc/sco_bulletins.py index ec691a07f1..27fe7c05fb 100644 --- a/app/scodoc/sco_bulletins.py +++ b/app/scodoc/sco_bulletins.py @@ -903,7 +903,7 @@ def do_formsemestre_bulletinetud( ) if format == "pdf": return ( - scu.sendPDFFile(REQUEST, bul, filename), + scu.sendPDFFile(bul, filename), I["filigranne"], ) # unused ret. value else: diff --git a/app/scodoc/sco_formations.py b/app/scodoc/sco_formations.py index 1a04fe23da..cb4754fe9c 100644 --- a/app/scodoc/sco_formations.py +++ b/app/scodoc/sco_formations.py @@ -132,9 +132,7 @@ def formation_export( if mod["ects"] is None: del mod["ects"] - return scu.sendResult( - REQUEST, F, name="formation", format=format, force_outer_xml_tag=False - ) + return scu.sendResult(F, name="formation", format=format, force_outer_xml_tag=False) def formation_import_xml(doc: str, import_tags=True): diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index df1625ee7f..7d898acc87 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -476,7 +476,7 @@ def formsemestre_partition_list(formsemestre_id, format="xml", REQUEST=None): # Ajoute les groupes for p in partitions: p["group"] = get_partition_groups(p) - return scu.sendResult(REQUEST, partitions, name="partition", format=format) + return scu.sendResult(partitions, name="partition", format=format) # Encore utilisé par groupmgr.js diff --git a/app/scodoc/sco_pvjury.py b/app/scodoc/sco_pvjury.py index 84e9a2db14..b9a6a3bdf6 100644 --- a/app/scodoc/sco_pvjury.py +++ b/app/scodoc/sco_pvjury.py @@ -706,7 +706,7 @@ def formsemestre_pvjury_pdf(formsemestre_id, group_ids=[], etudid=None, REQUEST= else: groups_filename = "" filename = "PV-%s%s-%s.pdf" % (sem["titre_num"], groups_filename, dt) - return scu.sendPDFFile(REQUEST, pdfdoc, filename) + return scu.sendPDFFile(pdfdoc, filename) def descrform_pvjury(sem): @@ -867,7 +867,7 @@ def formsemestre_lettres_individuelles(formsemestre_id, group_ids=[], REQUEST=No dt = time.strftime("%Y-%m-%d") groups_filename = "-" + groups_infos.groups_filename filename = "lettres-%s%s-%s.pdf" % (sem["titre_num"], groups_filename, dt) - return scu.sendPDFFile(REQUEST, pdfdoc, filename) + return scu.sendPDFFile(pdfdoc, filename) def descrform_lettres_individuelles(): diff --git a/app/scodoc/sco_report.py b/app/scodoc/sco_report.py index 29f166b584..47963cda23 100644 --- a/app/scodoc/sco_report.py +++ b/app/scodoc/sco_report.py @@ -1491,7 +1491,7 @@ def formsemestre_graph_parcours( statut=statut, ) filename = scu.make_filename("flux " + sem["titreannee"]) - return scu.sendPDFFile(REQUEST, doc, filename + ".pdf") + return scu.sendPDFFile(doc, filename + ".pdf") elif format == "png": # ( diff --git a/app/scodoc/sco_trombino.py b/app/scodoc/sco_trombino.py index bd3f19aadb..b8a8a63c80 100644 --- a/app/scodoc/sco_trombino.py +++ b/app/scodoc/sco_trombino.py @@ -466,7 +466,7 @@ def _listeappel_photos_pdf(groups_infos, REQUEST): document.build(objects) data = report.getvalue() - return scu.sendPDFFile(REQUEST, data, filename) + return scu.sendPDFFile(data, filename) # --------------------- Upload des photos de tout un groupe diff --git a/app/scodoc/sco_trombino_tours.py b/app/scodoc/sco_trombino_tours.py index 7a2ec1f03e..7a0fb688ff 100644 --- a/app/scodoc/sco_trombino_tours.py +++ b/app/scodoc/sco_trombino_tours.py @@ -272,7 +272,7 @@ def pdf_trombino_tours( document.build(objects) data = report.getvalue() - return scu.sendPDFFile(REQUEST, data, filename) + return scu.sendPDFFile(data, filename) # Feuille d'absences en pdf avec photos: @@ -466,4 +466,4 @@ def pdf_feuille_releve_absences( document.build(objects) data = report.getvalue() - return scu.sendPDFFile(REQUEST, data, filename) + return scu.sendPDFFile(data, filename) diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index b97435ac84..3d19ba92e0 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -538,17 +538,9 @@ def sendCSVFile(REQUEST, data, filename): # DEPRECATED ne plus utiliser return data -def sendPDFFile(REQUEST, data, filename): - filename = ( - unescape_html(suppress_accents(filename)).replace("&", "").replace(" ", "_") - ) - if REQUEST: - REQUEST.RESPONSE.setHeader("content-type", PDF_MIMETYPE) - REQUEST.RESPONSE.setHeader( - "content-disposition", 'attachment; filename="%s"' % filename - ) - return data - +def sendPDFFile(data, filename): + filename = make_filename(filename) + return send_file(data, filename=filename, mime=JSON_MIMETYPE, attached=True) class ScoDocJSONEncoder(json.JSONEncoder): def default(self, o): # pylint: disable=E0202 @@ -565,25 +557,21 @@ def sendJSON(data): return send_file(js, filename="sco_data.json", mime=JSON_MIMETYPE, attached=False) -def sendXML(REQUEST, data, tagname=None, force_outer_xml_tag=True): +def sendXML(data, tagname=None, force_outer_xml_tag=True): if type(data) != list: data = [data] # always list-of-dicts if force_outer_xml_tag: data = [{tagname: data}] tagname += "_list" doc = sco_xml.simple_dictlist2xml(data, tagname=tagname) - if REQUEST: - REQUEST.RESPONSE.setHeader("content-type", XML_MIMETYPE) - return doc + return send_file(doc, filename="sco_data.xml", mime=XML_MIMETYPE, attached=False) -def sendResult(REQUEST, data, name=None, format=None, force_outer_xml_tag=True): +def sendResult(data, name=None, format=None, force_outer_xml_tag=True): if (format is None) or (format == "html"): return data elif format == "xml": # name is outer tagname - return sendXML( - REQUEST, data, tagname=name, force_outer_xml_tag=force_outer_xml_tag - ) + return sendXML(data, tagname=name, force_outer_xml_tag=force_outer_xml_tag) elif format == "json": return sendJSON(data) else: diff --git a/app/views/absences.py b/app/views/absences.py index c723e0b295..1a1134440e 100644 --- a/app/views/absences.py +++ b/app/views/absences.py @@ -1223,7 +1223,7 @@ def _tableBillets(billets, etud=None, title=""): @scodoc @permission_required(Permission.ScoView) @scodoc7func -def listeBilletsEtud(etudid=False, REQUEST=None, format="html"): +def listeBilletsEtud(etudid=False, format="html"): """Liste billets pour un etudiant""" etuds = sco_etud.get_etud_info(filled=True, etudid=etudid) if not etuds: @@ -1243,12 +1243,12 @@ def listeBilletsEtud(etudid=False, REQUEST=None, format="html"): @scodoc @permission_required_compat_scodoc7(Permission.ScoView) @scodoc7func -def XMLgetBilletsEtud(etudid=False, REQUEST=None): +def XMLgetBilletsEtud(etudid=False): """Liste billets pour un etudiant""" if not sco_preferences.get_preference("handle_billets_abs"): return "" t0 = time.time() - r = listeBilletsEtud(etudid, REQUEST=REQUEST, format="xml") + r = listeBilletsEtud(etudid, format="xml") log("XMLgetBilletsEtud (%gs)" % (time.time() - t0)) return r diff --git a/app/views/notes.py b/app/views/notes.py index 5f05f249d7..8375d6627a 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -469,7 +469,7 @@ def formation_list(format=None, REQUEST=None, formation_id=None, args={}): (when args is given, formation_id is ignored). """ r = sco_formations.formation_list(formation_id=formation_id, args=args) - return scu.sendResult(REQUEST, r, name="formation", format=format) + return scu.sendResult(r, name="formation", format=format) @bp.route("/formation_export") @@ -614,8 +614,7 @@ sco_publish("/ue_move", sco_edit_formation.ue_move, Permission.ScoChangeFormatio @permission_required_compat_scodoc7(Permission.ScoView) @scodoc7func def formsemestre_list( - format=None, - REQUEST=None, + format="json", formsemestre_id=None, formation_id=None, etape_apo=None, @@ -632,7 +631,7 @@ def formsemestre_list( args[argname] = L[argname] sems = sco_formsemestre.do_formsemestre_list(args=args) # log('formsemestre_list: format="%s", %s semestres found' % (format,len(sems))) - return scu.sendResult(REQUEST, sems, name="formsemestre", format=format) + return scu.sendResult(sems, name="formsemestre", format=format) @bp.route( @@ -1328,7 +1327,7 @@ def do_formsemestre_inscription_listinscrits( r = sco_formsemestre_inscriptions.do_formsemestre_inscription_listinscrits( formsemestre_id ) - return scu.sendResult(REQUEST, r, format=format, name="inscrits") + return scu.sendResult(r, format=format, name="inscrits") @bp.route("/formsemestre_desinscription", methods=["GET", "POST"]) @@ -1699,7 +1698,7 @@ def formsemestre_bulletins_pdf(formsemestre_id, REQUEST, version="selectedevals" pdfdoc, filename = sco_bulletins_pdf.get_formsemestre_bulletins_pdf( formsemestre_id, REQUEST, version=version ) - return scu.sendPDFFile(REQUEST, pdfdoc, filename) + return scu.sendPDFFile(pdfdoc, filename) _EXPL_BULL = """Versions des bulletins: