improvement of profiles in contacts
This commit is contained in:
parent
a235e995d6
commit
47a5c8028e
5 changed files with 112 additions and 44 deletions
|
|
@ -21,6 +21,15 @@ from .cap import ICap
|
|||
|
||||
__all__ = ['ICapContact', 'Contact']
|
||||
|
||||
class ProfileNode(object):
|
||||
HEAD = 0x01
|
||||
|
||||
def __init__(self, name, label, value, sufix=None, flags=None):
|
||||
self.name = name
|
||||
self.label = label
|
||||
self.value = value
|
||||
self.sufix = sufix
|
||||
self.flags = flags
|
||||
|
||||
class Contact(object):
|
||||
STATUS_ONLINE = 0x001
|
||||
|
|
@ -28,24 +37,52 @@ class Contact(object):
|
|||
STATUS_AWAY = 0x004
|
||||
STATUS_ALL = 0xfff
|
||||
|
||||
def __init__(self, id, name, status, photo_url=None, thumbnail_url=None):
|
||||
def __init__(self, id, name, status):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.status = status
|
||||
self.photo_url = photo_url
|
||||
self.thumbnail_url = thumbnail_url
|
||||
self.status_msg = u''
|
||||
self.summary = u''
|
||||
self.avatar = None
|
||||
self.photos = []
|
||||
self.profile = None
|
||||
|
||||
def iter_fields(self):
|
||||
return {'id': self.id,
|
||||
'name': self.name,
|
||||
'status': self.status,
|
||||
'photo_url': self.photo_url,
|
||||
'thumbnail_url': self.thumbnail_url,
|
||||
'status_msg': self.status_msg,
|
||||
'summary': self.summary,
|
||||
'avatar': self.avatar,
|
||||
'photos': self.photos,
|
||||
'profile': self.profile,
|
||||
}.iteritems()
|
||||
|
||||
class ICapContact(ICap):
|
||||
def iter_contacts(self, status=Contact.STATUS_ALL):
|
||||
def iter_contacts(self, status=Contact.STATUS_ALL, ids=None):
|
||||
"""
|
||||
Iter contacts
|
||||
|
||||
@param status get only contacts with the specified status
|
||||
@param ids if set, get the specified contacts
|
||||
@return iterator over the contacts found
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_contact(self, id):
|
||||
raise NotImplementedError()
|
||||
"""
|
||||
Get a contact from his id.
|
||||
|
||||
The default implementation only calls iter_contacts()
|
||||
with the proper values, but it might be overloaded
|
||||
by backends.
|
||||
|
||||
@param id the ID requested
|
||||
@return the Contact object, or None if not found
|
||||
"""
|
||||
|
||||
l = self.iter_contacts(ids=[id])
|
||||
try:
|
||||
return l[0]
|
||||
except IndexError:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -22,31 +22,6 @@ from .cap import ICap
|
|||
__all__ = ['ICapDating', 'Profile']
|
||||
|
||||
|
||||
class Profile(object):
|
||||
def get_profile_text(self):
|
||||
body = u'Status: %s' % unicode(self.status)
|
||||
if self.photos:
|
||||
body += u'\nPhotos:'
|
||||
for photo in self.photos:
|
||||
body += u'\n\t\t%s' % unicode(photo)
|
||||
body += u'\nStats:'
|
||||
for label, value in self.get_stats().iteritems():
|
||||
body += u'\n\t\t%-15s %s' % (label + ':', value)
|
||||
body += u'\n\nInformations:'
|
||||
for section, d in self.get_table().iteritems():
|
||||
body += u'\n\t%s\n' % section
|
||||
for key, value in d.items():
|
||||
key = '%s:' % key
|
||||
if isinstance(value, list):
|
||||
body += u'\t\t%-15s %s\n' % (key, u', '.join([unicode(s) for s in value]))
|
||||
elif isinstance(value, float):
|
||||
body += u'\t\t%-15s %.2f\n' % (key, value)
|
||||
else:
|
||||
body += u'\t\t%-15s %s\n' % (key, unicode(value))
|
||||
body += u'\n\nDescription:\n%s' % unicode(self.get_description())
|
||||
|
||||
return body
|
||||
|
||||
class OptimizationNotFound(Exception): pass
|
||||
|
||||
class Optimization(object):
|
||||
|
|
@ -67,9 +42,6 @@ class StatusField(object):
|
|||
self.flags = flags
|
||||
|
||||
class ICapDating(ICap):
|
||||
def get_profile(self, _id):
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_status(self):
|
||||
"""
|
||||
Get a list of fields
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue