[Checkins] SVN: Sandbox/luciano/kirbi/ refactoring templates

Luciano Ramalho luciano at ramalho.org
Tue Aug 14 21:37:18 EDT 2007


Log message for revision 78828:
  refactoring templates
  

Changed:
  D   Sandbox/luciano/kirbi/index.pt
  U   Sandbox/luciano/kirbi/src/kirbi/app.py
  U   Sandbox/luciano/kirbi/src/kirbi/app_templates/index.pt
  U   Sandbox/luciano/kirbi/src/kirbi/app_templates/master.pt
  U   Sandbox/luciano/kirbi/src/kirbi/book.py
  D   Sandbox/luciano/kirbi/src/kirbi/book_templates/details.pt
  A   Sandbox/luciano/kirbi/src/kirbi/book_templates/index.pt
  U   Sandbox/luciano/kirbi/src/kirbi/pac.py
  U   Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt
  U   Sandbox/luciano/kirbi/src/kirbi/tests/test_pac.txt
  U   Sandbox/luciano/kirbi/src/kirbi/user.py

-=-
Deleted: Sandbox/luciano/kirbi/index.pt
===================================================================
--- Sandbox/luciano/kirbi/index.pt	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/index.pt	2007-08-15 01:37:17 UTC (rev 78828)
@@ -1,70 +0,0 @@
-<html metal:use-macro="context/@@master/page">
-<head>
-    <title metal:fill-slot="title">
-        Book detail: <span tal:replace="view/main_title" />
-    </title>
-</head>
-<body>
-  <span metal:fill-slot="content_title">Book details</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>
-
-  <div metal:fill-slot="content">
-
-    <div class="details">
-    <img class="cover" tal:attributes="src view/coverUrl">
-
-    <h1 tal:condition="view/main_title"
-        tal:content="view/main_title">Main Title</h1>
-    <h1 tal:condition="not:view/main_title"
-        class="unknown">(title not available)</h1>
-    <h2 tal:content="view/sub_title">sub-title</h2>
-
-    <table>
-        <tr><th>Creators</th>
-            <td>
-                <tal:creator repeat="creator context/creatorsListDict">
-                    <tal:comment replace="nothing">Next few lines have weird
-                        indentation because of the need to control the spaces
-                        between names and the comma</tal:comment>
-                    <a tal:attributes="href
-                       string:${view/creator_search_url}${creator/name}"
-                       tal:content="creator/name">
-                    Joe Doe</a><tal:role condition="creator/role">
-                    (<span tal:replace="creator/role" />)</tal:role><tal:comma
-                       condition="not:repeat/creator/end">, </tal:comma>
-                </tal:creator>
-            </td>
-        </tr>
-        <tr><th>ISBN-13</th>
-            <td tal:content="view/isbn13">9780123456789</td>
-        </tr>
-        <tr><th>Edition</th>
-            <td tal:content="context/edition">2nd</td>
-        </tr>
-        <tr><th>Publisher</th>
-            <td tal:content="context/publisher">Sample Publishing Co.</td>
-        </tr>
-        <tr><th>Issued</th>
-            <td tal:content="context/issued">2006-12-31</td>
-        </tr>
-        <tr><th>Language</th>
-            <td tal:content="context/language">pt</td>
-        </tr>
-    </table>
-
-    </div><!-- /details -->
-
-    <!-- XXX: only the site manager should be able to edit a book -->
-    <form class="search" tal:attributes="action python:view.url('edit')">
-        <input type="submit" name="submit" value="edit">
-    </form>
-
-
-  </div><!-- /content -->
-  </body>
-</html>

Modified: Sandbox/luciano/kirbi/src/kirbi/app.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/app.py	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/app.py	2007-08-15 01:37:17 UTC (rev 78828)
@@ -5,21 +5,34 @@
 from kirbi.user import UserFolder
 from zope.interface import Interface, implements
 from zope.component import getSiteManager
+from zope.traversing import browser
 
-sitePac = None
-siteUsers = None
+PAC_NAME = u'pac'
+USER_FOLDER_NAME = u'u'
 
 class Kirbi(grok.Application, grok.Container):
     """Peer-to-peer library system."""
     def __init__(self):
-        global sitePac, siteUsers
+        global sitePac, siteUsers, siteUsersURL
         super(Kirbi, self).__init__()
-        sitePac = self['pac'] = Pac()
-        siteUsers = self['u'] = UserFolder()
+        self[PAC_NAME] = Pac()
+        self[USER_FOLDER_NAME] = UserFolder()
 
 class Index(grok.View):
-    pass
 
+    def menu_items(self):
+        return [
+            {'url':self.url(self.context[USER_FOLDER_NAME],'join'),  'text':u'join'},
+            {'url':'''http://circulante.incubadora.fapesp.br/''',
+                'text':u'about'},
+        ]
+
+    def pac_url(self):
+        return self.url(self.context[PAC_NAME])
+
+    def login_url(self):
+        return self.url(self.context[USER_FOLDER_NAME],'login')
+
 class BookIndexes(grok.Indexes):
     grok.site(Kirbi)
     grok.context(Book)

Modified: Sandbox/luciano/kirbi/src/kirbi/app_templates/index.pt
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/app_templates/index.pt	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/app_templates/index.pt	2007-08-15 01:37:17 UTC (rev 78828)
@@ -3,11 +3,28 @@
    <title metal:fill-slot="title">Main</title>
 </head>
 <body>
-  <span metal:fill-slot="content_title">Main</span>      
+  <span metal:fill-slot="content_title">Collective catalog</span>
+  <span metal:fill-slot="content_actions">
+    <form class="search" tal:attributes="action view/pac_url">
+        <input type="text" name="query">
+        <input type="submit" name="submit" value="search">
+    </form>
+  </span>
 
   <div metal:fill-slot="content">
 
-  Main page stuff will be here.
+  <table><tr><td width="15%">
+    <form tal:attributes="action view/login_url">
+        <table bgcolor="#DDDDDD" width="100%">
+           <tr><th>Login</th><td><input name="login"></td></tr>
+           <tr><th>Password</th><td><input type="password" name="password"></td></tr>
+           <tr><td></td><td><input type="submit" value="enter"></td></tr>
+        </table>
+    </form>
+    </td><td valign="top" align="center">
+        <h2>Recent additions</h2>
+    </td></tr>
+  </table>
   
   </div>	
 </body>

Modified: Sandbox/luciano/kirbi/src/kirbi/app_templates/master.pt
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/app_templates/master.pt	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/app_templates/master.pt	2007-08-15 01:37:17 UTC (rev 78828)
@@ -26,11 +26,8 @@
         title="Circulante.org" width="212" height="51" />
     </a>
     <ul>
-        <li><a tal:attributes="href python:view.application_url('pac')">catalog</a></li>
-        <li><a tal:attributes="href python:view.application_url()">collection</a></li>
-        <li><a tal:attributes="href python:view.application_url('u')">users</a></li>
-        <li><a tal:attributes="href python:view.application_url()">leases</a></li>
-        <li><a tal:attributes="href python:view.application_url('pac')+'/incomplete'">incomplete</a></li>
+        <li tal:repeat="item view/menu_items"><a tal:attributes="href item/url"
+           tal:content="item/text">catalog</a></li>
     </ul>
   </div>
   <div metal:define-slot="body">

Modified: Sandbox/luciano/kirbi/src/kirbi/book.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/book.py	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/book.py	2007-08-15 01:37:17 UTC (rev 78828)
@@ -1,9 +1,12 @@
 import grok
-from zope.interface import Interface, implements, invariant, Invalid
+from interfaces import IBook
+from zope.interface import implements
 from zope import schema
 from isbn import isValidISBN, isValidISBN10, isValidISBN13, filterDigits
 from isbn import convertISBN10toISBN13, convertISBN13toLang
 
+USER_FOLDER_NAME = u'u'
+
 import os
 
 STATIC_PATH = os.path.join(os.path.dirname(__file__), 'static')
@@ -17,60 +20,6 @@
     'pt': u'o os a as um uns uma umas'.split(),
 }
 
