From 4afac2a0d06f9e421cd8b19954b3d0a7b8c2a1e2 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Mon, 12 Mar 2012 13:42:00 +0100 Subject: [PATCH] add method CapBaseObject.set_empty_fields() This method can be used to fill all empty fields with the same value. A field is empty when is value is None, NotLoaded or NotAvailable. Example: # It will be impossible to get all empty fields, except # of 'url' (with a call to fillobj()) video.set_empty_fields(NotAvailable, ('url',)) --- weboob/capabilities/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/weboob/capabilities/base.py b/weboob/capabilities/base.py index 020308d0..3a7e76c8 100644 --- a/weboob/capabilities/base.py +++ b/weboob/capabilities/base.py @@ -107,6 +107,15 @@ class CapBaseObject(object): return False return True + def set_empty_fields(self, value, excepts=()): + """ + Set the same value on all empty fields. + """ + for key, old_value in self.iter_fields(): + if old_value in (None, NotLoaded, NotAvailable) and \ + not key in excepts: + setattr(self, key, value) + def iter_fields(self): """ Iterate on the FIELDS keys and values.