Skip to content

Commit

Permalink
Add status to loans/libraries view.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Chitipothu committed Jun 8, 2011
1 parent 248a7a5 commit 9f68941
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion couchapps/admin/loans/views/libraries/map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
def _map(doc):
lib = doc.get("library")
status = doc.get("status")
if lib:
yield lib, 1
yield [lib, status], 1
6 changes: 4 additions & 2 deletions openlibrary/plugins/openlibrary/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,11 @@ def get_loans_per_user(self, key="", limit=1):
return [[row.key[-1], row.value] for row in rows if row.value >= limit]

def get_loans_per_library(self):
rows = self.view("loans/libraries", group=True).rows
# view contains:
# [lib_key, status], 1
rows = self.view("loans/libraries", group=True, group_level=1).rows
names = self._get_library_names()
return [[names.get(row.key, "-"), row.value] for row in rows]
return [[names.get(row.key[0], "-"), row.value] for row in rows]

def _get_library_names(self):
return dict((lib.key, lib.name) for lib in inlibrary.get_libraries())
Expand Down

0 comments on commit 9f68941

Please sign in to comment.