-class InvalidISBN(schema.ValidationError):
-    """This is not a valid ISBN-10 or ISBN-13"""
-
-def validateISBN(isbn):
-    if not isValidISBN(isbn):
-        raise InvalidISBN
-    else:
-        return True
-
-class IBook(Interface):
-    """A book record"""
-    title = schema.TextLine(title=u"Title",
-                            required=False,
-                            default=u'',
-                            missing_value=u'')
-    isbn = schema.TextLine(title=u"ISBN",
-                           required=False,
-                           constraint=validateISBN,
-                           description=u"ISBN in 10 or 13 digit format",
-                           min_length=10,
-                           max_length=17 #978-3-540-33807-9
-                           )
-
-    creators = schema.Tuple(title=u"Authors",
-                            value_type=schema.TextLine(),
-                            default=())
-    edition = schema.TextLine(title=u"Edition", required=False)
-    publisher = schema.TextLine(title=u"Publisher", required=False)
-    issued = schema.TextLine(title=u"Issued", required=False)
-    # TODO: set a vocabulary for language
-    language = schema.TextLine(title=u"Language", required=False)
-    
-    subjects = schema.Tuple(title=u"Subjects",
-                            value_type=schema.TextLine(),
-                            default=())
-            
-    source = schema.TextLine(title=u"Record source",
-                             required=False,
-                             description=u"Name of the source of this record.")
-    source_url = schema.URI(title=u"Source URL",
-                            required=False,
-                            description=u"URL of the source of this record.")
-    source_item_id = schema.TextLine(title=u"Item ID at Source",
-                            required=False,
-                            description= (u"Product number or other identifier"
-                                          u" for this item at source.")
-    )
-
-
-    @invariant
-    def titleOrIsbnGiven(book):
-        if (not book.title or not book.title.strip()) and (not book.isbn):
-            raise Invalid('Either the title or the ISBN must be given.')
-
 class Book(grok.Model):
     """A book record implementation.
 
@@ -130,6 +79,10 @@
         self.publisher = publisher
         self.issued = issued
         self.language = language
+        if subjects is None:
+            self.subjects = []
+        else:
+            self.subjects = subjects
         self.source = source
         self.source_url = source_url
         self.source_item_id = source_item_id
@@ -291,16 +244,17 @@
 
 
 class Edit(grok.EditForm):
+    # XXX: only the site manager should be able to edit a book
     pass
 
-class Index(grok.DisplayForm):
+class Display(grok.DisplayForm):
     pass
 
-class Details(grok.View):
-
+class Index(grok.View):
+    
     def __init__(self, *args):
         # XXX: Is this super call really needed for a View sub-class?
-        super(Details,self).__init__(*args)
+        super(Index,self).__init__(*args)
 
         # Note: this method was created because calling context properties
         # from the template raises a traversal error
@@ -313,3 +267,12 @@
         cover_name = 'covers/large/'+self.context.__name__+'.jpg'
         return self.static.get(cover_name,
                                self.static['covers/small-placeholder.jpg'])()
+
+    def menu_items(self):
+        return [
+            {'url':self.url(self.context.__parent__.__parent__[USER_FOLDER_NAME],'join'),
+                'text':u'join'},
+            {'url':'''http://circulante.incubadora.fapesp.br/''',
+                'text':u'about'},
+        ]
+

Deleted: Sandbox/luciano/kirbi/src/kirbi/book_templates/details.pt
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/book_templates/details.pt	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/book_templates/details.pt	2007-08-15 01:37:17 UTC (rev 78828)
@@ -1,70 +0,0 @@
-<html metal:use-macro="context/@@master/page">
-<head>
-    <title metal:fill-slot="title">
-        Book detail: <span tal:replace="view/main_title" />
-    </title>
-</head>
-<body>
-  <span metal:fill-slot="content_title">Book details</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>
-
-  <div metal:fill-slot="content">
-
-    <div class="details">
-    <img class="cover" tal:attributes="src view/coverUrl">
-
-    <h1 tal:condition="view/main_title"
-        tal:content="view/main_title">Main Title</h1>
-    <h1 tal:condition="not:view/main_title"
-        class="unknown">(title not available)</h1>
-    <h2 tal:content="view/sub_title">sub-title</h2>
-
-    <table>
-        <tr><th>Creators</th>
-            <td>
-                <tal:creator repeat="creator context/creatorsListDict">
-                    <tal:comment replace="nothing">Next few lines have weird
-                        indentation because of the need to control the spaces
-                        between names and the comma</tal:comment>
-                    <a tal:attributes="href
-                       string:${view/creator_search_url}${creator/name}"
-                       tal:content="creator/name">
-                    Joe Doe</a><tal:role condition="creator/role">
-                    (<span tal:replace="creator/role" />)</tal:role><tal:comma
-                       condition="not:repeat/creator/end">, </tal:comma>
-                </tal:creator>
-            </td>
-        </tr>
-        <tr><th>ISBN-13</th>
-            <td tal:content="view/isbn13">9780123456789</td>
-        </tr>
-        <tr><th>Edition</th>
-            <td tal:content="context/edition">2nd</td>
-        </tr>
-        <tr><th>Publisher</th>
-            <td tal:content="context/publisher">Sample Publishing Co.</td>
-        </tr>
-        <tr><th>Issued</th>
-            <td tal:content="context/issued">2006-12-31</td>
-        </tr>
-        <tr><th>Language</th>
-            <td tal:content="context/language">pt</td>
-        </tr>
-    </table>
-
-    </div><!-- /details -->
-
-    <!-- XXX: only the site manager should be able to edit a book -->
-    <form class="search" tal:attributes="action python:view.url('edit')">
-        <input type="submit" name="submit" value="edit">
-    </form>
-
-
-  </div><!-- /content -->
-  </body>
-</html>

Copied: Sandbox/luciano/kirbi/src/kirbi/book_templates/index.pt (from rev 78827, Sandbox/luciano/kirbi/index.pt)
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/book_templates/index.pt	                        (rev 0)
+++ Sandbox/luciano/kirbi/src/kirbi/book_templates/index.pt	2007-08-15 01:37:17 UTC (rev 78828)
@@ -0,0 +1,70 @@
+<html metal:use-macro="context/@@master/page">
+<head>
+    <title metal:fill-slot="title">
+        Book detail: <span tal:replace="view/main_title" />
+    </title>
+</head>
+<body>
+  <span metal:fill-slot="content_title">Book details</span>      
+  <span metal:fill-slot="content_actions">
+    <form class="search" action="../pac">
+        <input type="text" name="query">
+        <input type="submit" name="submit" value="search">
+    </form>
+  </span>
+
+  <div metal:fill-slot="content">
+
+    <div class="details">
+    <img class="cover" tal:attributes="src view/coverUrl">
+
+    <h1 tal:condition="view/main_title"
+        tal:content="view/main_title">Main Title</h1>
+    <h1 tal:condition="not:view/main_title"
+        class="unknown">(title not available)</h1>
+    <h2 tal:content="view/sub_title">sub-title</h2>
+
+    <table>
+        <tr><th>Creators</th>
+            <td>
+                <tal:creator repeat="creator context/creatorsListDict">
+                    <tal:comment replace="nothing">Next few lines have weird
+                        indentation because of the need to control the spaces
+                        between names and the comma</tal:comment>
+                    <a tal:attributes="href
+                       string:${view/creator_search_url}${creator/name}"
+                       tal:content="creator/name">
+                    Joe Doe</a><tal:role condition="creator/role">
+                    (<span tal:replace="creator/role" />)</tal:role><tal:comma
+                       condition="not:repeat/creator/end">, </tal:comma>
+                </tal:creator>
+            </td>
+        </tr>
+        <tr><th>ISBN-13</th>
+            <td tal:content="view/isbn13">9780123456789</td>
+        </tr>
+        <tr><th>Edition</th>
+            <td tal:content="context/edition">2nd</td>
+        </tr>
+        <tr><th>Publisher</th>
+            <td tal:content="context/publisher">Sample Publishing Co.</td>
+        </tr>
+        <tr><th>Issued</th>
+            <td tal:content="context/issued">2006-12-31</td>
+        </tr>
+        <tr><th>Language</th>
+            <td tal:content="context/language">pt</td>
+        </tr>
+    </table>
+
+    </div><!-- /details -->
+
+    <!-- XXX: only the site manager should be able to edit a book -->
+    <form class="search" tal:attributes="action python:view.url('edit')">
+        <input type="submit" name="submit" value="edit">
+    </form>
+
+
+  </div><!-- /content -->
+  </body>
+</html>

Modified: Sandbox/luciano/kirbi/src/kirbi/pac.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/pac.py	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/pac.py	2007-08-15 01:37:17 UTC (rev 78828)
@@ -86,6 +86,15 @@
         pac.addIncomplete(book.isbn13)
 
 class Incomplete(grok.View):
+
+    def menu_items(self):
+        return [
+            {'url':self.url(self.context.__parent__[USER_FOLDER_NAME],'join'),
+                'text':u'join'},
+            {'url':'''http://circulante.incubadora.fapesp.br/''',
+                'text':u'about'},
+        ]
+
     def sortedByTime(self, isbn_dict):
         pairs = ((timestamp, isbn) for isbn, timestamp in
                     isbn_dict.items())
@@ -104,10 +113,9 @@
         if self.context.getIncomplete() or self.context.getPending():
             self.request.response.setHeader("Refresh", "5; url=%s" % self.url())
         
-
-
 class Index(grok.View):
-
+    grok.context(Pac)
+            
     def menu_items(self):
         return [
             {'url':self.url(self.context.__parent__[USER_FOLDER_NAME],'join'),
@@ -160,7 +168,7 @@
             elif len(results) == 1:
                 qty = u'I'
                 s = u''
-                self.redirect(self.url(results[0])+'/details')
+                self.redirect(self.url(results[0]))
             else:
                 qty = u'%s i' % len(results)
                 s = u's'
@@ -181,9 +189,18 @@
         self.redirect(self.url(self.context))
         
 class AddBooks(grok.View):
+    grok.context(Pac)
     
     invalid_isbns = []
     
+    def menu_items(self):
+        return [
+            {'url':self.url(self.context.__parent__[USER_FOLDER_NAME],'join'),
+                'text':u'join'},
+            {'url':'''http://circulante.incubadora.fapesp.br/''',
+                'text':u'about'},
+        ]
+
     def update(self, isbns=None):
         if isbns is not None:
             isbns = list(set(isbns.split()))

Modified: Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt	2007-08-15 01:37:17 UTC (rev 78828)
@@ -26,7 +26,7 @@
             </td>
             <td>
                 <dl>
-                    <dt><a tal:attributes="href python:view.url(item)+'/details'"
+                    <dt><a tal:attributes="href python:view.url(item)"
                         tal:content="item/filing_title">title goes here</a>
                     </dt>
                     <dd tal:content="item/creatorsLine">

Modified: Sandbox/luciano/kirbi/src/kirbi/tests/test_pac.txt
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/tests/test_pac.txt	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/tests/test_pac.txt	2007-08-15 01:37:17 UTC (rev 78828)
@@ -5,21 +5,21 @@
 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'k0001'
-  >>> 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'k0001']
+    >>> import grok
+    >>> grok.grok('kirbi')
+    >>> from kirbi.pac import Pac
+    >>> from kirbi.book import Book
+    >>> pac = Pac()
+    >>> pac.addBook(Book(u'Zero'))
+    u'k0001'
+    >>> 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'k0001']
 
 One of the books has ISBN but no Title, so it's put in the fetch queue::
-  # this test is broken
-  # >>> pac.pending_isbns
-  # ['9780670030583']
+    # XXX: revise this test to the new Pac API
+    # >>> pac.pending_isbns
+    # ['9780670030583']

Modified: Sandbox/luciano/kirbi/src/kirbi/user.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/user.py	2007-08-15 01:25:25 UTC (rev 78827)
+++ Sandbox/luciano/kirbi/src/kirbi/user.py	2007-08-15 01:37:17 UTC (rev 78828)
@@ -87,8 +87,13 @@
     grok.name('index')
     def update(self, query=None):
         self.results_title = '%d users' % len(self.context)
+
+class Login(grok.View):
+    grok.context(UserFolder)
+    def render(self):
+        return 'This should log you in...'
     
-class Register(grok.AddForm):
+class Join(grok.AddForm):
     grok.context(UserFolder)
     """User registration form"""
     



More information about the Checkins mailing list