Grabbing groups you haven't joined in place.

This commit is contained in:
Kenneth Reitz
2011-02-19 14:15:58 -05:00
parent 8790a7279a
commit fc8a1244b6
+15
View File
@@ -17,6 +17,8 @@ class Groups(UserList):
self.data = []
self.sync()
def joined(self):
"""Returns list of """
def __getitem__(self, key):
@@ -27,6 +29,18 @@ class Groups(UserList):
if key in (group.id, group.slug):
return group
try:
r = requests.get(API_URL + 'groups/%s.json' % key)
r.raise_for_status()
group = models.Group()
group.import_from_api(json.loads(r.content)['group'])
return group
except requests.HTTPError:
return None
def __contains__(self, key):
if isinstance(key, int):
@@ -51,4 +65,5 @@ class Groups(UserList):
group = models.Group()
group.import_from_api(_group)
group.joined = True
self.data.append(group)