From: Marek Marecki Date: Sun, 30 Jun 2013 23:52:56 +0000 (+0200) Subject: Getting users who are contained in an aspect is now possible X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e4544075b00db12c35ce4e7c15c022c257689586;p=diaspy.git Getting users who are contained in an aspect is now possible --- diff --git a/diaspy/models.py b/diaspy/models.py index bd5053a..cc4b0a4 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -16,31 +16,50 @@ class Aspect(): def __init__(self, connection, id=-1): self._connection = connection self.id = id - self.name = '' + self.name = self._findname() + + def _findname(self): + """Finds name for aspect. + """ + name = '' + aspects = self._connection.getUserInfo()['aspects'] + for a in aspects: + if a['id'] == self.id: + name = a['name'] + break + return name def getUsers(self): - """Returns list of users who are listed in this aspect. + """Returns list of GUIDs of users who are listed in this aspect. """ start_regexp = re.compile('') ajax = ajax[begin:end] - all_users = userline_regexp.findall(ajax) - usernames = [line[35:-4] for line in all_users] - personid_regexp = 'alt="{USERNAME}" class="avatar" data-person_id="[0-9]+"' - person_ids = [re.compile(personid_regexp.replace('{USERNAME}', name)).search(ajax).group(0) for name in usernames] - personids = [] - for n, line in enumerate(person_ids): - i = -2 - id = '' + + usernames = [(line[17:33], line[35:-4]) for line in userline_regexp.findall(ajax)] + personids = [re.compile(personid_regexp.format(name)).search(ajax).group(0) for guid, name in usernames] + for n, line in enumerate(personids): + i, id = -2, '' while line[i].isdigit(): - id += line[i] + id = line[i] + id i -= 1 - personids.append((usernames[n], id)) - users = personids + personids[n] = (usernames[n][1], id) + + users_in_aspect = [] + for name, id in personids: + if re.compile(method_regexp.format(id, self.id)).search(ajax): users_in_aspect.append(name) + + users = [] + for i, user in enumerate(usernames): + guid, name = user + if name in users_in_aspect: + users.append(guid) return users def addUser(self, user_id):