[Checkins] SVN: grokapps/kirbi/trunk/src/kirbi/ Fixed retryPending. Tested, fixed and refactored book/item covers.

Leonardo Rochael Almeida leo at hiper.com.br
Fri Sep 21 01:01:47 EDT 2007


Log message for revision 79777:
  Fixed retryPending. Tested, fixed and refactored book/item covers.

Changed:
  U   grokapps/kirbi/trunk/src/kirbi/README.txt
  U   grokapps/kirbi/trunk/src/kirbi/TODO.txt
  U   grokapps/kirbi/trunk/src/kirbi/app.py
  U   grokapps/kirbi/trunk/src/kirbi/book.py
  U   grokapps/kirbi/trunk/src/kirbi/collection.py
  A   grokapps/kirbi/trunk/src/kirbi/ftests/covers.txt
  U   grokapps/kirbi/trunk/src/kirbi/ftests/learning.txt
  A   grokapps/kirbi/trunk/src/kirbi/ftests/pac.txt
  U   grokapps/kirbi/trunk/src/kirbi/ftests/test_functional.py
  U   grokapps/kirbi/trunk/src/kirbi/interfaces.py
  U   grokapps/kirbi/trunk/src/kirbi/item.py
  U   grokapps/kirbi/trunk/src/kirbi/pac.py
  D   grokapps/kirbi/trunk/src/kirbi/tests/test_pac.txt

-=-
Modified: grokapps/kirbi/trunk/src/kirbi/README.txt
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/README.txt	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/README.txt	2007-09-21 05:01:46 UTC (rev 79777)
@@ -149,15 +149,3 @@
 * preferences (at least passwd change; default lease time; create
     alternative collecions; privacy)
 
-
-Other tasks
-===========
-
-* Refactor kirbifetch to allow pluggable metadata sources, instead of
-  relying on Amazon.com exclusively
-
-* Increase test coverage
-
-* Packaging (buildout, eggification)
-
-* AJAXification using same framework used for Grok Admin UI

Modified: grokapps/kirbi/trunk/src/kirbi/TODO.txt
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/TODO.txt	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/TODO.txt	2007-09-21 05:01:46 UTC (rev 79777)
@@ -5,3 +5,12 @@
 * move cover images into ZODB (perhaps using blob support)
 
 * make kirbi startup start kirbifetch as well
+
+* Refactor kirbifetch to allow pluggable metadata sources, instead of
+  relying on Amazon.com exclusively
+
+* Increase test coverage
+
+* Packaging (buildout, eggification)
+
+* AJAXification using same framework used for Grok Admin UI

Modified: grokapps/kirbi/trunk/src/kirbi/app.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/app.py	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/app.py	2007-09-21 05:01:46 UTC (rev 79777)
@@ -110,7 +110,7 @@
     item_id = index.Field()
     lender_login = index.Field()
     borrower_login = index.Field()
-    getDue = index.Field()
+    expected_return_date = index.Field()
     request_date = index.Field()
     status = index.Field()
 
@@ -216,4 +216,4 @@
         # handled by calling the super.QuickNameChooser
         return super(QuickNameChooser, self).chooseName(name, object)
 
- 
\ No newline at end of file
+ 

Modified: grokapps/kirbi/trunk/src/kirbi/book.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/book.py	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/book.py	2007-09-21 05:01:46 UTC (rev 79777)
@@ -20,7 +20,7 @@
 from zope import schema
 from isbn import isValidISBN, isValidISBN10, isValidISBN13, filterDigits
 from isbn import convertISBN10toISBN13, convertISBN13toLang
-from zope.component import getUtility
+from zope.component import getUtility, getMultiAdapter
 from zope.app.catalog.interfaces import ICatalog
 
 
@@ -315,6 +315,19 @@
             self.source_url = None
 
     def coverUrl(self):
