102 lines
3.4 KiB
Python
102 lines
3.4 KiB
Python
#!/bin/bash /usr/scripts/python.sh
|
|
# -*- coding: utf-8 -*-
|
|
from gestion.affich_tools import coul
|
|
import time
|
|
|
|
import gestion.whos
|
|
import gestion.annuaires_pg
|
|
|
|
def prise_etat(chbre):
|
|
if chbre=="????":
|
|
return coul("Chambre invalide", "violet")
|
|
return gestion.whos.prise_etat(chbre)[0]
|
|
|
|
def timeformat(t, format):
|
|
return time.strftime(format, time.localtime(t))
|
|
|
|
def blacklist(l):
|
|
bl=[]
|
|
for b in l:
|
|
b=b.value
|
|
debut=time.strftime("%d/%m/%Y %H:%M", time.localtime(b['debut']))
|
|
fin=time.strftime("%d/%m/%Y %H:%M", time.localtime(b['fin']))
|
|
couleur='rouge' if b['actif'] else None
|
|
bl.append(coul("du %s au %s : %s [%s]" % (debut, fin, b['type'], b['comm']), couleur))
|
|
return bl
|
|
|
|
def split(str, *arg):
|
|
return str.split(*arg)
|
|
|
|
def telephone(l):
|
|
tel=[]
|
|
for t in l:
|
|
if len(str(t)) == 10:
|
|
tel.append("%c%c.%c%c.%c%c.%c%c.%c%c" % tuple(map(ord, str(t))))
|
|
else:
|
|
if t.startswith("00"):
|
|
t="+%s" % t[2:]
|
|
tel.append(t)
|
|
return tel
|
|
|
|
templateEnv=None
|
|
def template():
|
|
global templateEnv
|
|
if not templateEnv:
|
|
# un import paresseux, comme ça, pas la peine d'installer jinja2 sur les machines où il n'y en a pas besoin
|
|
import jinja2
|
|
template_path = '/usr/scripts/lc_ldap/printing/templates/'
|
|
templateLoader = jinja2.FileSystemLoader( searchpath=["/", template_path] )
|
|
templateEnv = jinja2.Environment( loader=templateLoader, trim_blocks=True )
|
|
templateEnv.filters['coul'] = coul
|
|
templateEnv.filters['blacklist'] = blacklist
|
|
templateEnv.filters['prise_etat'] = prise_etat
|
|
templateEnv.filters['timeformat'] = timeformat
|
|
templateEnv.filters['split'] = split
|
|
templateEnv.filters['telephone'] = telephone
|
|
return templateEnv
|
|
|
|
def machine(machine, params):
|
|
params['o']=machine
|
|
return template().get_template("machine").render(params)
|
|
|
|
def proprio(proprio, params):
|
|
params['o']=proprio
|
|
etat_administratif=[]
|
|
if proprio.paiement_ok() and proprio.carte_ok():
|
|
etat_administratif.append(coul(u"à jour", "vert"))
|
|
if not proprio.carte_ok():
|
|
etat_administratif.append(coul(u"manque carte d'étudiant", "violet"))
|
|
if not proprio.paiement_ok():
|
|
etat_administratif.append(coul(u"cotisation non réglée", "violet"))
|
|
params['etat_administratif']=etat_administratif
|
|
if proprio["chbre"][0].value not in ["????", "EXT"]:
|
|
params['brassage'] = coul("Cr@ns", "bleu") if gestion.annuaires_pg.is_crans(proprio["chbre"][0].value[0], proprio["chbre"][0].value[1:]) else coul("CROUS", "jaune")
|
|
return params
|
|
|
|
def club(club, params):
|
|
params=proprio(club, params)
|
|
return template().get_template("club").render(params)
|
|
|
|
def adherent(adherent, params):
|
|
params=proprio(adherent, params)
|
|
return template().get_template("adherent").render(params)
|
|
|
|
def facture(facture, params):
|
|
params['o']=facture
|
|
return template().get_template("facture").render(params)
|
|
|
|
def sprint(object, limit=5):
|
|
params={'limit':limit}
|
|
from lc_ldap import objets
|
|
if isinstance(object, objets.machine):
|
|
return machine(object, params)
|
|
elif isinstance(object, objets.adherent):
|
|
return adherent(object, params)
|
|
elif isinstance(object, objets.club):
|
|
return club(object, params)
|
|
elif isinstance(object, objets.facture):
|
|
return facture(object, params)
|
|
else:
|
|
return str(object)
|
|
|
|
|