enhancement of load detection of fields

This commit is contained in:
Romain Bignon 2010-08-14 21:50:31 +02:00
commit b354f8d3a7
4 changed files with 35 additions and 13 deletions

View file

@ -62,7 +62,30 @@ class CapBaseObject(object):
self.id = id
self.backend = backend
def __iscomplete__(self):
"""
Return True if the object is completed.
It is usefull when the object is a field of an other object which is
going to be filled.
The default behavior is to iter on fields (with iter_fields) and if
a field is NotLoaded, return False.
"""
for key, value in self.iter_fields():
if value is NotLoaded:
return False
return True
def iter_fields(self):
"""
Iterate on the FIELDS keys and values.
Can be overloaded to iterate on other things.
@return [iter(key,value)] iterator on key, value
"""
if self.FIELDS is None:
for key, value in iter_fields(self):
if key != 'backend':

View file

@ -33,9 +33,10 @@ class ProfileNode(object):
self.sufix = sufix
self.flags = flags
class ContactPhoto(object):
class ContactPhoto(CapBaseObject):
def __init__(self, name):
self.name = name
CapBaseObject.__init__(self, name)
self.name = name #useless, but keep compatibility
self.url = u''
self.data = ''
self.thumbnail_url = u''

View file

@ -22,7 +22,7 @@ from .base import IBaseCap, NotLoaded, CapBaseObject
__all__ = ['BaseVideo', 'ICapVideo']
class VideoThumbnail(object):
class VideoThumbnail(CapBaseObject):
def __init__(self, url):
self.url = url.replace(' ', '%20')
self.data = NotLoaded