forked from ScoDoc/DocScoDoc
Fix:archives (again...)
This commit is contained in:
parent
0fe89b0501
commit
0330544a0b
@ -47,6 +47,7 @@
|
|||||||
qui est une description (humaine, format libre) de l'archive.
|
qui est une description (humaine, format libre) de l'archive.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import chardet
|
||||||
import datetime
|
import datetime
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
@ -55,7 +56,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
import chardet
|
from typing import Union
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
from flask import g, request
|
from flask import g, request
|
||||||
@ -232,14 +233,17 @@ class BaseArchiver(object):
|
|||||||
os.mkdir(archive_id) # if exists, raises an OSError
|
os.mkdir(archive_id) # if exists, raises an OSError
|
||||||
finally:
|
finally:
|
||||||
scu.GSL.release()
|
scu.GSL.release()
|
||||||
self.store(archive_id, "_description.txt", description.encode("utf-8"))
|
self.store(archive_id, "_description.txt", description)
|
||||||
return archive_id
|
return archive_id
|
||||||
|
|
||||||
def store(self, archive_id: str, filename: str, data: bytes):
|
def store(self, archive_id: str, filename: str, data: Union[str, bytes]):
|
||||||
"""Store data in archive, under given filename.
|
"""Store data in archive, under given filename.
|
||||||
Filename may be modified (sanitized): return used filename
|
Filename may be modified (sanitized): return used filename
|
||||||
The file is created or replaced.
|
The file is created or replaced.
|
||||||
|
data may be str or bytes
|
||||||
"""
|
"""
|
||||||
|
if isinstance(data, str):
|
||||||
|
data = data.encode(scu.SCO_ENCODING)
|
||||||
self.initialize()
|
self.initialize()
|
||||||
filename = scu.sanitize_filename(filename)
|
filename = scu.sanitize_filename(filename)
|
||||||
log("storing %s (%d bytes) in %s" % (filename, len(data), archive_id))
|
log("storing %s (%d bytes) in %s" % (filename, len(data), archive_id))
|
||||||
@ -350,13 +354,11 @@ def do_formsemestre_archive(
|
|||||||
html_sco_header.sco_footer(),
|
html_sco_header.sco_footer(),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
data = data.encode(scu.SCO_ENCODING)
|
|
||||||
PVArchive.store(archive_id, "Tableau_moyennes.html", data)
|
PVArchive.store(archive_id, "Tableau_moyennes.html", data)
|
||||||
|
|
||||||
# Bulletins en JSON
|
# Bulletins en JSON
|
||||||
data = gen_formsemestre_recapcomplet_json(formsemestre_id, xml_with_decisions=True)
|
data = gen_formsemestre_recapcomplet_json(formsemestre_id, xml_with_decisions=True)
|
||||||
data_js = json.dumps(data, indent=1, cls=scu.ScoDocJSONEncoder)
|
data_js = json.dumps(data, indent=1, cls=scu.ScoDocJSONEncoder)
|
||||||
data_js = data_js.encode(scu.SCO_ENCODING)
|
|
||||||
if data:
|
if data:
|
||||||
PVArchive.store(archive_id, "Bulletins.json", data_js)
|
PVArchive.store(archive_id, "Bulletins.json", data_js)
|
||||||
# Decisions de jury, en XLS
|
# Decisions de jury, en XLS
|
||||||
@ -365,7 +367,7 @@ def do_formsemestre_archive(
|
|||||||
PVArchive.store(
|
PVArchive.store(
|
||||||
archive_id,
|
archive_id,
|
||||||
"Decisions_Jury" + scu.XLSX_SUFFIX,
|
"Decisions_Jury" + scu.XLSX_SUFFIX,
|
||||||
data.encode(scu.SCO_ENCODING),
|
data,
|
||||||
)
|
)
|
||||||
# Classeur bulletins (PDF)
|
# Classeur bulletins (PDF)
|
||||||
data, _ = sco_bulletins_pdf.get_formsemestre_bulletins_pdf(
|
data, _ = sco_bulletins_pdf.get_formsemestre_bulletins_pdf(
|
||||||
|
Loading…
Reference in New Issue
Block a user