Permalink
Browse files

Abstract code to fetch results into QuerySet._get_results

  • Loading branch information...
1 parent b15ca76 commit 6546e390f955b6ca0982d88dd533dd5d6a15aada @dcramer committed with gandalfar Jun 25, 2011
Showing with 9 additions and 7 deletions.
  1. +9 −7 sentry/db/models.py
View
16 sentry/db/models.py
@@ -78,13 +78,7 @@ def __getitem__(self, key):
desc = False
index = self.index
-
- if self.filter:
- data = [(pk, app.db.get_data(self.model, pk)) for pk in app.db.list_by_cindex(self.model, **to_db(self.model, self.filter))]
- else:
- data = app.db.list(self.model, index, start, num, desc)
-
- results = [self.model(pk, **data) for pk, data in data]
+ results = self._get_results(start, num, index, desc)
if is_slice:
return results
@@ -102,6 +96,14 @@ def __iter__(self):
for r in self[0:-1]:
yield r
+ def _get_results(self, start, num, index, desc=False):
+ if self.filter:
+ data = [(pk, app.db.get_data(self.model, pk)) for pk in app.db.list_by_cindex(self.model, **to_db(self.model, self.filter))]
+ else:
+ data = app.db.list(self.model, index, start, num, desc)
+
+ return [self.model(pk, **data) for pk, data in data]
+
def order_by(self, index):
assert not self.filter
self.index = index

0 comments on commit 6546e39

Please sign in to comment.