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',))
This commit is contained in:
parent
c45cddc337
commit
4afac2a0d0
1 changed files with 9 additions and 0 deletions
|
|
@ -107,6 +107,15 @@ class CapBaseObject(object):
|
||||||
return False
|
return False
|
||||||
return True
|
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):
|
def iter_fields(self):
|
||||||
"""
|
"""
|
||||||
Iterate on the FIELDS keys and values.
|
Iterate on the FIELDS keys and values.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue