From 577cac00eeabde3fb9c441e5a0ab8d7ba8e4b5dd Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 2 Mar 2022 23:14:04 +0100 Subject: [PATCH] =?UTF-8?q?Export=20des=20annotations=20sur=20des=20groupe?= =?UTF-8?q?s=20d'=C3=A9tudiants.=20Closes=20#327?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_groups_exports.py | 96 ++++++++++++++++++++++++++++++++ app/scodoc/sco_groups_view.py | 2 + app/scodoc/sco_utils.py | 2 +- app/views/scolar.py | 13 +++-- sco_version.py | 2 +- 5 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 app/scodoc/sco_groups_exports.py diff --git a/app/scodoc/sco_groups_exports.py b/app/scodoc/sco_groups_exports.py new file mode 100644 index 00000000..b2e95545 --- /dev/null +++ b/app/scodoc/sco_groups_exports.py @@ -0,0 +1,96 @@ +# -*- mode: python -*- +# -*- coding: utf-8 -*- + +############################################################################## +# +# Gestion scolarite IUT +# +# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Emmanuel Viennet emmanuel.viennet@viennet.net +# +############################################################################## + +"""Exports groupes +""" +from flask import request + +from app.scodoc import notesdb as ndb +from app.scodoc import sco_excel +from app.scodoc import sco_groups_view +from app.scodoc import sco_preferences +from app.scodoc.gen_tables import GenTable +import app.scodoc.sco_utils as scu +import sco_version + + +def groups_list_annotation(group_ids: list[int]) -> list[dict]: + """Renvoie la liste des annotations pour les groupes d"étudiants indiqués + Arg: liste des id de groupes + Clés: etudid, ine, nip, nom, prenom, date, comment + """ + cnx = ndb.GetDBConnexion() + cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) + annotations = [] + for group_id in group_ids: + cursor.execute( + """SELECT i.id AS etudid, i.code_nip, i.code_ine, i.nom, i.prenom, ea.date, ea.comment + FROM group_membership gm, identite i, etud_annotations ea + WHERE gm.group_id=%(group_ids)s + AND gm.etudid=i.id + AND i.id=ea.etudid + """, + {"group_ids": group_id}, + ) + annotations += cursor.dictfetchall() + return annotations + + +def groups_export_annotations(group_ids, formsemestre_id=None, format="html"): + """Les annotations""" + groups_infos = sco_groups_view.DisplayedGroupsInfos( + group_ids, formsemestre_id=formsemestre_id + ) + annotations = groups_list_annotation(groups_infos.group_ids) + for annotation in annotations: + annotation["date_str"] = annotation["date"].strftime("%d/%m/%Y à %Hh%M") + if format == "xls": + columns_ids = ("etudid", "nom", "prenom", "date", "comment") + else: + columns_ids = ("etudid", "nom", "prenom", "date_str", "comment") + table = GenTable( + rows=annotations, + columns_ids=columns_ids, + titles={ + "etudid": "etudid", + "nom": "Nom", + "prenom": "Prénom", + "date": "Date", + "date_str": "Date", + "comment": "Annotation", + }, + origin="Généré par %s le " % sco_version.SCONAME + + scu.timedate_human_repr() + + "", + page_title=f"Annotations sur les étudiants de {groups_infos.groups_titles}", + caption="Annotations", + base_url=groups_infos.base_url, + html_sortable=True, + html_class="table_leftalign", + preferences=sco_preferences.SemPreferences(formsemestre_id), + ) + return table.make_page(format=format) diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 5b89ab44..259256bd 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -826,6 +826,8 @@ def tab_absences_html(groups_infos, etat=None): % groups_infos.groups_query_args, """
  • Liste d'appel avec photos
  • """ % groups_infos.groups_query_args, + """
  • Liste des annotations
  • """ + % groups_infos.groups_query_args, "", ] ) diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 7af19bc1..196c2c21 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -810,7 +810,7 @@ def abbrev_prenom(prenom): # def timedate_human_repr(): - "representation du temps courant pour utilisateur: a localiser" + "representation du temps courant pour utilisateur" return time.strftime("%d/%m/%Y à %Hh%M") diff --git a/app/views/scolar.py b/app/views/scolar.py index 060fd4c3..680f1dd2 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -68,8 +68,6 @@ from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message import app from app.scodoc.gen_tables import GenTable from app.scodoc import html_sco_header -from app.scodoc import html_sidebar -from app.scodoc import imageresize from app.scodoc import sco_import_etuds from app.scodoc import sco_abs from app.scodoc import sco_archives_etud @@ -87,12 +85,9 @@ from app.scodoc import sco_formsemestre_edit from app.scodoc import sco_formsemestre_inscriptions from app.scodoc import sco_groups from app.scodoc import sco_groups_edit +from app.scodoc import sco_groups_exports from app.scodoc import sco_groups_view -from app.scodoc import sco_logos -from app.scodoc import sco_news from app.scodoc import sco_page_etud -from app.scodoc import sco_parcours_dut -from app.scodoc import sco_permissions from app.scodoc import sco_permissions_check from app.scodoc import sco_photos from app.scodoc import sco_portal_apogee @@ -364,6 +359,12 @@ sco_publish( methods=["GET", "POST"], ) +sco_publish( + "/groups_export_annotations", + sco_groups_exports.groups_export_annotations, + Permission.ScoView, +) + @bp.route("/groups_view") @scodoc diff --git a/sco_version.py b/sco_version.py index 19d27aea..337ea606 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.1.69" +SCOVERSION = "9.1.70" SCONAME = "ScoDoc"