From b3225e07f7293fd6f2835b593402383c666da68e Mon Sep 17 00:00:00 2001 From: jean-marie Place Date: Fri, 17 Sep 2021 08:22:54 +0200 Subject: [PATCH 1/2] avant tests --- app/scodoc/sco_placement.py | 51 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/app/scodoc/sco_placement.py b/app/scodoc/sco_placement.py index 32f89437..9a234875 100644 --- a/app/scodoc/sco_placement.py +++ b/app/scodoc/sco_placement.py @@ -188,7 +188,7 @@ def placement_eval_selectetuds(evaluation_id): """ % runner.__dict__ ) - return runner._exec_placement() # calcul et generation du fichier + return runner.exec_placement() # calcul et generation du fichier # return flask.redirect(url_for("scodoc.index")) H = [html_sco_header.sco_header(init_jquery_ui=True)] H.append(sco_evaluations.evaluation_describe(evaluation_id=evaluation_id)) @@ -235,16 +235,14 @@ class PlacementRunner: self.evaltitre = self.eval_data["description"] else: self.evaltitre = "évaluation du %s" % self.eval_data["jour"] - self.desceval = [ - ["%s" % self.sem["titreannee"]], - ["Module : %s - %s" % (self.Mod["code"], self.Mod["abbrev"])], - ["Surveillants : %s" % self.surveillants], - ["Batiment : %(batiment)s - Salle : %(salle)s" % self.__dict__], - [ - "Controle : %s (coef. %g)" - % (self.evaltitre, self.eval_data["coefficient"]) - ], - ] # une liste de liste de chaines: description de l'evaluation + self.desceval = [ # une liste de chaines: description de l'evaluation + "%s" % self.sem["titreannee"], + "Module : %s - %s" % (self.Mod["code"], self.Mod["abbrev"]), + "Surveillants : %s" % self.surveillants, + "Batiment : %(batiment)s - Salle : %(salle)s" % self.__dict__, + "Controle : %s (coef. %g)" + % (self.evaltitre, self.eval_data["coefficient"]), + ] def check_placement(self): # Check access (admin, respformation, and responsable_id) @@ -252,7 +250,7 @@ class PlacementRunner: self.current_user, self.moduleimpl_id ) - def _exec_placement(self): + def exec_placement(self): self._repartition() if self.file_format == "xls": return self._production_xls() @@ -310,18 +308,21 @@ class PlacementRunner: return plan def _production_xls(self): - filename = "placement_%s_%s%s" % (self.evalname, self.gr_title_filename, scu.XLSX_SUFFIX) + filename = "placement_%s_%s%s" % ( + self.evalname, + self.gr_title_filename, + scu.XLSX_SUFFIX, + ) xls = self._excel_feuille_placement() return sco_excel.send_from_flask(xls, filename) def _production_pdf(self): - pdf_title = self.desceval + pdf_title = "
".join(self.desceval) pdf_title += ( - "Date : %(jour)s - Horaire : %(heure_debut)s à %(heure_fin)s" + "\nDate : %(jour)s - Horaire : %(heure_debut)s à %(heure_fin)s" % self.eval_data ) - breakpoint() - filename = "placement_%(evalname)s_%(gr_title_filename)s.pdf" % self.__dict__ + filename = "placement_%(evalname)s_%(gr_title_filename)s" % self.__dict__ titles = { "nom": "Nom", "prenom": "Prenom", @@ -348,7 +349,6 @@ class PlacementRunner: ) else: rows.append({"nom": etud[0][0], "prenom": etud[0][1], "place": etud[1]}) - tab = GenTable( titles=titles, columns_ids=columns_ids, @@ -359,10 +359,11 @@ class PlacementRunner: + "", pdf_title=pdf_title, # pdf_shorttitle = '', - preferences=sco_preferences.SemPreferences(self.moduleimpl_data["formsemestre_id"]), - # html_generate_cells=False # la derniere ligne (moyennes) est incomplete + preferences=sco_preferences.SemPreferences( + self.moduleimpl_data["formsemestre_id"] + ), ) - t = tab.make_page(format="pdf", with_html_headers=False, REQUEST=REQUEST) + t = tab.make_page(format="pdf", with_html_headers=False) return t def _one_header(self, ws): @@ -476,7 +477,7 @@ class PlacementRunner: for line, desceval in enumerate(self.desceval): if line in [1, 4, 7]: ws.append_blank_row() - ws.append_single_cell_row(desceval[0], self.styles["titres"]) + ws.append_single_cell_row(desceval, self.styles["titres"]) ws.append_single_cell_row( "Date : %(jour)s - Horaire : %(heure_debut)s à %(heure_fin)s" % self.eval_data, @@ -514,10 +515,12 @@ class PlacementRunner: row += 3 col += 1 if col == self.nb_rangs: # On a fini la rangée courante - ws0.append_row(cells_a) # on affiche les 3 lignes construites + ws0.append_row(cells_a) # on affiche les 3 lignes construites ws0.append_row(cells_b) ws0.append_row(cells_c) - cells_a = [ws0.make_cell(rang, self.styles["2b"])] # on réinitialise les 3 lignes + cells_a = [ + ws0.make_cell(rang, self.styles["2b"]) + ] # on réinitialise les 3 lignes cells_b = [ws0.make_cell("", self.styles["2b"])] cells_c = [ws0.make_cell("", self.styles["2b"])] col = 0 From 5f6c43449735a82650c901c2507be2d7a2db176d Mon Sep 17 00:00:00 2001 From: jean-marie Place Date: Fri, 17 Sep 2021 09:20:04 +0200 Subject: [PATCH 2/2] minor refactor --- app/scodoc/sco_placement.py | 44 +++++++++++++++---------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/app/scodoc/sco_placement.py b/app/scodoc/sco_placement.py index 9a234875..9536d0b5 100644 --- a/app/scodoc/sco_placement.py +++ b/app/scodoc/sco_placement.py @@ -30,57 +30,50 @@ Contribution M. Salomon, UFC / IUT DE BELFORT-MONTBÉLIARD, 2016 """ -import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error import random import time from copy import copy import wtforms.validators -from flask import request, render_template, url_for +from flask import request, render_template from flask_login import current_user -from werkzeug import Response from flask_wtf import FlaskForm +from openpyxl.styles import PatternFill, Alignment, Border, Side, Font from wtforms import ( StringField, - PasswordField, - BooleanField, SubmitField, SelectField, RadioField, HiddenField, SelectMultipleField, - validators, ) -from wtforms.validators import ValidationError, DataRequired, Email, EqualTo - -from app.scodoc.sco_exceptions import ScoValueError import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb -from app.scodoc import html_sco_header +from app import ScoValueError +from app.scodoc import html_sco_header, sco_preferences from app.scodoc import sco_edit_module from app.scodoc import sco_evaluations from app.scodoc import sco_excel +from app.scodoc.sco_excel import ScoExcelBook, COLORS from app.scodoc import sco_formsemestre from app.scodoc import sco_formsemestre_inscriptions from app.scodoc import sco_groups from app.scodoc import sco_moduleimpl from app.scodoc import sco_permissions_check -from app.scodoc import sco_preferences -from app.scodoc import sco_saisie_notes +from app.scodoc.gen_tables import GenTable from app.scodoc import sco_etud import sco_version -from app.scodoc.gen_tables import GenTable -from app.scodoc.sco_excel import * # XXX à vérifier -from app.scodoc.TrivialFormulator import TrivialFormulator -_ = lambda x: x # sans babel -_l = _ +# _ = lambda x: x # sans babel +# _l = _ COORD = "Coordonnées" SEQ = "Continue" class PlacementForm(FlaskForm): + """Formulaire pour placement des étudiants en Salle""" + TOUS = "Tous" evaluation_id = HiddenField("evaluation_id") file_format = RadioField( @@ -115,7 +108,6 @@ class PlacementForm(FlaskForm): eval_data = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id}) if not eval_data: raise ScoValueError("invalid evaluation_id") - eval_data = eval_data[0] # groupes groups = sco_groups.do_evaluation_listegroupes( evaluation_id, include_default=True @@ -123,7 +115,7 @@ class PlacementForm(FlaskForm): self.groups_tree = {} self.has_groups = False for group in groups: - partition = group["partition_name"] or self.TOUS # TODO check required + partition = group["partition_name"] or self.TOUS group_id = group["group_id"] group_name = group["group_name"] or self.TOUS if partition not in self.groups_tree: @@ -190,10 +182,12 @@ def placement_eval_selectetuds(evaluation_id): ) return runner.exec_placement() # calcul et generation du fichier # return flask.redirect(url_for("scodoc.index")) - H = [html_sco_header.sco_header(init_jquery_ui=True)] - H.append(sco_evaluations.evaluation_describe(evaluation_id=evaluation_id)) - H.append("

Placement et émargement des étudiants

") - H.append(render_template("scodoc/forms/placement.html", form=form)) + H = [ + html_sco_header.sco_header(init_jquery_ui=True), + sco_evaluations.evaluation_describe(evaluation_id=evaluation_id), + "

Placement et émargement des étudiants

", + render_template("scodoc/forms/placement.html", form=form), + ] F = html_sco_header.sco_footer() return "\n".join(H) + "

" + F @@ -269,7 +263,6 @@ class PlacementRunner: def _build_listetud(self): if None in [g["group_name"] for g in self.groups]: # tous les etudiants getallstudents = True - gr_title_filename = "tous" else: getallstudents = False etudids = sco_groups.do_evaluation_listeetuds_groups( @@ -330,7 +323,6 @@ class PlacementRunner: "ligne": "Ligne", "place": "Place", } - nb_rangs = int(self.nb_rangs) if self.etiquetage == COORD: columns_ids = ["nom", "prenom", "colonne", "ligne"] else: @@ -531,7 +523,7 @@ class PlacementRunner: ws0.append_row(cells_c) ws0.set_row_dimension_height(row, space / 25) - def _next_page(ws): + def _next_page(self, ws): pass def _feuille1(self, ws, maxlines):