retire arguments REQUEST de sendResult et sendPDFFile

This commit is contained in:
Emmanuel Viennet 2021-09-21 15:53:33 +02:00
parent 2c97349acf
commit f516ccdfe7
12 changed files with 30 additions and 47 deletions

View File

@ -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:

View File

@ -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):

View File

@ -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

View File

@ -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():

View File

@ -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":
#
(

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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:<ul><li><bf>courte</bf>: moyennes des modules</li><li><bf>intermédiaire</bf>: moyennes des modules et notes des évaluations sélectionnées</li><li><bf>complète</bf>: toutes les notes</li><ul>"""
@ -1715,7 +1714,7 @@ def formsemestre_bulletins_pdf_choice(REQUEST, formsemestre_id, version=None):
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)
return formsemestre_bulletins_choice(
REQUEST,
formsemestre_id,
@ -1733,7 +1732,7 @@ def etud_bulletins_pdf(etudid, REQUEST, version="selectedevals"):
pdfdoc, filename = sco_bulletins_pdf.get_etud_bulletins_pdf(
etudid, REQUEST, version=version
)
return scu.sendPDFFile(REQUEST, pdfdoc, filename)
return scu.sendPDFFile(pdfdoc, filename)
@bp.route("/formsemestre_bulletins_mailetuds_choice")

View File

@ -336,7 +336,7 @@ def getEtudInfo(etudid=False, code_nip=False, filled=False, REQUEST=None, format
if format is None:
return etud
else:
return scu.sendResult(REQUEST, etud, name="etud", format=format)
return scu.sendResult(etud, name="etud", format=format)
sco_publish(
@ -391,7 +391,7 @@ def etud_info(etudid=None, format="xml", REQUEST=None):
"error": "code etudiant inconnu",
}
return scu.sendResult(
REQUEST, d, name="etudiant", format=format, force_outer_xml_tag=False
d, name="etudiant", format=format, force_outer_xml_tag=False
)
d = {}
etud = etuds[0]
@ -459,9 +459,7 @@ def etud_info(etudid=None, format="xml", REQUEST=None):
)
log("etud_info (%gs)" % (time.time() - t0))
return scu.sendResult(
REQUEST, d, name="etudiant", format=format, force_outer_xml_tag=False
)
return scu.sendResult(d, name="etudiant", format=format, force_outer_xml_tag=False)
# -------------------------- FICHE ETUDIANT --------------------------

View File

@ -88,7 +88,7 @@ def index_html(REQUEST, all_depts=False, with_inactives=False, format="html"):
@scodoc7func
def user_info(user_name, format="json", REQUEST=None):
info = sco_users.user_info(user_name)
return scu.sendResult(REQUEST, info, name="user", format=format)
return scu.sendResult(info, name="user", format=format)
@bp.route("/create_user_form", methods=["GET", "POST"])