From 27af8f31c0d7f424b244200efdc66d216e6b95fe Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sun, 23 Mar 2014 20:36:31 +0100 Subject: [PATCH] [attributs] typage des articles comme des dict --- attributs.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/attributs.py b/attributs.py index a7e36b3..cf7f212 100644 --- a/attributs.py +++ b/attributs.py @@ -1459,10 +1459,21 @@ class article(Attr): category = 'facture' can_modify = [cableur, nounou, tresorier] ldap_name = "article" + python_type = dict + + python_type_keys = ['code', 'designation', 'nombre', 'pu'] def parse_value(self, article): - art_code, art_designation, art_nombre, art_pu = article.split('~~') - now = time.time() + if isinstance(article, self.python_type): + for key in self.python_type_keys: + if key not in article: + raise ValueError("Un article devrait avoir '%s'" % key) + art_code = article['code'] + art_designation = article['designation'] + art_nombre = article['nombre'] + art_pu = article['pu'] + else: + art_code, art_designation, art_nombre, art_pu = article.split('~~') self.value = { 'code' : art_code, # code de l'article (SOLDE, FRAIS, ...) 'designation' : art_designation, 'nombre' : art_nombre,# nombre d'article @@ -1476,7 +1487,7 @@ class article(Attr): return self.value.__getitem__(attr) def __setitem__(self, attr, values): - if attr in ['code', 'designation', 'nombre', 'pu']: + if attr in self.python_type_keys: ret = self.value.__setitem__(attr, values) self.parse_value(unicode(self)) return ret