DocScoDoc/app/scodoc/sco_modalites.py

111 lines
3.6 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2021-01-01 17:51:08 +01:00
# Copyright (c) 1999 - 2021 Emmanuel Viennet. All rights reserved.
2020-09-26 16:19:37 +02:00
#
# 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
#
##############################################################################
"""Modalites des semestres
La "modalite" est utilisee pour organiser les listes de semestres sur la page d'accueil.
Elle n'est pas utilisée pour les parcours, ni pour rien d'autre
(c'est donc un attribut "cosmétique").
"""
import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu
2021-08-29 19:57:32 +02:00
from app import log
2020-09-26 16:19:37 +02:00
def list_formsemestres_modalites(sems):
2021-01-01 18:40:47 +01:00
"""Liste ordonnée des modalités présentes dans ces formsemestres"""
2020-09-26 16:19:37 +02:00
modalites = {}
for sem in sems:
if sem["modalite"] not in modalites:
m = do_modalite_list(args={"modalite": sem["modalite"]})[0]
2020-09-26 16:19:37 +02:00
modalites[m["modalite"]] = m
2021-07-09 17:47:06 +02:00
modalites = list(modalites.values())
2020-09-26 16:19:37 +02:00
modalites.sort(key=lambda x: x["numero"])
return modalites
def group_sems_by_modalite(sems):
2020-09-26 16:19:37 +02:00
"""Given the list of fromsemestre, group them by modalite,
sorted in each one by semestre id and date
"""
2021-01-28 23:02:18 +01:00
sems_by_mod = scu.DictDefault(defaultvalue=[])
modalites = list_formsemestres_modalites(sems)
2020-09-26 16:19:37 +02:00
for modalite in modalites:
for sem in sems:
if sem["semestre_id"] < 0: # formations en un semestre
sem["sortkey"] = (-100 * sem["semestre_id"], sem["dateord"])
else:
sem["sortkey"] = (sem["semestre_id"], sem["dateord"])
if sem["modalite"] == modalite["modalite"]:
sems_by_mod[modalite["modalite"]].append(sem)
# tri dans chaque modalité par indice de semestre et date debut
for modalite in modalites:
sems_by_mod[modalite["modalite"]].sort(key=lambda x: x["sortkey"])
return sems_by_mod, modalites
# ------ Low level interface (database) ------
2021-01-28 23:02:18 +01:00
_modaliteEditor = ndb.EditableTable(
2020-09-26 16:19:37 +02:00
"notes_form_modalites",
"form_modalite_id",
("form_modalite_id", "modalite", "titre", "numero"),
sortkey="numero",
2021-01-28 23:02:18 +01:00
output_formators={"numero": ndb.int_null_is_zero},
2020-09-26 16:19:37 +02:00
)
def do_modalite_list(*args, **kw):
2021-01-01 18:40:47 +01:00
"""Liste des modalites"""
2021-06-15 13:59:56 +02:00
cnx = ndb.GetDBConnexion()
2020-09-26 16:19:37 +02:00
return _modaliteEditor.list(cnx, *args, **kw)
def do_modalite_create(args, REQUEST=None):
2020-09-26 16:19:37 +02:00
"create a modalite"
2021-06-15 13:59:56 +02:00
cnx = ndb.GetDBConnexion()
2020-09-26 16:19:37 +02:00
r = _modaliteEditor.create(cnx, args)
return r
def do_modalite_delete(oid, REQUEST=None):
2020-09-26 16:19:37 +02:00
"delete a modalite"
2021-06-15 13:59:56 +02:00
cnx = ndb.GetDBConnexion()
2020-09-26 16:19:37 +02:00
log("do_modalite_delete: form_modalite_id=%s" % oid)
_modaliteEditor.delete(cnx, oid)
def do_modalite_edit(*args, **kw): # unused
2020-09-26 16:19:37 +02:00
"edit a modalite"
2021-06-15 13:59:56 +02:00
cnx = ndb.GetDBConnexion()
2020-09-26 16:19:37 +02:00
# check
_ = do_modalite_list({"form_modalite_id": args[0]["form_modalite_id"]})[0]
2020-09-26 16:19:37 +02:00
_modaliteEditor.edit(cnx, *args, **kw)