forked from ScoDoc/ScoDoc
filename export formations
This commit is contained in:
parent
7edd051183
commit
c5c0b510ec
@ -151,8 +151,14 @@ def formation_export(
|
|||||||
if mod["ects"] is None:
|
if mod["ects"] is None:
|
||||||
del mod["ects"]
|
del mod["ects"]
|
||||||
|
|
||||||
|
filename = f"scodoc_formation_{formation.departement.acronym}_{formation.acronyme or ''}_v{formation.version}"
|
||||||
return scu.sendResult(
|
return scu.sendResult(
|
||||||
F, name="formation", format=format, force_outer_xml_tag=False, attached=True
|
F,
|
||||||
|
name="formation",
|
||||||
|
format=format,
|
||||||
|
force_outer_xml_tag=False,
|
||||||
|
attached=True,
|
||||||
|
filename=filename,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -645,21 +645,30 @@ class ScoDocJSONEncoder(json.JSONEncoder):
|
|||||||
return json.JSONEncoder.default(self, o)
|
return json.JSONEncoder.default(self, o)
|
||||||
|
|
||||||
|
|
||||||
def sendJSON(data, attached=False):
|
def sendJSON(data, attached=False, filename=None):
|
||||||
js = json.dumps(data, indent=1, cls=ScoDocJSONEncoder)
|
js = json.dumps(data, indent=1, cls=ScoDocJSONEncoder)
|
||||||
return send_file(
|
return send_file(
|
||||||
js, filename="sco_data.json", mime=JSON_MIMETYPE, attached=attached
|
js, filename=filename or "sco_data.json", mime=JSON_MIMETYPE, attached=attached
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def sendXML(data, tagname=None, force_outer_xml_tag=True, attached=False, quote=True):
|
def sendXML(
|
||||||
|
data,
|
||||||
|
tagname=None,
|
||||||
|
force_outer_xml_tag=True,
|
||||||
|
attached=False,
|
||||||
|
quote=True,
|
||||||
|
filename=None,
|
||||||
|
):
|
||||||
if type(data) != list:
|
if type(data) != list:
|
||||||
data = [data] # always list-of-dicts
|
data = [data] # always list-of-dicts
|
||||||
if force_outer_xml_tag:
|
if force_outer_xml_tag:
|
||||||
data = [{tagname: data}]
|
data = [{tagname: data}]
|
||||||
tagname += "_list"
|
tagname += "_list"
|
||||||
doc = sco_xml.simple_dictlist2xml(data, tagname=tagname, quote=quote)
|
doc = sco_xml.simple_dictlist2xml(data, tagname=tagname, quote=quote)
|
||||||
return send_file(doc, filename="sco_data.xml", mime=XML_MIMETYPE, attached=attached)
|
return send_file(
|
||||||
|
doc, filename=filename or "sco_data.xml", mime=XML_MIMETYPE, attached=attached
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def sendResult(
|
def sendResult(
|
||||||
@ -669,6 +678,7 @@ def sendResult(
|
|||||||
force_outer_xml_tag=True,
|
force_outer_xml_tag=True,
|
||||||
attached=False,
|
attached=False,
|
||||||
quote_xml=True,
|
quote_xml=True,
|
||||||
|
filename=None,
|
||||||
):
|
):
|
||||||
if (format is None) or (format == "html"):
|
if (format is None) or (format == "html"):
|
||||||
return data
|
return data
|
||||||
@ -679,9 +689,10 @@ def sendResult(
|
|||||||
force_outer_xml_tag=force_outer_xml_tag,
|
force_outer_xml_tag=force_outer_xml_tag,
|
||||||
attached=attached,
|
attached=attached,
|
||||||
quote=quote_xml,
|
quote=quote_xml,
|
||||||
|
filename=filename,
|
||||||
)
|
)
|
||||||
elif format == "json":
|
elif format == "json":
|
||||||
return sendJSON(data, attached=attached)
|
return sendJSON(data, attached=attached, filename=filename)
|
||||||
else:
|
else:
|
||||||
raise ValueError("invalid format: %s" % format)
|
raise ValueError("invalid format: %s" % format)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user