[attributs, ...] __getitem__ et __setitem__ pour les attibut dont la valeur est un dictionnaire
donc pour blacklist et pour article pour le moment
This commit is contained in:
parent
49709b663a
commit
aebe4613e4
3 changed files with 40 additions and 2 deletions
39
attributs.py
39
attributs.py
|
@ -999,6 +999,17 @@ class blacklist(Attr):
|
||||||
'comm' : bl_comm,
|
'comm' : bl_comm,
|
||||||
'actif' : (bl_debut == '-' or int(bl_debut) < now) and (bl_fin == '-' or int(bl_fin) > now) }
|
'actif' : (bl_debut == '-' or int(bl_debut) < now) and (bl_fin == '-' or int(bl_fin) > now) }
|
||||||
|
|
||||||
|
def __getitem__(self, attr):
|
||||||
|
return self.value.__getitem__(attr)
|
||||||
|
|
||||||
|
def __setitem__(self, attr, values):
|
||||||
|
if attr in ['debut', 'fin', 'type', 'comm']:
|
||||||
|
ret=self.value.__setitem__(attr, values)
|
||||||
|
self.parse_value(unicode(self))
|
||||||
|
return ret
|
||||||
|
else:
|
||||||
|
raise ValueError("blacklist has no %r" % attr)
|
||||||
|
|
||||||
def is_actif(self):
|
def is_actif(self):
|
||||||
return self.value['actif']
|
return self.value['actif']
|
||||||
|
|
||||||
|
@ -1227,8 +1238,36 @@ class recuPaiement(Attr):
|
||||||
|
|
||||||
@crans_attribute
|
@crans_attribute
|
||||||
class article(Attr):
|
class article(Attr):
|
||||||
|
singlevalue = False
|
||||||
|
optional = True
|
||||||
|
legend = u"Articles"
|
||||||
|
category = 'facture'
|
||||||
|
can_modify = [cableur, nounou, tresorier]
|
||||||
ldap_name = "article"
|
ldap_name = "article"
|
||||||
|
|
||||||
|
def parse_value(self, article):
|
||||||
|
art_code, art_designation, art_nombre, art_pu = article.split('~~')
|
||||||
|
now = time.time()
|
||||||
|
self.value = { 'code' : art_code, # code de l'article (SOLDE, FRAIS, ...)
|
||||||
|
'designation' : art_designation,
|
||||||
|
'nombre' : art_nombre,# nombre d'article
|
||||||
|
'pu' : art_pu, # prix à l'unité
|
||||||
|
}
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return u'%(code)s~~%(designation)s~~%(nombre)s~~%(pu)s' % self.value
|
||||||
|
|
||||||
|
def __getitem__(self, attr):
|
||||||
|
return self.value.__getitem__(attr)
|
||||||
|
|
||||||
|
def __setitem__(self, attr, values):
|
||||||
|
if attr in ['code', 'designation', 'nombre', 'pu']:
|
||||||
|
ret = self.value.__setitem__(attr, values)
|
||||||
|
self.parse_value(unicode(self))
|
||||||
|
return ret
|
||||||
|
else:
|
||||||
|
raise ValueError("article has no %r" % attr)
|
||||||
|
|
||||||
@crans_attribute
|
@crans_attribute
|
||||||
class dnsIpv6(boolAttr):
|
class dnsIpv6(boolAttr):
|
||||||
ldap_name = "dnsIpv6"
|
ldap_name = "dnsIpv6"
|
||||||
|
|
|
@ -17,7 +17,6 @@ def timeformat(t, format):
|
||||||
def blacklist(l):
|
def blacklist(l):
|
||||||
bl=[]
|
bl=[]
|
||||||
for b in l:
|
for b in l:
|
||||||
b=b.value
|
|
||||||
debut=time.strftime("%d/%m/%Y %H:%M", time.localtime(b['debut']))
|
debut=time.strftime("%d/%m/%Y %H:%M", time.localtime(b['debut']))
|
||||||
fin=time.strftime("%d/%m/%Y %H:%M", time.localtime(b['fin']))
|
fin=time.strftime("%d/%m/%Y %H:%M", time.localtime(b['fin']))
|
||||||
couleur='rouge' if b['actif'] else None
|
couleur='rouge' if b['actif'] else None
|
||||||
|
|
|
@ -109,7 +109,7 @@ def services_to_args_mail_bienvenue(x):
|
||||||
def services_to_time_blacklist(x):
|
def services_to_time_blacklist(x):
|
||||||
if isinstance(x, attributs.blacklist):
|
if isinstance(x, attributs.blacklist):
|
||||||
# Un set à au plus deux valeur : la date de début et la date de fin de la blacklist
|
# Un set à au plus deux valeur : la date de début et la date de fin de la blacklist
|
||||||
return set([(0 if x.value['debut'] == '-' else x.value['debut']), (0 if x.value['fin'] == '-' else x.value['fin'])])
|
return set([(0 if x['debut'] == '-' else x['debut']), (0 if x['fin'] == '-' else x['fin'])])
|
||||||
else:
|
else:
|
||||||
return [0]
|
return [0]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue