diff --git a/attributs.py b/attributs.py index 962be90..6da0033 100644 --- a/attributs.py +++ b/attributs.py @@ -39,6 +39,7 @@ import re import sys import netaddr import time +import datetime import functools import smtplib import random @@ -1010,12 +1011,26 @@ class blacklist(Attr): @crans_attribute class historique(Attr): + """Un historique est usuellement de la forme JJ/MM/AAAA HH:mm:ss, action comm""" + singlevalue = False optional = True legend = u"Historique de l'objet" category = 'info' ldap_name = "historique" + # Thanks to 20-100, on va devoir gérer deux cas + FORMAT = "%d/%m/%Y %H:%M:%S" + FORMAT_OLD = "%d/%m/%Y %H:%M" # ancien binding + + def get_datetime(self): + """Renvoie un objet datetime de la ligne correspondante""" + datepart = self.value.split(',',1)[0] + try: + return datetime.datetime.strptime(self.FORMAT, datepart) + except ValueError: + return datetime.datetime.strptime(self.FORMAT_OLD, datepart) + @crans_attribute class info(Attr): singlevalue = False diff --git a/objets.py b/objets.py index 4ea231c..c70f9ae 100644 --- a/objets.py +++ b/objets.py @@ -166,7 +166,7 @@ class CransLdapObject(object): assert isinstance(login, unicode) assert isinstance(chain, unicode) - new_line = u"%s, %s : %s" % (time.strftime("%d/%m/%Y %H:%M:%S"), login, chain) + new_line = u"%s, %s : %s" % (time.strftime(attributs.historique.FORMAT), login, chain) # Attention, le __setitem__ est surchargé, mais pas .append sur l'historique self["historique"] = self.get("historique", []) + [new_line]