diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..b7f214681a --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] + max-line-length = 88 + ignore = E203,W503 \ No newline at end of file diff --git a/app/comp/moy_sem.py b/app/comp/moy_sem.py index a1fe0104ae..15313550a6 100644 --- a/app/comp/moy_sem.py +++ b/app/comp/moy_sem.py @@ -78,7 +78,11 @@ def compute_sem_moys_apc_using_ects( else: ects = ects_df.to_numpy() # ects est maintenant un array nb_etuds x nb_ues + moy_gen = (etud_moy_ue_df * ects).sum(axis=1) / ects.sum(axis=1) + except ZeroDivisionError: + # peut arriver si aucun module... on ignore + moy_gen = pd.Series(np.NaN, index=etud_moy_ue_df.index) except TypeError: if None in ects: formation = db.session.get(Formation, formation_id) diff --git a/app/email.py b/app/email.py index a75b2def3c..a983ef2df8 100644 --- a/app/email.py +++ b/app/email.py @@ -79,13 +79,15 @@ Adresses d'origine: to : {orig_to} cc : {orig_cc} bcc: {orig_bcc} ---- +--- \n\n""" + msg.body ) current_app.logger.info( - f"""email sent to{' (mode test)' if email_test_mode_address else ''}: {msg.recipients} + f"""email sent to{ + ' (mode test)' if email_test_mode_address else '' + }: {msg.recipients} from sender {msg.sender} """ ) @@ -98,7 +100,8 @@ def get_from_addr(dept_acronym: str = None): """L'adresse "from" à utiliser pour envoyer un mail Si le departement est spécifié, ou si l'attribut `g.scodoc_dept`existe, - prend le `email_from_addr` des préférences de ce département si ce champ est non vide. + prend le `email_from_addr` des préférences de ce département si ce champ + est non vide. Sinon, utilise le paramètre global `email_from_addr`. Sinon, la variable de config `SCODOC_MAIL_FROM`. """ diff --git a/app/scodoc/notesdb.py b/app/scodoc/notesdb.py index 3b7dd26547..044d0dc612 100644 --- a/app/scodoc/notesdb.py +++ b/app/scodoc/notesdb.py @@ -1,19 +1,17 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- +import datetime import html import traceback + +from flask import g, current_app, abort import psycopg2 import psycopg2.pool import psycopg2.extras -from flask import g, current_app, abort - -import app -import app.scodoc.sco_utils as scu from app import log from app.scodoc.sco_exceptions import ScoException, ScoValueError, NoteProcessError -import datetime quote_html = html.escape diff --git a/app/scodoc/sco_abs.py b/app/scodoc/sco_abs.py index 1e56ca87e3..8a04cac276 100755 --- a/app/scodoc/sco_abs.py +++ b/app/scodoc/sco_abs.py @@ -318,7 +318,7 @@ def list_abs_in_range( Returns: List of absences """ - if matin != None: + if matin is not None: matin = _toboolean(matin) ismatin = " AND A.MATIN = %(matin)s " else: @@ -387,7 +387,7 @@ def count_abs_just(etudid, debut, fin, matin=None, moduleimpl_id=None) -> int: Returns: An integer. """ - if matin != None: + if matin is not None: matin = _toboolean(matin) ismatin = " AND A.MATIN = %(matin)s " else: @@ -482,7 +482,9 @@ def _get_abs_description(a, cursor=None): else: a["matin"] = False cursor.execute( - """select * from absences where etudid=%(etudid)s and jour=%(jour)s and matin=%(matin)s order by entry_date desc""", + """SELECT * FROM absences + WHERE etudid=%(etudid)s AND jour=%(jour)s AND matin=%(matin)s + ORDER BY entry_date desc""", a, ) A = cursor.dictfetchall() @@ -517,9 +519,9 @@ def list_abs_jour(date, am=True, pm=True, is_abs=True, is_just=None): req = """SELECT DISTINCT etudid, jour, matin FROM ABSENCES A WHERE A.jour = %(date)s """ - if is_abs != None: + if is_abs is not None: req += " AND A.estabs = %(is_abs)s" - if is_just != None: + if is_just is not None: req += " AND A.estjust = %(is_just)s" if not am: req += " AND NOT matin " @@ -883,7 +885,7 @@ def MonthTableBody( descr = ev[4] # cc = [] - if color != None: + if color is not None: cc.append('' % color) else: cc.append('') @@ -896,7 +898,7 @@ def MonthTableBody( cc.append("" % (href, descr)) if legend or d == 1: - if pad_width != None: + if pad_width is not None: n = pad_width - len(legend) # pad to 8 cars if n > 0: legend = ( @@ -959,7 +961,7 @@ def MonthTableBody( ev_year = int(ev[0][:4]) ev_month = int(ev[0][5:7]) ev_day = int(ev[0][8:10]) - if ev[4] != None: + if ev[4] is not None: ev_half = int(ev[4]) else: ev_half = 0 @@ -978,7 +980,7 @@ def MonthTableBody( if len(ev) > 5 and ev[5]: descr = ev[5] # - if color != None: + if color is not None: cc.append('' % (color)) else: cc.append('') @@ -1072,7 +1074,8 @@ def invalidate_abs_count_sem(sem): def invalidate_abs_etud_date(etudid, date): # was invalidateAbsEtudDate - """Doit etre appelé à chaque modification des absences pour cet étudiant et cette date. + """Doit etre appelé à chaque modification des absences + pour cet étudiant et cette date. Invalide cache absence et caches semestre date: date au format ISO """ diff --git a/app/scodoc/sco_abs_views.py b/app/scodoc/sco_abs_views.py index f3473bf5dd..4af828c393 100644 --- a/app/scodoc/sco_abs_views.py +++ b/app/scodoc/sco_abs_views.py @@ -137,14 +137,14 @@ def doSignaleAbsence( ] if dates: H.append( - f"""

Ajout de {nbadded} absences {just_str}justifiées + f"""

Ajout de {nbadded} absences {just_str}justifiées du {datedebut} au {datefin} {indication_module}

""" ) else: H.append( - f"""

Aucune date ouvrable + f"""

Aucune date ouvrable entre le {datedebut} et le {datefin} !

""" @@ -152,11 +152,11 @@ def doSignaleAbsence( H.append( f"""