39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
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)
|