quick frontend, primitivus: quickContactList refactored to handle several profiles at once
This commit is contained in:
parent
0b52799489
commit
8851addc20
1 changed files with 552 additions and 168 deletions
|
|
@ -93,16 +93,20 @@ class QuickWidgetsManager(object):
|
|||
else:
|
||||
return widgets_map.itervalues()
|
||||
|
||||
def getWidget(self, class_, target, profile):
|
||||
def getWidget(self, class_, target=None, profiles=None):
|
||||
"""Get a widget without creating it if it doesn't exist.
|
||||
|
||||
@param class_(class): class of the widget to create
|
||||
@param target: target depending of the widget, usually a JID instance
|
||||
@param profile (unicode): %(doc_profile)s
|
||||
@param profiles (unicode, iterable[unicode], None): profile(s) to use (may or may not be
|
||||
used, depending of the widget class)
|
||||
@return: a class_ instance or None if the widget doesn't exist
|
||||
"""
|
||||
assert (target is not None) or (profiles is not None)
|
||||
if profiles is not None and isinstance(profiles, unicode):
|
||||
profiles = [profiles]
|
||||
class_ = self.getRealClass(class_)
|
||||
hash_ = class_.getWidgetHash(target, profile)
|
||||
hash_ = class_.getWidgetHash(target, profiles)
|
||||
try:
|
||||
return self._widgets[class_.__name__][hash_]
|
||||
except KeyError:
|
||||
|
|
@ -140,7 +144,7 @@ class QuickWidgetsManager(object):
|
|||
if 'profiles' in _kwargs and 'profile' in _kwargs:
|
||||
raise ValueError("You can't have 'profile' and 'profiles' keys at the same time")
|
||||
try:
|
||||
_kwargs['profiles'] = _kwargs.pop('profile')
|
||||
_kwargs['profiles'] = [_kwargs.pop('profile')]
|
||||
except KeyError:
|
||||
if not 'profiles' in _kwargs:
|
||||
_kwargs['profiles'] = None
|
||||
|
|
@ -266,7 +270,7 @@ class QuickWidget(object):
|
|||
if not self.PROFILES_ALLOW_NONE:
|
||||
raise ValueError("profiles can't have a value of None")
|
||||
else:
|
||||
if not self.PROFILES_MULTIPLE:
|
||||
if not self.PROFILES_MULTIPLE and len(profiles) != 1:
|
||||
raise ValueError("multiple profiles are not allowed")
|
||||
for profile in profiles:
|
||||
self.addProfile(profile)
|
||||
|
|
|
|||
Loading…
Reference in a new issue