[Checkins] SVN: Sandbox/luciano/kirbi/src/kirbi/ added import button to pac index (appears only when the pac is empty), and ImportDemo view

Luciano Ramalho luciano at ramalho.org
Sat Jul 21 21:42:33 EDT 2007


Log message for revision 78279:
  added import button to pac index (appears only when the pac is empty), and ImportDemo view
  

Changed:
  U   Sandbox/luciano/kirbi/src/kirbi/book.py
  U   Sandbox/luciano/kirbi/src/kirbi/pac.py
  U   Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt

-=-
Modified: Sandbox/luciano/kirbi/src/kirbi/book.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/book.py	2007-07-21 21:32:45 UTC (rev 78278)
+++ Sandbox/luciano/kirbi/src/kirbi/book.py	2007-07-22 01:42:31 UTC (rev 78279)
@@ -179,7 +179,7 @@
         if filing_title:
             self.__filing_title = filing_title
         elif not self.title or not self.title.strip():
-            self.__filing_title = self.__isbn13
+            self.__filing_title = '{isbn: %s}' % self.__isbn13
         else: # generate automatically
             # Do we know the language and it's articles?
             if self.language and self.language in ARTICLES:

Modified: Sandbox/luciano/kirbi/src/kirbi/pac.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/pac.py	2007-07-21 21:32:45 UTC (rev 78278)
+++ Sandbox/luciano/kirbi/src/kirbi/pac.py	2007-07-22 01:42:31 UTC (rev 78279)
@@ -22,12 +22,15 @@
     """
 
 class Index(grok.View):
-    
+
     def update(self, query=None):
+
         if not query:
             # XXX: if the query is empty, return all books; this should change
             # to some limited default search criteria or none at all
             results = self.context.values()
+            if not results:
+                self.demo_link = True # flag to display Import demo collection
             self.results_title = 'All items'
         else:
             catalog = getUtility(ICatalog)
@@ -52,13 +55,12 @@
             self.results_title = u'%stem%s matching "%s"' % (qty, s, query)
 
         self.results = sorted(results, key=attrgetter('filing_title'))
-        
+
     def coverUrl(self, name):
         cover_name = 'covers/medium/'+name+'.jpg'
         return self.static.get(cover_name,
                                self.static['covers/small-placeholder.jpg'])()
 
-
 class AddBook(grok.AddForm):
 
     form_fields = grok.AutoFields(Book)
@@ -113,3 +115,21 @@
         name = INameChooser(pac).chooseName(book_dict.get('isbn13'), book)
         pac[name] = book
         return name
+
+class ImportDemo(grok.View):
+
+    def render(self):
+        pac = self.context
+        from demo.collection import collection
+        for record in collection:
+            if record['name']:
+                record['creators'] = [creator.strip() for creator in record['name'].split('|')]
+                del record['name']
+            for key in record.keys():
+                if record[key] is None:
+                    del record[key]
+            book = Book(**record)
+            name = INameChooser(pac).chooseName(record.get('isbn13'), book)
+            pac[name] = book
+
+        self.redirect(self.url('index'))

Modified: Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt	2007-07-21 21:32:45 UTC (rev 78278)
+++ Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt	2007-07-22 01:42:31 UTC (rev 78279)
@@ -6,13 +6,13 @@
 
 </head>
 <body>
-  <span metal:fill-slot="content_title">Collective catalog</span>      
+  <span metal:fill-slot="content_title">Collective catalog</span>
   <span metal:fill-slot="content_actions">
     <form class="search" action=".">
         <input type="text" name="query">
         <input type="submit" name="submit" value="search">
     </form>
-  </span>  
+  </span>
   <div metal:fill-slot="content">
 
     <h3 tal:content="view/results_title">999 items matched the query</h3>
@@ -31,11 +31,16 @@
                     </dt>
                     <dd tal:content="item/creatorsLine">
                     </dd>
-                </dl>            
+                </dl>
             </td>
         </tr>
     </table>
 
+    <form tal:condition="view/demo_link|nothing"
+          tal:attributes="action python:view.url('importdemo')" method="post">
+        <input type="submit" value="Import a demo collection">
+    </form>
+
     <p><a tal:attributes="href python:view.url('addbook')">
             Add Book
     </a></p>



More information about the Checkins mailing list