-        cover_name = 'covers/large/'+self.context.getCoverId()+'.jpg'
-        return self.static.get(cover_name,
-                               self.static['covers/small-placeholder.jpg'])()
+        cover = getMultiAdapter((self.context, self.request), name='cover')
+        return cover()
+
+
+class Cover(grok.View):
+    grok.context(IBook)
+
+    def render(self):
+        prefix = 'covers/large/' + self.context.getCoverId()
+        tries = [prefix + ext for ext in '.gif .jpg .png'.split()]
+        tries.append('covers/small-placeholder.jpg')
+        for path in tries:
+            cover = self.static.get(path, None)
+            if cover:
+                return cover()
+        raise LookupError("Cover placeholder not found")

Modified: grokapps/kirbi/trunk/src/kirbi/collection.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/collection.py	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/collection.py	2007-09-21 05:01:46 UTC (rev 79777)
@@ -22,7 +22,7 @@
 from kirbi.item import Item
 from kirbi.book import Book
 from zope.app.container.interfaces import INameChooser
-from zope.component import getUtility
+from zope.component import getUtility, getMultiAdapter
 from zope.app.catalog.interfaces import ICatalog
 
 
@@ -60,10 +60,9 @@
         
     def coverUrl(self, item):
         book = self.pac[item.manifestation_id]
