2020-09-26 16:19:37 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-01-02 13:16:27 +01:00
|
|
|
# Copyright (c) 1999 - 2023 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@gmail.com
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
Rapport (table) avec dernier semestre fréquenté et débouché de chaque étudiant
|
|
|
|
"""
|
2021-08-10 17:12:10 +02:00
|
|
|
import http
|
2021-09-18 10:10:02 +02:00
|
|
|
from flask import url_for, g, request
|
2021-07-11 17:37:12 +02:00
|
|
|
|
2022-02-13 23:53:11 +01:00
|
|
|
from app import log
|
|
|
|
from app.comp import res_sem
|
2022-03-27 22:25:00 +02:00
|
|
|
from app.comp.res_compat import NotesTableCompat
|
2022-02-13 23:53:11 +01:00
|
|
|
from app.models import FormSemestre
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.sco_utils as scu
|
|
|
|
import app.scodoc.notesdb as ndb
|
|
|
|
from app.scodoc.sco_exceptions import AccessDenied
|
|
|
|
from app.scodoc.scolog import logdb
|
|
|
|
from app.scodoc.gen_tables import GenTable
|
2021-07-11 23:11:10 +02:00
|
|
|
from app.scodoc import safehtml
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import html_sco_header
|
|
|
|
from app.scodoc import sco_permissions_check
|
|
|
|
from app.scodoc import sco_preferences
|
|
|
|
from app.scodoc import sco_tag_module
|
|
|
|
from app.scodoc import sco_etud
|
2021-08-21 17:07:44 +02:00
|
|
|
import sco_version
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def report_debouche_date(start_year=None, format="html"):
|
2021-09-30 09:37:18 +02:00
|
|
|
"""Rapport (table) pour les débouchés des étudiants sortis
|
|
|
|
à partir de l'année indiquée.
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
if not start_year:
|
2021-09-30 09:37:18 +02:00
|
|
|
return report_debouche_ask_date("Année de début de la recherche")
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
start_year = int(start_year)
|
|
|
|
except ValueError:
|
|
|
|
return report_debouche_ask_date(
|
|
|
|
"Année invalide. Année de début de la recherche"
|
|
|
|
)
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
if format == "xls":
|
|
|
|
keep_numeric = True # pas de conversion des notes en strings
|
|
|
|
else:
|
|
|
|
keep_numeric = False
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
etudids = get_etudids_with_debouche(start_year)
|
|
|
|
tab = table_debouche_etudids(etudids, keep_numeric=keep_numeric)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2020-12-24 00:07:17 +01:00
|
|
|
tab.filename = scu.make_filename("debouche_scodoc_%s" % start_year)
|
2021-08-21 17:07:44 +02:00
|
|
|
tab.origin = (
|
|
|
|
"Généré par %s le " % sco_version.SCONAME + scu.timedate_human_repr() + ""
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
tab.caption = "Récapitulatif débouchés à partir du 1/1/%s." % start_year
|
2021-09-18 10:10:02 +02:00
|
|
|
tab.base_url = "%s?start_year=%s" % (request.base_url, start_year)
|
2020-09-26 16:19:37 +02:00
|
|
|
return tab.make_page(
|
|
|
|
title="""<h2 class="formsemestre">Débouchés étudiants </h2>""",
|
|
|
|
init_qtip=True,
|
|
|
|
javascripts=["js/etud_info.js"],
|
|
|
|
format=format,
|
|
|
|
with_html_headers=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def get_etudids_with_debouche(start_year):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Liste des etudids de tous les semestres terminant
|
|
|
|
à partir du 1er janvier de start_year
|
|
|
|
et ayant un 'debouche' renseigné.
|
|
|
|
"""
|
|
|
|
start_date = str(start_year) + "-01-01"
|
|
|
|
# Recupere tous les etudid avec un debouché renseigné et une inscription dans un semestre
|
|
|
|
# posterieur à la date de depart:
|
2021-07-28 17:03:54 +02:00
|
|
|
# r = ndb.SimpleDictFetch(
|
2020-09-26 16:19:37 +02:00
|
|
|
# """SELECT DISTINCT i.etudid
|
|
|
|
# FROM notes_formsemestre_inscription i, admissions adm, notes_formsemestre s
|
|
|
|
# WHERE adm.debouche is not NULL
|
|
|
|
# AND i.etudid = adm.etudid AND i.formsemestre_id = s.formsemestre_id
|
|
|
|
# AND s.date_fin >= %(start_date)s
|
|
|
|
# """,
|
|
|
|
# {'start_date' : start_date })
|
|
|
|
|
2021-06-15 13:59:56 +02:00
|
|
|
r = ndb.SimpleDictFetch(
|
2020-09-26 16:19:37 +02:00
|
|
|
"""SELECT DISTINCT i.etudid
|
2021-08-08 17:38:46 +02:00
|
|
|
FROM notes_formsemestre_inscription i, notes_formsemestre s, itemsuivi it
|
|
|
|
WHERE i.etudid = it.etudid
|
|
|
|
AND i.formsemestre_id = s.id AND s.date_fin >= %(start_date)s
|
2021-09-30 09:37:18 +02:00
|
|
|
AND s.dept_id = %(dept_id)s
|
2021-08-08 17:38:46 +02:00
|
|
|
""",
|
2021-09-30 09:37:18 +02:00
|
|
|
{"start_date": start_date, "dept_id": g.scodoc_dept_id},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
return [x["etudid"] for x in r]
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def table_debouche_etudids(etudids, keep_numeric=True):
|
2022-02-13 23:53:11 +01:00
|
|
|
"""Rapport pour ces étudiants"""
|
2020-09-26 16:19:37 +02:00
|
|
|
L = []
|
|
|
|
for etudid in etudids:
|
2021-08-22 13:24:36 +02:00
|
|
|
etud = sco_etud.get_etud_info(filled=True, etudid=etudid)[0]
|
2020-09-26 16:19:37 +02:00
|
|
|
# retrouve le "dernier" semestre (au sens de la date de fin)
|
|
|
|
sems = etud["sems"]
|
2021-07-13 16:39:41 +02:00
|
|
|
es = [(s["date_fin_iso"], i) for i, s in enumerate(sems)]
|
2020-09-26 16:19:37 +02:00
|
|
|
imax = max(es)[1]
|
|
|
|
last_sem = sems[imax]
|
2022-02-13 23:53:11 +01:00
|
|
|
formsemestre = FormSemestre.query.get_or_404(last_sem["formsemestre_id"])
|
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
2020-09-26 16:19:37 +02:00
|
|
|
row = {
|
|
|
|
"etudid": etudid,
|
2021-02-13 17:28:55 +01:00
|
|
|
"civilite": etud["civilite"],
|
2020-09-26 16:19:37 +02:00
|
|
|
"nom": etud["nom"],
|
|
|
|
"prenom": etud["prenom"],
|
2021-07-11 17:37:12 +02:00
|
|
|
"_nom_target": url_for(
|
|
|
|
"scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid
|
|
|
|
),
|
|
|
|
"_prenom_target": url_for(
|
|
|
|
"scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid
|
|
|
|
),
|
2020-09-26 16:19:37 +02:00
|
|
|
"_nom_td_attrs": 'id="%s" class="etudinfo"' % (etud["etudid"]),
|
|
|
|
# 'debouche' : etud['debouche'],
|
2020-12-24 00:07:17 +01:00
|
|
|
"moy": scu.fmt_note(nt.get_etud_moy_gen(etudid), keep_numeric=keep_numeric),
|
2020-09-26 16:19:37 +02:00
|
|
|
"rang": nt.get_etud_rang(etudid),
|
|
|
|
"effectif": len(nt.T),
|
|
|
|
"semestre_id": last_sem["semestre_id"],
|
|
|
|
"semestre": last_sem["titre"],
|
|
|
|
"date_debut": last_sem["date_debut"],
|
|
|
|
"date_fin": last_sem["date_fin"],
|
|
|
|
"periode": "%s - %s" % (last_sem["mois_debut"], last_sem["mois_fin"]),
|
|
|
|
"sem_ident": "%s %s"
|
|
|
|
% (last_sem["date_debut_iso"], last_sem["titre"]), # utile pour tris
|
|
|
|
}
|
|
|
|
|
|
|
|
# recherche des débouchés
|
2021-08-21 00:24:51 +02:00
|
|
|
debouche = itemsuivi_list_etud(etudid) # liste de plusieurs items
|
2020-09-26 16:19:37 +02:00
|
|
|
if debouche:
|
|
|
|
row["debouche"] = "<br>".join(
|
|
|
|
[
|
|
|
|
str(it["item_date"])
|
|
|
|
+ " : "
|
|
|
|
+ it["situation"]
|
|
|
|
+ " <i>"
|
|
|
|
+ it["tags"]
|
|
|
|
+ "</i>"
|
|
|
|
for it in debouche
|
|
|
|
]
|
|
|
|
) #
|
|
|
|
else:
|
|
|
|
row["debouche"] = "non renseigné"
|
|
|
|
L.append(row)
|
|
|
|
L.sort(key=lambda x: x["sem_ident"])
|
|
|
|
|
|
|
|
titles = {
|
2021-02-13 17:28:55 +01:00
|
|
|
"civilite": "",
|
2020-09-26 16:19:37 +02:00
|
|
|
"nom": "Nom",
|
|
|
|
"prenom": "Prénom",
|
|
|
|
"semestre": "Dernier semestre",
|
|
|
|
"semestre_id": "S",
|
|
|
|
"periode": "Dates",
|
|
|
|
"moy": "Moyenne",
|
|
|
|
"rang": "Rang",
|
|
|
|
"effectif": "Eff.",
|
|
|
|
"debouche": "Débouché",
|
|
|
|
}
|
|
|
|
tab = GenTable(
|
|
|
|
columns_ids=(
|
|
|
|
"semestre",
|
|
|
|
"semestre_id",
|
|
|
|
"periode",
|
2021-02-13 17:28:55 +01:00
|
|
|
"civilite",
|
2020-09-26 16:19:37 +02:00
|
|
|
"nom",
|
|
|
|
"prenom",
|
|
|
|
"moy",
|
|
|
|
"rang",
|
|
|
|
"effectif",
|
|
|
|
"debouche",
|
|
|
|
),
|
|
|
|
titles=titles,
|
|
|
|
rows=L,
|
|
|
|
# html_col_width='4em',
|
|
|
|
html_sortable=True,
|
|
|
|
html_class="table_leftalign table_listegroupe",
|
2021-07-28 17:03:54 +02:00
|
|
|
preferences=sco_preferences.SemPreferences(),
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
return tab
|
|
|
|
|
|
|
|
|
2021-09-30 09:37:18 +02:00
|
|
|
def report_debouche_ask_date(msg: str) -> str:
|
2020-12-24 00:07:17 +01:00
|
|
|
"""Formulaire demande date départ"""
|
2021-09-30 09:37:18 +02:00
|
|
|
return f"""{html_sco_header.sco_header()}
|
|
|
|
<h2>Table des débouchés des étudiants</h2>
|
|
|
|
<form method="GET">
|
|
|
|
{msg}
|
|
|
|
<input type="text" name="start_year" value="" size=10/>
|
|
|
|
</form>
|
|
|
|
{html_sco_header.sco_footer()}
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Nouveau suivi des etudiants (nov 2017)
|
|
|
|
#
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2021-06-15 13:59:56 +02:00
|
|
|
_itemsuiviEditor = ndb.EditableTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
"itemsuivi",
|
|
|
|
"itemsuivi_id",
|
|
|
|
("itemsuivi_id", "etudid", "item_date", "situation"),
|
|
|
|
sortkey="item_date desc",
|
|
|
|
convert_null_outputs_to_empty=True,
|
2020-12-24 00:07:17 +01:00
|
|
|
output_formators={
|
2021-07-11 22:00:41 +02:00
|
|
|
"situation": safehtml.html_to_safe_html,
|
2021-06-15 13:59:56 +02:00
|
|
|
"item_date": ndb.DateISOtoDMY,
|
2020-12-24 00:07:17 +01:00
|
|
|
},
|
2021-06-15 13:59:56 +02:00
|
|
|
input_formators={"item_date": ndb.DateDMYtoISO},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
_itemsuivi_create = _itemsuiviEditor.create
|
|
|
|
_itemsuivi_delete = _itemsuiviEditor.delete
|
|
|
|
_itemsuivi_list = _itemsuiviEditor.list
|
|
|
|
_itemsuivi_edit = _itemsuiviEditor.edit
|
|
|
|
|
|
|
|
|
|
|
|
class ItemSuiviTag(sco_tag_module.ScoTag):
|
2020-12-24 00:07:17 +01:00
|
|
|
"""Les tags sur les items"""
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
tag_table = "itemsuivi_tags" # table (tag_id, title)
|
|
|
|
assoc_table = "itemsuivi_tags_assoc" # table (tag_id, object_id)
|
|
|
|
obj_colname = "itemsuivi_id" # column name for object_id in assoc_table
|
|
|
|
|
|
|
|
|
|
|
|
def itemsuivi_get(cnx, itemsuivi_id, ignore_errors=False):
|
|
|
|
"""get an item"""
|
|
|
|
items = _itemsuivi_list(cnx, {"itemsuivi_id": itemsuivi_id})
|
|
|
|
if items:
|
|
|
|
return items[0]
|
|
|
|
elif not ignore_errors:
|
|
|
|
raise ValueError("invalid itemsuivi_id")
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def itemsuivi_suppress(itemsuivi_id):
|
2020-12-24 00:07:17 +01:00
|
|
|
"""Suppression d'un item"""
|
2021-07-29 16:31:15 +02:00
|
|
|
if not sco_permissions_check.can_edit_suivi():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-09-26 16:19:37 +02:00
|
|
|
item = itemsuivi_get(cnx, itemsuivi_id, ignore_errors=True)
|
|
|
|
if item:
|
|
|
|
_itemsuivi_delete(cnx, itemsuivi_id)
|
2021-07-31 18:01:10 +02:00
|
|
|
logdb(cnx, method="itemsuivi_suppress", etudid=item["etudid"])
|
2020-09-26 16:19:37 +02:00
|
|
|
log("suppressed itemsuivi %s" % (itemsuivi_id,))
|
2021-09-21 13:36:56 +02:00
|
|
|
return ("", 204)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def itemsuivi_create(etudid, item_date=None, situation="", format=None):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Creation d'un item"""
|
2021-07-29 16:31:15 +02:00
|
|
|
if not sco_permissions_check.can_edit_suivi():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-09-26 16:19:37 +02:00
|
|
|
itemsuivi_id = _itemsuivi_create(
|
|
|
|
cnx, args={"etudid": etudid, "item_date": item_date, "situation": situation}
|
|
|
|
)
|
2021-07-31 18:01:10 +02:00
|
|
|
logdb(cnx, method="itemsuivi_create", etudid=etudid)
|
2020-09-26 16:19:37 +02:00
|
|
|
log("created itemsuivi %s for %s" % (itemsuivi_id, etudid))
|
|
|
|
item = itemsuivi_get(cnx, itemsuivi_id)
|
|
|
|
if format == "json":
|
2021-09-21 13:36:56 +02:00
|
|
|
return scu.sendJSON(item)
|
2020-09-26 16:19:37 +02:00
|
|
|
return item
|
|
|
|
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def itemsuivi_set_date(itemsuivi_id, item_date):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""set item date
|
|
|
|
item_date is a string dd/mm/yyyy
|
|
|
|
"""
|
2021-07-29 16:31:15 +02:00
|
|
|
if not sco_permissions_check.can_edit_suivi():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
# log('itemsuivi_set_date %s : %s' % (itemsuivi_id, item_date))
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-09-26 16:19:37 +02:00
|
|
|
item = itemsuivi_get(cnx, itemsuivi_id)
|
|
|
|
item["item_date"] = item_date
|
|
|
|
_itemsuivi_edit(cnx, item)
|
2021-09-21 13:36:56 +02:00
|
|
|
return ("", 204)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def itemsuivi_set_situation(object, value):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""set situation"""
|
2021-07-29 16:31:15 +02:00
|
|
|
if not sco_permissions_check.can_edit_suivi():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
itemsuivi_id = object
|
|
|
|
situation = value.strip("-_ \t")
|
|
|
|
# log('itemsuivi_set_situation %s : %s' % (itemsuivi_id, situation))
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-09-26 16:19:37 +02:00
|
|
|
item = itemsuivi_get(cnx, itemsuivi_id)
|
|
|
|
item["situation"] = situation
|
|
|
|
_itemsuivi_edit(cnx, item)
|
2020-12-24 00:07:17 +01:00
|
|
|
return situation or scu.IT_SITUATION_MISSING_STR
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def itemsuivi_list_etud(etudid, format=None):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Liste des items pour cet étudiant, avec tags"""
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-09-26 16:19:37 +02:00
|
|
|
items = _itemsuivi_list(cnx, {"etudid": etudid})
|
|
|
|
for it in items:
|
2021-08-21 00:24:51 +02:00
|
|
|
it["tags"] = ", ".join(itemsuivi_tag_list(it["itemsuivi_id"]))
|
2020-09-26 16:19:37 +02:00
|
|
|
if format == "json":
|
2021-09-21 13:36:56 +02:00
|
|
|
return scu.sendJSON(items)
|
2020-09-26 16:19:37 +02:00
|
|
|
return items
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def itemsuivi_tag_list(itemsuivi_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""les noms de tags associés à cet item"""
|
2021-06-15 13:59:56 +02:00
|
|
|
r = ndb.SimpleDictFetch(
|
2020-09-26 16:19:37 +02:00
|
|
|
"""SELECT t.title
|
|
|
|
FROM itemsuivi_tags_assoc a, itemsuivi_tags t
|
2021-08-08 17:38:46 +02:00
|
|
|
WHERE a.tag_id = t.id
|
2020-09-26 16:19:37 +02:00
|
|
|
AND a.itemsuivi_id = %(itemsuivi_id)s
|
|
|
|
""",
|
|
|
|
{"itemsuivi_id": itemsuivi_id},
|
|
|
|
)
|
|
|
|
return [x["title"] for x in r]
|
|
|
|
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def itemsuivi_tag_search(term):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""List all used tag names (for auto-completion)"""
|
|
|
|
# restrict charset to avoid injections
|
2021-07-12 15:13:10 +02:00
|
|
|
if not scu.ALPHANUM_EXP.match(term):
|
2020-09-26 16:19:37 +02:00
|
|
|
data = []
|
|
|
|
else:
|
2021-06-15 13:59:56 +02:00
|
|
|
r = ndb.SimpleDictFetch(
|
2021-08-29 21:21:41 +02:00
|
|
|
"SELECT title FROM itemsuivi_tags WHERE title LIKE %(term)s AND dept_id=%(dept_id)s",
|
|
|
|
{
|
|
|
|
"term": term + "%",
|
|
|
|
"dept_id": g.scodoc_dept_id,
|
|
|
|
},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
data = [x["title"] for x in r]
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
return scu.sendJSON(data)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def itemsuivi_tag_set(itemsuivi_id="", taglist=None):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""taglist may either be:
|
|
|
|
a string with tag names separated by commas ("un;deux")
|
|
|
|
or a list of strings (["un", "deux"])
|
|
|
|
"""
|
2021-07-29 16:31:15 +02:00
|
|
|
if not sco_permissions_check.can_edit_suivi():
|
2020-09-26 16:19:37 +02:00
|
|
|
raise AccessDenied("Vous n'avez pas le droit d'effectuer cette opération !")
|
|
|
|
if not taglist:
|
|
|
|
taglist = []
|
2021-07-11 18:18:44 +02:00
|
|
|
elif isinstance(taglist, str):
|
2020-09-26 16:19:37 +02:00
|
|
|
taglist = taglist.split(",")
|
|
|
|
taglist = [t.strip() for t in taglist]
|
|
|
|
# log('itemsuivi_tag_set: itemsuivi_id=%s taglist=%s' % (itemsuivi_id, taglist))
|
|
|
|
# Sanity check:
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-12-24 00:07:17 +01:00
|
|
|
_ = itemsuivi_get(cnx, itemsuivi_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
newtags = set(taglist)
|
2021-08-21 00:24:51 +02:00
|
|
|
oldtags = set(itemsuivi_tag_list(itemsuivi_id))
|
2020-09-26 16:19:37 +02:00
|
|
|
to_del = oldtags - newtags
|
|
|
|
to_add = newtags - oldtags
|
|
|
|
|
|
|
|
# should be atomic, but it's not.
|
|
|
|
for tagname in to_add:
|
2021-08-21 00:24:51 +02:00
|
|
|
t = ItemSuiviTag(tagname, object_id=itemsuivi_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
for tagname in to_del:
|
2021-08-21 00:24:51 +02:00
|
|
|
t = ItemSuiviTag(tagname)
|
2020-09-26 16:19:37 +02:00
|
|
|
t.remove_tag_from_object(itemsuivi_id)
|
2021-08-10 17:12:10 +02:00
|
|
|
return "", http.HTTPStatus.NO_CONTENT
|