[printing] Club, adherent, machines affichable de façon plus exhaustive

This commit is contained in:
Valentin Samir 2013-11-20 00:33:29 +01:00
parent 1b424e5afb
commit 702f941469
8 changed files with 124 additions and 45 deletions

View file

@ -1,39 +1,79 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.path.append('/usr/scripts/')
import jinja2
from gestion.affich_tools import coul
from lc_ldap import objets
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)
template_path = '/usr/scripts/lc_ldap/printing/templates/'
templateLoader = jinja2.FileSystemLoader( searchpath=["/", template_path] )
templateEnv = jinja2.Environment( loader=templateLoader )
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
def machine(machine, limit):
params={}
params.update(machine.attrs)
params['proprio']=machine.proprio().attrs
if limit:
for attr in ['historique', 'blacklist']:
if params.get(attr, []) and len(params[attr])>limit:
params[attr]=params[attr][0:limit]
def machine(machine, params):
params['o']=machine
return templateEnv.get_template("machine").render(params)
def adherent(adherent, limit):
params={}
params.update(adherent.attrs)
params['etat']=adherent.paiement_ok()
if limit:
for attr in ['historique', 'blacklist']:
if params.get(attr, []) and len(params[attr])>limit:
params[attr]=params[attr][0:limit]
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 templateEnv.get_template("club").render(params)
def adherent(adherent, params):
params=proprio(adherent, params)
return templateEnv.get_template("adherent").render(params)
def sprint(object, limit=10):
def sprint(object, limit=5):
params={'limit':limit}
if isinstance(object, objets.machine):
return machine(object, limit)
return machine(object, params)
elif isinstance(object, objets.adherent):
return adherent(object, limit)
return adherent(object, params)
elif isinstance(object, objets.club):
return club(object, params)
else:
return str(object)