-        cover_name = 'covers/large/'+book.__name__+'.jpg'
-        return self.static.get(cover_name,
-                               self.static['covers/small-placeholder.jpg'])()
-    
+        cover = getMultiAdapter((book, self.request), name='cover')
+        return cover()
+
     def yourRequests(self):
         catalog = getUtility(ICatalog)
         res = catalog.searchResults(
@@ -123,7 +122,7 @@
                 added = True
 
         if retry_isbns:
-            self.context.retryPending(retry_isbns)
+            self.retryPending(retry_isbns)
         # XXX this would be great with AJAX, avoiding the ugly refresh
         # If there are no invalid_isbns in the text area, set refresh or redirect
         if not self.invalid_isbns:
@@ -155,6 +154,10 @@
         self.pac = self.context.__parent__.__parent__['pac']
         return list(self.sortedByTime(self.pac.getPending()))
 
+    def retryPending(self, retry_isbns):
+        self.pac.retryPending(retry_isbns)
+
+
 class ImportSample(grok.View):
                 
     def render(self, quantity=10):

Added: grokapps/kirbi/trunk/src/kirbi/ftests/covers.txt
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/ftests/covers.txt	                        (rev 0)
+++ grokapps/kirbi/trunk/src/kirbi/ftests/covers.txt	2007-09-21 05:01:46 UTC (rev 79777)
@@ -0,0 +1,68 @@
+If there are no covers available, a placeholder should be retrieved instead::
+
+    >>> import os, os.path
+    >>> from kirbi.book import Book
+    >>> from kirbi.app import Kirbi
+    >>> from kirbi.collection import Collection
+    >>> from kirbi.item import Item
+    >>> import kirbi
+    >>> from zope.publisher.browser import TestRequest
+    >>> from zope.component import getMultiAdapter
+    >>> from zope.app.component.hooks import setSite
+
+    >>> root = getRootFolder()
+    >>> app = root['kirbi'] = Kirbi()
+    >>> setSite(app)
+    >>> pac = app['pac']
+    >>> collection = Collection('123')
+    >>> request = TestRequest()
+    >>> cover_dir = os.path.join(os.path.dirname(kirbi.__file__),
+    ...                          'static', 'covers')
+    >>> pac.addBook(Book(title='NoSuchBook'))
+    u'b1'
+    >>> book = pac['b1']
+    >>> item = Item(book.__name__, '')
+    >>> pac_index = getMultiAdapter((pac, request), name='index')
+    >>> book_index = getMultiAdapter((book, request), name='index')
+    >>> col_index = getMultiAdapter((collection, request), name='index')
+
+    >>> print pac_index.coverUrl(book)
+    http://.../@@/kirbi/covers/small-placeholder.jpg
+    >>> print book_index.coverUrl()
+    http://.../@@/kirbi/covers/small-placeholder.jpg
+    >>> print col_index.coverUrl(item)
+    http://.../@@/kirbi/covers/small-placeholder.jpg
+
+Available covers should be retrieved, for extensions in .gif, .jpg or .png::
+
+    >>> cover_prefix = os.path.join(cover_dir, 'large', book.__name__)
+    >>> file(cover_prefix + '.gif', 'w').close()
+    >>> print pac_index.coverUrl(book)
+    http://.../@@/kirbi/covers/large/b1.gif
+    >>> book_index = getMultiAdapter((book, request), name='index')
+    >>> print book_index.coverUrl()
+    http://.../@@/kirbi/covers/large/b1.gif
+    >>> print col_index.coverUrl(item)
+    http://.../@@/kirbi/covers/large/b1.gif
+    >>> os.unlink(cover_prefix + '.gif')
+
+
+    >>> file(cover_prefix + '.jpg', 'w').close()
+    >>> print pac_index.coverUrl(book)
+    http://.../@@/kirbi/covers/large/b1.jpg
+    >>> book_index = getMultiAdapter((book, request), name='index')
+    >>> print book_index.coverUrl()
+    http://.../@@/kirbi/covers/large/b1.jpg
+    >>> print col_index.coverUrl(item)
+    http://.../@@/kirbi/covers/large/b1.jpg
+    >>> os.unlink(cover_prefix + '.jpg')
+
+    >>> file(cover_prefix + '.png', 'w').close()
+    >>> print pac_index.coverUrl(book)
+    http://.../@@/kirbi/covers/large/b1.png
+    >>> book_index = getMultiAdapter((book, request), name='index')
+    >>> print book_index.coverUrl()
+    http://.../@@/kirbi/covers/large/b1.png
+    >>> print col_index.coverUrl(item)
+    http://.../@@/kirbi/covers/large/b1.png
+    >>> os.unlink(cover_prefix + '.png')

Modified: grokapps/kirbi/trunk/src/kirbi/ftests/learning.txt
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/ftests/learning.txt	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/ftests/learning.txt	2007-09-21 05:01:46 UTC (rev 79777)
@@ -7,8 +7,10 @@
 First we setup the app::
 
     >>> from grok.ftests.xmlrpc_helper import ServerProxy
+    >>> from zope.app.component.hooks import setSite
     >>> from kirbi.app import Kirbi
     >>> root = getRootFolder()
+    >>> setSite(root)
     >>> kirbi = root['kirbi'] = Kirbi()
 
 A Pac instance is created when Kirbi is initialized::
@@ -28,9 +30,3 @@
     >>> obj
     <kirbi.app.Kirbi object at ...>
 
-There is a shortcut for this in the Grok API, but for some reason it doesn't
-work in this test:
-
-    >>> theApp = grok.getSite()
-    >>> repr(theApp)
-    'None'

Copied: grokapps/kirbi/trunk/src/kirbi/ftests/pac.txt (from rev 79776, grokapps/kirbi/trunk/src/kirbi/tests/test_pac.txt)
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/ftests/pac.txt	                        (rev 0)
+++ grokapps/kirbi/trunk/src/kirbi/ftests/pac.txt	2007-09-21 05:01:46 UTC (rev 79777)
@@ -0,0 +1,28 @@
+==============================================
+Pac: The Public Access Catalog container class
+==============================================
+
+A Pac is designed to store book records. Let's create one and put a few
+books in it::
+
+    >>> import grok
+    >>> from kirbi.pac import Pac
+    >>> from kirbi.book import Book
+    >>> from kirbi.app import Kirbi
+    >>> root = getRootFolder()
+    >>> app = root['kirbi'] = Kirbi()
+    >>> pac = app['pac']
+    >>> pac.addBook(Book(u'Zero'))
+    u'b1'
+    >>> pac.addBook(Book(isbn13='978-0670030583'))
+    u'9780670030583'
+    >>> pac.addBook(Book(u'A Tale of Two Cities', isbn13='978-0141439600'))
+    u'9780141439600'
+    >>> sorted(pac)
+    [u'9780141439600', u'9780670030583', u'b1']
+
+One of the books has ISBN but no Title, so it's put in the fetch queue::
+    # XXX: revise this test to the new Pac API
+    # >>> pac.pending_isbns
+    # ['9780670030583']
+

Modified: grokapps/kirbi/trunk/src/kirbi/ftests/test_functional.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/ftests/test_functional.py	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/ftests/test_functional.py	2007-09-21 05:01:46 UTC (rev 79777)
@@ -24,6 +24,8 @@
                 'user.txt',
                 'learning.txt',
                 'addbook.txt',
+                'pac.txt',
+                'covers.txt',
                 ]
 
     for docfile in docfiles:

