diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index ca851306d8..4e8bb81a8e 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -372,6 +372,11 @@ def _check_duplicate_code(cnx, args, code_name, context, edit=True, REQUEST=None raise ScoGenError(err_page) +def _check_civilite(args): + civilite = args.get("civilite", "X") or "X" + args["civilite"] = input_civilite(civilite) # TODO: A faire valider + + def identite_edit(cnx, args, context=None, REQUEST=None): """Modifie l'identite d'un étudiant. Si context et notification et difference, envoie message notification. @@ -409,6 +414,7 @@ def identite_create(cnx, args, context=None, REQUEST=None): "check unique etudid, then create" _check_duplicate_code(cnx, args, "code_nip", context, edit=False, REQUEST=REQUEST) _check_duplicate_code(cnx, args, "code_ine", context, edit=False, REQUEST=REQUEST) + _check_civilite(args) if "etudid" in args: etudid = args["etudid"] @@ -761,7 +767,6 @@ _etud_annotationsEditor = ndb.EditableTable( output_formators={"comment": safehtml.html_to_safe_html, "date": ndb.DateISOtoDMY}, ) - etud_annotations_create = _etud_annotationsEditor.create etud_annotations_delete = _etud_annotationsEditor.delete etud_annotations_list = _etud_annotationsEditor.list @@ -1059,4 +1064,4 @@ def descr_situation_etud(context, etudid, ne=""): else: date_dem = events[0]["event_date"] situation += " le " + str(date_dem) - return situation \ No newline at end of file + return situation diff --git a/app/scodoc/sco_excel.py b/app/scodoc/sco_excel.py index 06e2ad70ba..8326580305 100644 --- a/app/scodoc/sco_excel.py +++ b/app/scodoc/sco_excel.py @@ -34,6 +34,7 @@ import time from enum import Enum from tempfile import NamedTemporaryFile +import openpyxl.utils.datetime from openpyxl import Workbook, load_workbook from openpyxl.cell import WriteOnlyCell from openpyxl.styles import Font, Border, Side, Alignment, PatternFill @@ -86,40 +87,42 @@ def send_excel_file(request, data, filename, mime=scu.XLSX_MIMETYPE): # a datetime.time object will be returned. #
Note: 1904-01-01 is not regarded as a valid date in the datemode 1 system; its "serial number" # is zero. - -_XLDAYS_TOO_LARGE = (2958466, 2958466 - 1462) # This is equivalent to 10000-01-01 +# +# _XLDAYS_TOO_LARGE = (2958466, 2958466 - 1462) # This is equivalent to 10000-01-01 +# def xldate_as_datetime(xldate, datemode=0): - if datemode not in (0, 1): - raise ValueError("invalid mode %s" % datemode) - if xldate == 0.00: - return datetime.time(0, 0, 0) - if xldate < 0.00: - raise ValueError("invalid date code %s" % xldate) - xldays = int(xldate) - frac = xldate - xldays - seconds = int(round(frac * 86400.0)) - assert 0 <= seconds <= 86400 - if seconds == 86400: - seconds = 0 - xldays += 1 - if xldays >= _XLDAYS_TOO_LARGE[datemode]: - raise ValueError("date too large %s" % xldate) - - if xldays == 0: - # second = seconds % 60; minutes = seconds // 60 - minutes, second = divmod(seconds, 60) - # minute = minutes % 60; hour = minutes // 60 - hour, minute = divmod(minutes, 60) - return datetime.time(hour, minute, second) - - if xldays < 61 and datemode == 0: - raise ValueError("ambiguous date %s" % xldate) - - return datetime.datetime.fromordinal( - xldays + 693594 + 1462 * datemode - ) + datetime.timedelta(seconds=seconds) + return openpyxl.utils.datetime.from_ISO8601(xldate) + # if datemode not in (0, 1): + # raise ValueError("invalid mode %s" % datemode) + # if xldate == 0.00: + # return datetime.time(0, 0, 0) + # if xldate < 0.00: + # raise ValueError("invalid date code %s" % xldate) + # xldays = int(xldate) + # frac = xldate - xldays + # seconds = int(round(frac * 86400.0)) + # assert 0 <= seconds <= 86400 + # if seconds == 86400: + # seconds = 0 + # xldays += 1 + # if xldays >= _XLDAYS_TOO_LARGE[datemode]: + # raise ValueError("date too large %s" % xldate) + # + # if xldays == 0: + # # second = seconds % 60; minutes = seconds // 60 + # minutes, second = divmod(seconds, 60) + # # minute = minutes % 60; hour = minutes // 60 + # hour, minute = divmod(minutes, 60) + # return datetime.time(hour, minute, second) + # + # if xldays < 61 and datemode == 0: + # raise ValueError("ambiguous date %s" % xldate) + # + # return datetime.datetime.fromordinal( + # xldays + 693594 + 1462 * datemode + # ) + datetime.timedelta(seconds=seconds) class ScoExcelBook: diff --git a/app/scodoc/sco_import_etuds.py b/app/scodoc/sco_import_etuds.py index 4990591521..d31e13bf3c 100644 --- a/app/scodoc/sco_import_etuds.py +++ b/app/scodoc/sco_import_etuds.py @@ -32,10 +32,14 @@ import collections import os import re import time +from datetime import date + +import flask import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb from app.scodoc.notes_log import log +from app.scodoc.sco_excel import COLORS from app.scodoc.sco_formsemestre_inscriptions import ( do_formsemestre_inscription_with_modules, ) @@ -164,7 +168,7 @@ def sco_import_generate_excel_sample( If group_ids, liste les etudiants de ces groupes """ style = sco_excel.excel_make_style(bold=True) - style_required = sco_excel.excel_make_style(bold=True, color="red") + style_required = sco_excel.excel_make_style(bold=True, color=COLORS.RED) titles = [] titlesStyles = [] for l in fmt: @@ -214,7 +218,7 @@ def sco_import_generate_excel_sample( else: lines = [[]] # empty content, titles only return sco_excel.excel_simple_table( - titles=titles, titlesStyles=titlesStyles, sheet_name="Etudiants", lines=lines + titles=titles, titles_styles=titlesStyles, sheet_name="Etudiants", lines=lines ) @@ -238,7 +242,7 @@ def students_import_excel( ) if REQUEST: if formsemestre_id: - dest = "formsemestre_status?formsemestre_id=%s" % formsemestre_id + dest = "Notes/formsemestre_status?formsemestre_id=%s" % formsemestre_id else: dest = scu.NotesURL() H = [html_sco_header.sco_header(page_title="Import etudiants")] @@ -271,12 +275,11 @@ def scolars_import_excel_file( exceldata = datafile.read() if not exceldata: raise ScoValueError("Ficher excel vide ou invalide") - diag, data = sco_excel.Excel_to_list(exceldata) + diag, data = sco_excel.excel_bytes_to_list(exceldata) if not data: # probably a bug raise ScoException("scolars_import_excel_file: empty file !") formsemestre_to_invalidate = set() - # 1- --- check title line titles = {} fmt = sco_import_format() @@ -378,8 +381,8 @@ def scolars_import_excel_file( # Excel date conversion: if scu.strlower(titleslist[i]) == "date_naissance": if val: - if re.match(r"^[0-9]*\.?[0-9]*$", str(val)): - val = sco_excel.xldate_as_datetime(float(val)) + # if re.match(r"^[0-9]*\.?[0-9]*$", str(val)): + val = sco_excel.xldate_as_datetime(val) # INE if ( scu.strlower(titleslist[i]) == "code_ine" @@ -625,7 +628,7 @@ def scolars_import_admission( etuds_by_nomprenom[np] = m exceldata = datafile.read() - diag2, data = sco_excel.Excel_to_list(exceldata, convert_to_string=False) + diag2, data = sco_excel.excel_bytes_to_list(exceldata) if not data: raise ScoException("scolars_import_admission: empty file !") diag += diag2 diff --git a/app/scodoc/sco_pdf.py b/app/scodoc/sco_pdf.py index f90fed8cf8..2721f91921 100755 --- a/app/scodoc/sco_pdf.py +++ b/app/scodoc/sco_pdf.py @@ -126,7 +126,6 @@ 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) diff --git a/app/scodoc/sco_pvpdf.py b/app/scodoc/sco_pvpdf.py index 9351c578ff..2f101cf679 100644 --- a/app/scodoc/sco_pvpdf.py +++ b/app/scodoc/sco_pvpdf.py @@ -222,7 +222,6 @@ 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, diff --git a/app/views/absences.py b/app/views/absences.py index ffde5f8322..c5591f1882 100644 --- a/app/views/absences.py +++ b/app/views/absences.py @@ -793,7 +793,7 @@ def _gen_form_saisie_groupe( % ( td_matin_class, bulle_am, - etudid + ":" + date + ":" + "am", + str(etudid) + ":" + date + ":" + "am", checked, etudid, date + ":am", diff --git a/app/views/scolar.py b/app/views/scolar.py index 5ac226f69a..a06cc811e8 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -1759,8 +1759,7 @@ def check_group_apogee( return "\n".join(H) + html_sco_header.sco_footer() -@bp.route("/form_students_import_excel") -@scodoc +@bp.route("/form_students_import_excel", methods=["GET", "POST"]) @permission_required(Permission.ScoEtudInscrit) @scodoc7func(context) def form_students_import_excel(context, REQUEST, formsemestre_id=None): @@ -1768,7 +1767,12 @@ def form_students_import_excel(context, REQUEST, formsemestre_id=None): if formsemestre_id: sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) dest_url = ( - scu.ScoURL() + "/formsemestre_status?formsemestre_id=%s" % formsemestre_id + # scu.ScoURL() + "/formsemestre_status?formsemestre_id=%s" % formsemestre_id # TODO: Remplacer par for_url ? + url_for( + "notes.formsemestre_status", + scodoc_dept=g.scodoc_dept, + formsemestre_id=formsemestre_id, + ) ) else: sem = None