diff --git a/printing/templates.py b/printing/templates.py index aea47a3..f41ec88 100644 --- a/printing/templates.py +++ b/printing/templates.py @@ -1,9 +1,24 @@ #!/bin/bash /usr/scripts/python.sh # -*- coding: utf-8 -*- from gestion.affich_tools import coul, tableau +import importlib import time -import gestion.whos -import gestion.annuaires_pg +import sys +import gestion + +def try_import(lib): + if not isinstance(lib, unicode): + lib = lib.decode('utf-8') + try: + lib = importlib.import_module(lib) + except: + if sys.stdout.isatty(): + print (u"Impossible d'importer %s, c'est sans doute un problème de droits." % lib).encode('utf-8') + lib = None + return lib + +gestion.whos = try_import(u"gestion.whos") +gestion.annuaires_pg = try_import("gestion.annuaires_pg") def prise_etat(chbre): if chbre=="????": @@ -16,10 +31,17 @@ def timeformat(t, format): def blacklist(l): bl=[] for b in l: - debut=time.strftime("%d/%m/%Y %H:%M", time.localtime(b['debut'])) - fin=time.strftime("%d/%m/%Y %H:%M", time.localtime(b['fin'])) + debut=b['debut'] if b['debut'] == '-' else time.strftime("%d/%m/%Y %H:%M", time.localtime(b['debut'])) + fin=b['fin'] if b['fin'] == '-' else 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)) + if debut != '-' and fin !='-': + bl.append(coul(u"du %s au %s : %s [%s]" % (debut, fin, b['type'], b['comm']), couleur)) + elif debut != '-': + bl.append(coul(u"À partir du %s : %s [%s]" % (debut, b['type'], b['comm']), couleur)) + elif fin != '-': + bl.append(coul(u"Jusqu'au %s : %s [%s]" % (fin, b['type'], b['comm']), couleur)) + else: + bl.append(coul(u"%s [%s]" % (b['type'], b['comm']), couleur)) return bl def split(str, *arg): @@ -82,7 +104,7 @@ def list_factures(factures): def list_adherents(adherents): return tableau([ - [a['aid'][0], + [a['aid'][0], u' '.join(unicode(i) for i in a['prenom'] + a['nom']), a['chbre'][0], coul('o', 'vert') if a.paiement_ok() else coul('n', 'rouge'), coul('o', 'vert') if a.carte_ok() else coul('n', 'rouge'), @@ -158,4 +180,4 @@ def sprint_list(list): else: ret.append("Listes d'objets de classe %s non affichage" % classe.__name__) return '\n'.join(ret) - +