Modified: grokapps/kirbi/trunk/src/kirbi/interfaces.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/interfaces.py	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/interfaces.py	2007-09-21 05:01:46 UTC (rev 79777)
@@ -153,8 +153,14 @@
 
     request_date = Attribute(u"When the lease was requested.")
 
-    getDue = Attribute(u"Calculated due date.")
+    expected_delivery_date = Attribute(u"When the copy is to be delivered to the borrower.")
 
+    delivery_date = Attribute(u"When the copy was delivered to the borrower.")
+
+    expected_return_date = Attribute(u"When the copy is to be returned.")
+
+    return_date = Attribute(u"When the copy was returned.")
+
     # XXX: This should have a vocabulary
     duration = Attribute(u"One of: minute week month quarter semester year")
     

Modified: grokapps/kirbi/trunk/src/kirbi/item.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/item.py	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/item.py	2007-09-21 05:01:46 UTC (rev 79777)
@@ -153,6 +153,8 @@
     def getDue(self):
         return Lease.calculateDue(self.request_date, self.duration)
 
+    expected_return_date = property(getDue)
+
     @staticmethod
     def calculateDue(fromDateTime, interval):
         MONTHLY_INTERVALS = {u'month':1, u'quarter':3, u'semester':6}

Modified: grokapps/kirbi/trunk/src/kirbi/pac.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/pac.py	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/pac.py	2007-09-21 05:01:46 UTC (rev 79777)
@@ -25,7 +25,7 @@
 from isbn import isValidISBN, isValidISBN10, convertISBN10toISBN13, filterDigits
 
 from zope.app.catalog.interfaces import ICatalog
-from zope.component import getUtility, queryUtility
+from zope.component import getUtility, queryUtility, getMultiAdapter
 from persistent.dict import PersistentDict
 from time import localtime, strftime
 
@@ -102,9 +102,8 @@
     grok.context(Pac)
 
     def coverUrl(self, book):
-        cover_name = 'covers/large/'+book.__name__+'.jpg'
-        return self.static.get(cover_name,
-                               self.static['covers/small-placeholder.jpg'])()
+        cover = getMultiAdapter((book, self.request), name='cover')
+        return cover()
 
     def update(self, query=None):
         if not query:

Deleted: grokapps/kirbi/trunk/src/kirbi/tests/test_pac.txt
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/tests/test_pac.txt	2007-09-20 23:50:45 UTC (rev 79776)
+++ grokapps/kirbi/trunk/src/kirbi/tests/test_pac.txt	2007-09-21 05:01:46 UTC (rev 79777)
@@ -1,25 +0,0 @@
-==============================================
-Pac: The Public Access Catalog container class
-==============================================
-
-A Pac is designed to store book records. Let's create one and put a few
-books in it::
-
-    >>> import grok
-    >>> grok.grok('kirbi')
-    >>> from kirbi.pac import Pac
-    >>> from kirbi.book import Book
-    >>> pac = Pac()
-    >>> pac.addBook(Book(u'Zero'))
-    u'b1'
-    >>> pac.addBook(Book(isbn13='978-0670030583'))
-    u'9780670030583'
-    >>> pac.addBook(Book(u'A Tale of Two Cities', isbn13='978-0141439600'))
-    u'9780141439600'
-    >>> sorted(pac)
-    [u'9780141439600', u'9780670030583', u'b1']
-
-One of the books has ISBN but no Title, so it's put in the fetch queue::
-    # XXX: revise this test to the new Pac API
-    # >>> pac.pending_isbns
-    # ['9780670030583']



More information about the Checkins mailing list