[printing] Fonctions d'affichage pour les objets lc_ldap
pour le moment il n'y a qu'un support partiel pour les machines et les adherents
This commit is contained in:
parent
ad58564193
commit
1b424e5afb
4 changed files with 65 additions and 0 deletions
39
printing/templates.py
Normal file
39
printing/templates.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import sys
|
||||
sys.path.append('/usr/scripts/')
|
||||
import jinja2
|
||||
|
||||
from gestion.affich_tools import coul
|
||||
from lc_ldap import objets
|
||||
|
||||
template_path = '/usr/scripts/lc_ldap/printing/templates/'
|
||||
templateLoader = jinja2.FileSystemLoader( searchpath=["/", template_path] )
|
||||
templateEnv = jinja2.Environment( loader=templateLoader )
|
||||
templateEnv.filters['coul'] = coul
|
||||
|
||||
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]
|
||||
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]
|
||||
return templateEnv.get_template("adherent").render(params)
|
||||
|
||||
def sprint(object, limit=10):
|
||||
if isinstance(object, objets.machine):
|
||||
return machine(object, limit)
|
||||
elif isinstance(object, objets.adherent):
|
||||
return adherent(object, limit)
|
||||
else:
|
||||
return str(object)
|
Loading…
Add table
Add a link
Reference in a new issue