From 97fe89ab666ab789a25fd11b59ae8b0b18d75654 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Wed, 5 Oct 2011 15:36:50 +0200 Subject: [PATCH] profile is now a dict, not a list --- weboob/applications/havesex/havesex.py | 4 ++-- weboob/applications/qhavesex/contacts.py | 4 ++-- weboob/backends/aum/contact.py | 12 ++++++------ weboob/capabilities/contact.py | 5 ++++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/weboob/applications/havesex/havesex.py b/weboob/applications/havesex/havesex.py index 29140912..d8e7d615 100644 --- a/weboob/applications/havesex/havesex.py +++ b/weboob/applications/havesex/havesex.py @@ -38,7 +38,7 @@ class ProfileFormatter(IFormatter): result = u'' if node.flags & node.SECTION: result += u'\t' * level + node.label + '\n' - for sub in node.value: + for sub in node.value.itervalues(): result += self.print_node(sub, level+1) else: if isinstance(node.value, (tuple,list)): @@ -63,7 +63,7 @@ class ProfileFormatter(IFormatter): for name, photo in item['photos'].iteritems(): result += u'\t%s%s\n' % (photo, ' (hidden)' if photo.hidden else '') result += u'Profile:\n' - for head in item['profile']: + for head in item['profile'].itervalues(): result += self.print_node(head) result += u'Description:\n' for s in item['summary'].split('\n'): diff --git a/weboob/applications/qhavesex/contacts.py b/weboob/applications/qhavesex/contacts.py index 3d2f5558..eb9e8549 100644 --- a/weboob/applications/qhavesex/contacts.py +++ b/weboob/applications/qhavesex/contacts.py @@ -250,7 +250,7 @@ class ContactProfile(QWidget): missing_fields.add('profile') elif not self.loaded_profile: self.loaded_profile = True - for head in contact.profile: + for head in contact.profile.itervalues(): if head.flags & head.HEAD: widget = self.ui.headWidget else: @@ -265,7 +265,7 @@ class ContactProfile(QWidget): if node.flags & node.SECTION: value = QWidget() value.setLayout(QFormLayout()) - for sub in node.value: + for sub in node.value.itervalues(): self.process_node(sub, value) elif isinstance(node.value, list): value = QLabel('
'.join(unicode(s) for s in node.value)) diff --git a/weboob/backends/aum/contact.py b/weboob/backends/aum/contact.py index 09726880..172f4139 100644 --- a/weboob/backends/aum/contact.py +++ b/weboob/backends/aum/contact.py @@ -208,20 +208,20 @@ class Contact(_Contact): url=photo['url'], thumbnail_url=photo['url'].replace('image', 'thumb1_'), hidden=photo['hidden']) - self.profile = [] + self.profile = OrderedDict() for section, d in self.TABLE.iteritems(): flags = ProfileNode.SECTION if section.startswith('_'): flags |= ProfileNode.HEAD section = section.lstrip('_') - s = ProfileNode(section, section.capitalize(), [], flags=flags) + s = ProfileNode(section, section.capitalize(), OrderedDict(), flags=flags) for key, builder in d.iteritems(): value = builder.get_value(profile, consts[int(profile['sex'])]) - s.value.append(ProfileNode(key, key.capitalize().replace('_', ' '), value)) + s.value[key] = ProfileNode(key, key.capitalize().replace('_', ' '), value) - self.profile.append(s) + self.profile[section] = s self.aum_profile = profile @@ -230,7 +230,7 @@ class Contact(_Contact): result = u'' if node.flags & node.SECTION: result += u'\t' * level + node.label + '\n' - for sub in node.value: + for sub in node.value.itervalues(): result += print_node(sub, level+1) else: if isinstance(node.value, (tuple,list)): @@ -257,7 +257,7 @@ class Contact(_Contact): for name, photo in self.photos.iteritems(): result += u'\t%s%s\n' % (photo, ' (hidden)' if photo.hidden else '') result += u'\nProfile:\n' - for head in self.profile: + for head in self.profile.itervalues(): result += print_node(head) result += u'Description:\n' for s in self.summary.split('\n'): diff --git a/weboob/capabilities/contact.py b/weboob/capabilities/contact.py index 6a6e5a28..a392cbdd 100644 --- a/weboob/capabilities/contact.py +++ b/weboob/capabilities/contact.py @@ -35,6 +35,9 @@ class ProfileNode(object): self.sufix = sufix self.flags = flags + def __getitem__(self, key): + return self.value[key] + class ContactPhoto(CapBaseObject): def __init__(self, name): CapBaseObject.__init__(self, name) @@ -70,7 +73,7 @@ class Contact(CapBaseObject): self.add_field('status_msg', basestring) self.add_field('summary', basestring) self.add_field('photos', dict, OrderedDict()) - self.add_field('profile', list) + self.add_field('profile', dict) def set_photo(self, name, **kwargs): if not name in self.photos: