gestClasse.py
Aller à la documentation de ce fichier.
#!/usr/bin/python
#Ce module permet de gérer des classes d'élèves. La classe
#AbstractGestClasse définit les fonctions minimales à implémenter
#pour chaque gestionnaire de classes.
#
licence={}
licence['en']="""
file gestClasse.py
this file is part of the project scolasync
Copyright (C) 2012 Georges Khaznadar <georgesk@ofset.org>
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 version3 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, see <http://www.gnu.org/licenses/>.
"""
import xml.dom.minidom, copy
class AbstractGestClasse:
def __init__(self,f):
return
def collectClasses(self):
return []
def elevesDeClasse(self, cl):
return[]
def unique_name(self, el):
return "Cette fonction est abstraite, ne l'appelez pas ainsi."
def showable_name(self,el):
return "Cette fonction est abstraite, ne l'appelez pas ainsi."
class Sconet(AbstractGestClasse):
def __init__(self, f):
AbstractGestClasse.__init__(self,f)
if type(f)==type(""):
try:
# python3 way
file=open(f, "r", encoding="iso-8859-1")
except:
# former way
file=open(f, "r")
self.donnees=xml.dom.minidom.parse(f)
self.makeCompact()
def makeCompact(self):
self.nullTexts={}
self.elementsWalk(self.donnees.documentElement, self.collectNullTexts)
for el in self.nullTexts.keys():
for e in self.nullTexts[el]:
el.removeChild(e)
def collectNullTexts(self,el):
self.nullTexts[el]=[]
for e in el.childNodes:
if e.nodeType==e.TEXT_NODE and e.data.strip()=="":
self.nullTexts[el].append(e)
def collectClasses(self):
self.classes=set()
self.elementsWalk(self.donnees.documentElement, self.collectOneClass)
return self.classes
def elevesDeClasse(self, className):
self.currentResult=[]
self.currentClassName=className
self.elementsWalk(self.donnees.documentElement, self.unIDEleveDeClasse)
ids=copy.copy(self.currentResult)
self.currentResult=[]
for i in ids:
self.currentID=i
self.elementsWalk(self.donnees.documentElement, self.eleveParID)
return copy.copy(self.currentResult)
# appends the "eleve" element to the list self.currentResult if
# @code
# self.currentID is matched
#
# @endcode
#
def eleveParID(self,el):
if el.nodeName.lower()=="eleve" and el.getAttribute("ELEVE_ID")==self.currentID:
self.currentResult.append(el)
# appends the ID of an "eleve" to self.currentResult if he belongs to
# the class self.currentClassName
# @param el an element
#
def unIDEleveDeClasse(self, el):
if el.nodeName.lower()=="structures_eleve":
structures=el.getElementsByTagName("STRUCTURE")
if len (structures) > 0:
if structures[0].getElementsByTagName("TYPE_STRUCTURE")[0].firstChild.data=="D":
if structures[0].getElementsByTagName("CODE_STRUCTURE")[0].firstChild.data==self.currentClassName:
idEleve=el.getAttribute("ELEVE_ID")
self.currentResult.append(idEleve)
def collectOneClass(self,el):
if el.nodeName.lower()=="structure":
if el.getElementsByTagName("TYPE_STRUCTURE")[0].firstChild.data=="D":
self.classes.add(el.getElementsByTagName("CODE_STRUCTURE")[0].firstChild.data)
def unique_name(self, el, fields=["NOM", "PRENOM"]):
items=[]
for f in fields:
items.append(el.getElementsByTagName(f)[0].firstChild.data)
items.append(el.getAttribute("ELEVE_ID"))
return "_".join(items)
def showable_name(self,el, fields=["NOM", "PRENOM"]):
items=[]
for f in fields:
items.append(el.getElementsByTagName(f)[0].firstChild.data)
return " ".join(items)
# implemente un parcour des éléments d'un arbre, pour y appliquer
# une procédure
# @param el un élément
# @param proc la procédure à appliquer (paramètres : l'élément)
#
def elementsWalk(self, el, proc):
proc(el)
for e in el.childNodes:
self.elementsWalk(e, proc)
def __str__(self):
return self.donnees.toprettyxml(indent=" ",encoding="utf-8")
src.gestClasse.Sconet.collectNullTexts
def collectNullTexts(self, el)
Definition: gestClasse.py:100
src.gestClasse.Sconet.currentID
currentID
Definition: gestClasse.py:125
src.gestClasse.Sconet.elevesDeClasse
def elevesDeClasse(self, className)
Definition: gestClasse.py:118
src.gestClasse.AbstractGestClasse.collectClasses
def collectClasses(self)
Definition: gestClasse.py:45
src.gestClasse.Sconet.collectOneClass
def collectOneClass(self, el)
adds one class name to the set self.classes
Definition: gestClasse.py:158
src.gestClasse.Sconet.makeCompact
def makeCompact(self)
removes useless thext nodes containing only spaces.
Definition: gestClasse.py:93
src.gestClasse.AbstractGestClasse.__init__
def __init__(self, f)
le constructeur
Definition: gestClasse.py:39
src.gestClasse.AbstractGestClasse.showable_name
def showable_name(self, el)
Definition: gestClasse.py:66
src.gestClasse.Sconet.classes
classes
Definition: gestClasse.py:110
src.gestClasse.AbstractGestClasse
Definition: gestClasse.py:32
src.gestClasse.Sconet
Une classe pour travailler avec des données Sconet.
Definition: gestClasse.py:72
src.gestClasse.Sconet.eleveParID
def eleveParID(self, el)
Definition: gestClasse.py:136
src.gestClasse.Sconet.collectClasses
def collectClasses(self)
Definition: gestClasse.py:109
src.gestClasse.Sconet.__str__
def __str__(self)
Definition: gestClasse.py:200
src.gestClasse.Sconet.unique_name
def unique_name(self, el, fields=["NOM", "PRENOM"])
a unique name for an "eleve", based on a few fields and on the ID
Definition: gestClasse.py:170
src.gestClasse.Sconet.__init__
def __init__(self, f)
Le constructeur.
Definition: gestClasse.py:78
src.gestClasse.Sconet.elementsWalk
def elementsWalk(self, el, proc)
Definition: gestClasse.py:195
src.gestClasse.Sconet.unIDEleveDeClasse
def unIDEleveDeClasse(self, el)
Definition: gestClasse.py:145
src.gestClasse.AbstractGestClasse.elevesDeClasse
def elevesDeClasse(self, cl)
Definition: gestClasse.py:52
src.gestClasse.Sconet.showable_name
def showable_name(self, el, fields=["NOM", "PRENOM"])
Definition: gestClasse.py:182
src.gestClasse.Sconet.nullTexts
nullTexts
Definition: gestClasse.py:94
src.gestClasse.Sconet.currentResult
currentResult
Definition: gestClasse.py:119
src.gestClasse.Sconet.donnees
donnees
Definition: gestClasse.py:87
src.gestClasse.AbstractGestClasse.unique_name
def unique_name(self, el)
Definition: gestClasse.py:59
src.gestClasse.Sconet.currentClassName
currentClassName
Definition: gestClasse.py:120