forked from ScoDoc/DocScoDoc
various fixes. Bulletins et saisie décision ok.
This commit is contained in:
parent
3dc94775a1
commit
f0c96e3e68
@ -31,17 +31,13 @@ Module main: essais divers
|
||||
Emmanuel Viennet, 2021
|
||||
"""
|
||||
|
||||
import io
|
||||
import pprint
|
||||
from pprint import pprint as pp
|
||||
import functools
|
||||
import six.moves._thread # essai
|
||||
from zipfile import ZipFile
|
||||
|
||||
try:
|
||||
from io import StringIO ## for Python 3
|
||||
except ImportError:
|
||||
from cStringIO import StringIO ## for Python 2
|
||||
|
||||
import flask
|
||||
from flask import request, render_template, redirect
|
||||
from flask_login import login_required
|
||||
@ -180,7 +176,7 @@ def getzip():
|
||||
# REQUEST.RESPONSE.setHeader(
|
||||
# "content-disposition", 'attachement; filename="monzip.zip"'
|
||||
# )
|
||||
zipdata = StringIO()
|
||||
zipdata = io.StringIO()
|
||||
zipfile = ZipFile(zipdata, "w")
|
||||
zipfile.writestr("fichier1", "un contenu")
|
||||
zipfile.writestr("fichier2", "deux contenus")
|
||||
|
@ -187,7 +187,7 @@ def bonus_iutr(notes_sport, coefs, infos=None):
|
||||
# le bonus est le minimum entre 0.35 et la somme de toutes les bonifs
|
||||
bonus = min(0.35, sum([x for x in notes_sport]))
|
||||
for ue_id in infos["moy_ues"]:
|
||||
# open('/tmp/log','a').write( ue_id + infos['moy_ues'] + '\n\n' )
|
||||
# open('/tmp/log','a').write( str(ue_id) + infos['moy_ues'] + '\n\n' )
|
||||
ue_status = infos["moy_ues"][ue_id]
|
||||
if ue_status["sum_coefs"] > 0:
|
||||
# modifie moyenne UE dans semestre courant
|
||||
|
@ -1,17 +1,13 @@
|
||||
"""Simple image resize using PIL"""
|
||||
|
||||
import io
|
||||
from PIL import Image as PILImage
|
||||
|
||||
try:
|
||||
from io import StringIO # for Python 3
|
||||
except ImportError:
|
||||
from cStringIO import StringIO # for Python 2
|
||||
|
||||
|
||||
def ImageScale(img_file, maxx, maxy):
|
||||
im = PILImage.open(img_file)
|
||||
im.thumbnail((maxx, maxy), PILImage.ANTIALIAS)
|
||||
out_file_str = StringIO()
|
||||
out_file_str = io.BytesIO()
|
||||
im.save(out_file_str, im.format)
|
||||
out_file_str.seek(0)
|
||||
tmp = out_file_str.read()
|
||||
@ -25,7 +21,7 @@ def ImageScaleH(img_file, W=None, H=90):
|
||||
# keep aspect
|
||||
W = int((im.size[0] * H) / float(im.size[1]))
|
||||
im.thumbnail((W, H), PILImage.ANTIALIAS)
|
||||
out_file_str = StringIO()
|
||||
out_file_str = io.BytesIO()
|
||||
im.save(out_file_str, im.format)
|
||||
out_file_str.seek(0)
|
||||
tmp = out_file_str.read()
|
||||
|
@ -1289,7 +1289,18 @@ class NotesTable(object):
|
||||
cnx = ndb.GetDBConnexion()
|
||||
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
||||
cursor.execute(
|
||||
"select n.* from notes_notes n, notes_evaluation e, notes_moduleimpl m, notes_moduleimpl_inscription i where n.etudid = %(etudid)s and n.value = %(code_attente)s and n.evaluation_id=e.evaluation_id and e.moduleimpl_id=m.moduleimpl_id and m.formsemestre_id=%(formsemestre_id)s and e.coefficient != 0 and m.moduleimpl_id=i.moduleimpl_id and i.etudid=%(etudid)s",
|
||||
"""SELECT n.*
|
||||
FROM notes_notes n, notes_evaluation e, notes_moduleimpl m,
|
||||
notes_moduleimpl_inscription i
|
||||
WHERE n.etudid = %(etudid)s
|
||||
and n.value = %(code_attente)s
|
||||
and n.evaluation_id = e.id
|
||||
and e.moduleimpl_id = m.id
|
||||
and m.formsemestre_id = %(formsemestre_id)s
|
||||
and e.coefficient != 0
|
||||
and m.id = i.moduleimpl_id
|
||||
and i.etudid=%(etudid)s
|
||||
""",
|
||||
{
|
||||
"formsemestre_id": self.formsemestre_id,
|
||||
"etudid": etudid,
|
||||
|
@ -81,15 +81,12 @@ XXX A vérifier:
|
||||
"""
|
||||
|
||||
import collections
|
||||
import datetime
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import datetime
|
||||
import os
|
||||
|
||||
try:
|
||||
from io import StringIO # for Python 3
|
||||
except ImportError:
|
||||
from cStringIO import StringIO # for Python 2
|
||||
from zipfile import ZipFile
|
||||
import pprint
|
||||
from functools import reduce
|
||||
@ -203,7 +200,7 @@ def fix_data_encoding(
|
||||
|
||||
class StringIOFileLineWrapper(object):
|
||||
def __init__(self, data):
|
||||
self.f = StringIO(data)
|
||||
self.f = io.StringIO(data)
|
||||
self.lineno = 0
|
||||
|
||||
def close(self):
|
||||
@ -1223,7 +1220,7 @@ def export_csv_to_apogee(
|
||||
e.associate_sco(context, apo_data)
|
||||
|
||||
# Ré-écrit le fichier Apogée
|
||||
f = StringIO()
|
||||
f = io.StringIO()
|
||||
apo_data.write_header(f)
|
||||
apo_data.write_etuds(f)
|
||||
|
||||
@ -1245,7 +1242,7 @@ def export_csv_to_apogee(
|
||||
|
||||
# Create ZIP
|
||||
if not dest_zip:
|
||||
data = StringIO()
|
||||
data = io.StringIO()
|
||||
dest_zip = ZipFile(data, "w")
|
||||
my_zip = True
|
||||
else:
|
||||
@ -1269,7 +1266,7 @@ def export_csv_to_apogee(
|
||||
nar_filename = basename + "-nar" + scu.XLSX_SUFFIX
|
||||
cr_filename = basename + "-decisions" + scu.XLSX_SUFFIX
|
||||
|
||||
logf = StringIO()
|
||||
logf = io.StringIO()
|
||||
logf.write("export_to_apogee du %s\n\n" % time.ctime())
|
||||
logf.write("Semestres ScoDoc sources:\n")
|
||||
for sem in apo_data.sems_etape:
|
||||
|
@ -50,15 +50,12 @@ Pour définir un nouveau type de bulletin:
|
||||
Chaque semestre peut si nécessaire utiliser un type de bulletin différent.
|
||||
|
||||
"""
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import traceback
|
||||
import re
|
||||
import os
|
||||
|
||||
try:
|
||||
from io import StringIO # for Python 3
|
||||
except ImportError:
|
||||
from cStringIO import StringIO # for Python 2
|
||||
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate
|
||||
|
||||
from app.scodoc import VERSION
|
||||
@ -92,7 +89,7 @@ def pdfassemblebulletins(
|
||||
sco_preferences.get_preference("bottom_margin", formsemestre_id),
|
||||
)
|
||||
|
||||
report = StringIO.StringIO() # in-memory document, no disk file
|
||||
report = io.BytesIO() # in-memory document, no disk file
|
||||
document = BaseDocTemplate(report)
|
||||
document.addPageTemplates(
|
||||
sco_pdf.ScolarsPageTemplate(
|
||||
@ -149,9 +146,14 @@ def process_field(
|
||||
image_dir = scu.SCODOC_LOGOS_DIR + "/logos_" + scu.get_dept_id() + "/"
|
||||
if not os.path.exists(image_dir):
|
||||
image_dir = scu.SCODOC_LOGOS_DIR + "/" # use global logos
|
||||
if not os.path.exists(image_dir):
|
||||
log(f"Warning: missing global logo directory ({image_dir})")
|
||||
image_dir = None
|
||||
|
||||
text = re.sub(
|
||||
r"<(\s*)logo(.*?)src\s*=\s*(.*?)>", r"<\1logo\2\3>", text
|
||||
) # remove forbidden src attribute
|
||||
if image_dir is not None:
|
||||
text = re.sub(
|
||||
r'<\s*logo(.*?)name\s*=\s*"(\w*?)"(.*?)/?>',
|
||||
r'<img\1src="%s/logo_\2.jpg"\3/>' % image_dir,
|
||||
@ -170,7 +172,7 @@ def get_formsemestre_bulletins_pdf(
|
||||
"document pdf et filename"
|
||||
from app.scodoc import sco_bulletins
|
||||
|
||||
cached = sco_cache.SemBulletinsPDFCache.get(formsemestre_id + "_" + version)
|
||||
cached = sco_cache.SemBulletinsPDFCache.get(str(formsemestre_id) + "_" + version)
|
||||
if cached:
|
||||
return cached[1], cached[0]
|
||||
fragments = []
|
||||
@ -219,7 +221,7 @@ def get_formsemestre_bulletins_pdf(
|
||||
filename = scu.unescape_html(filename).replace(" ", "_").replace("&", "")
|
||||
# fill cache
|
||||
sco_cache.SemBulletinsPDFCache.set(
|
||||
formsemestre_id + "_" + version, (filename, pdfdoc)
|
||||
str(formsemestre_id) + "_" + version, (filename, pdfdoc)
|
||||
)
|
||||
return pdfdoc, filename
|
||||
|
||||
|
@ -86,8 +86,10 @@ class DecisionSem(object):
|
||||
self.devenir = devenir
|
||||
self.assiduite = assiduite
|
||||
self.rule_id = rule_id
|
||||
# code unique utilise pour la gestion du formulaire
|
||||
self.codechoice = str(
|
||||
# code unique (string) utilise pour la gestion du formulaire
|
||||
self.codechoice = (
|
||||
"C" # prefix pour éviter que Flask le considère comme int
|
||||
+ str(
|
||||
hash(
|
||||
(
|
||||
code_etat,
|
||||
@ -98,6 +100,7 @@ class DecisionSem(object):
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
# xxx debug
|
||||
# log('%s: %s %s %s %s %s' % (self.codechoice,code_etat,new_code_prev,formsemestre_id_utilise_pour_compenser,devenir,assiduite) )
|
||||
|
||||
|
@ -126,6 +126,7 @@ def makeParas(txt, style, suppress_empty=False):
|
||||
paras = r
|
||||
return [Paragraph(SU(s), style) for s in paras]
|
||||
except Exception as e:
|
||||
raise
|
||||
detail = " " + str(e)
|
||||
log(traceback.format_exc())
|
||||
log("Invalid pdf para format: %s" % txt)
|
||||
|
@ -201,8 +201,8 @@ class CourrierIndividuelTemplate(PageTemplate):
|
||||
self.logo_header = None
|
||||
# Search logos in dept specific dir, then in global scu.CONFIG dir
|
||||
for image_dir in (
|
||||
scu.SCODOC_LOGOS_DIR + "/logos_" + scu.get_dept_id() + "/",
|
||||
scu.SCODOC_LOGOS_DIR + "/", # global logos
|
||||
scu.SCODOC_LOGOS_DIR + "/logos_" + scu.get_dept_id(),
|
||||
scu.SCODOC_LOGOS_DIR, # global logos
|
||||
):
|
||||
for suffix in scu.LOGOS_IMAGES_ALLOWED_TYPES:
|
||||
if template_name == "PVJuryTemplate":
|
||||
@ -222,6 +222,7 @@ class CourrierIndividuelTemplate(PageTemplate):
|
||||
|
||||
fn = image_dir + "/logo_header" + "." + suffix
|
||||
if not self.logo_header and os.path.exists(fn):
|
||||
log("XXX XXX : logo_header " + fn)
|
||||
self.logo_header = Image(
|
||||
fn,
|
||||
height=LOGO_HEADER_HEIGHT,
|
||||
|
@ -64,10 +64,10 @@ ATTRIBUTES_MAPPING = {
|
||||
}
|
||||
|
||||
|
||||
def setup_log(dept_id: str):
|
||||
def setup_log(dept_acronym: str):
|
||||
"""log to console (stderr) and /opt/scodoc-data/log/migration78.log"""
|
||||
log_formatter = logging.Formatter(
|
||||
"%(asctime)s %(levelname)s (" + dept_id + ") %(message)s"
|
||||
"%(asctime)s %(levelname)s (" + dept_acronym + ") %(message)s"
|
||||
)
|
||||
# Log to file:
|
||||
logger = logging.getLogger()
|
||||
@ -117,8 +117,7 @@ def import_scodoc7_dept(dept_id: str, dept_db_uri=None):
|
||||
logging.info(f"All table imported: clearing app caches...")
|
||||
clear_scodoc_cache()
|
||||
logging.info(f"Done.")
|
||||
logging.warning(f"Un redémarrage du serveur postgresql est conseillé")
|
||||
logging.warning(f"systemctl restart postgresql"
|
||||
logging.warning(f"Un redémarrage du serveur postgresql est conseillé.")
|
||||
|
||||
|
||||
def get_class_for_table(table):
|
||||
|
Loading…
Reference in New Issue
Block a user