ScoDoc-Lille/sco_dept_filtrage.py

85 lines
2.6 KiB
Python

# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
# Copyright (c) 1999 - 2021 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
#
##############################################################################
import re
from notes_log import log
class SemProperty:
def __init__(self, prefix):
self.index = {} # valeur : clé
self.next_key = 0
self.prefix = prefix
def get_key(self, value):
if value in self.index:
return self.index[value]
else:
self.index[value] = self.prefix + "{:02d}".format(self.next_key)
self.next_key += 1
def js(self):
returned = "\n"
for val in sorted(self.index):
returned += "%s:%s\n" % (self.index[val], val)
return returned
locked = SemProperty("A")
semestre_id = SemProperty("B")
modalite = SemProperty("B")
annee = SemProperty("C")
titre = SemProperty("D")
etapes = SemProperty("E")
def get_filtrage_html():
returned = "<!-- "
returned += locked.js()
returned += semestre_id.js()
returned += modalite.js()
returned += annee.js()
returned += titre.js()
returned += etapes.js()
returned += " -->"
return returned
def complete_sem(sems):
for row in sems:
classes = []
classes.append(locked.get_key(row["lockimg"]))
classes.append(semestre_id.get_key(row["semestre_id_n"]))
classes.append(modalite.get_key(row["modalite"]))
classes.append(annee.get_key(row["anneescolaire"]))
pattern = "<a.*>(.*)</a>"
title = re.search(pattern, row["titre_resp"]).group(1)
classes.append(titre.get_key(title))
for etapevdi in row["etapes"]:
classes.append(etapes.get_key(etapevdi.etape))
row["_css_row_class"] = " ".join([x for x in classes if x is not None])