[Checkins] SVN: Sandbox/luciano/kirbi/src/kirbi/ implemented buttons to add book from PAC to collection

Luciano Ramalho luciano at ramalho.org
Mon Aug 20 19:07:48 EDT 2007


Log message for revision 79057:
  implemented buttons to add book from PAC to collection
  

Changed:
  U   Sandbox/luciano/kirbi/src/kirbi/app.py
  U   Sandbox/luciano/kirbi/src/kirbi/app_templates/master.pt
  U   Sandbox/luciano/kirbi/src/kirbi/collection.py
  U   Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt
  U   Sandbox/luciano/kirbi/src/kirbi/static/master.css

-=-
Modified: Sandbox/luciano/kirbi/src/kirbi/app.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/app.py	2007-08-20 22:55:34 UTC (rev 79056)
+++ Sandbox/luciano/kirbi/src/kirbi/app.py	2007-08-20 23:07:47 UTC (rev 79057)
@@ -136,20 +136,25 @@
         #XXX: change this method to use our UserFolder and User class instead
         #     of PrincipalFolder and InternalPrincipal
         login = data['login']
-        title = data.get('name') or login # name is blank or None, use login
-        self.context.collections[login] = Collection(title)
+        if login in self.context.collections: # duplicate login name
+            ### XXX: find out how to display this message in the form template
+            msg = u'Duplicate login. Please choose a different one.'
+            self.redirect(self.url()+'?'+urlencode({'error_msg':msg}))
+        else:
+            title = data.get('name') or login # if name is blank or None, use login
+            self.context.collections[login] = Collection(title)
+        
+            # add principal to principal folder
+            pau = getUtility(IAuthentication)
+            principals = pau['principals']
+            principals[login] = InternalPrincipal(login, data['password'],
+                                                  data['name'])
     
-        # add principal to principal folder
-        pau = getUtility(IAuthentication)
-        principals = pau['principals']
-        principals[login] = InternalPrincipal(login, data['password'],
-                                              data['name'])
-
-        # assign role to principal
-        role_manager = IPrincipalRoleManager(self.context)
-        role_manager.assignRoleToPrincipal('kirbi.Owner', 
-                               principals.prefix + login)
-        self.redirect(self.url('login')+'?'+urlencode({'login':login}))
+            # assign role to principal
+            role_manager = IPrincipalRoleManager(self.context)
+            role_manager.assignRoleToPrincipal('kirbi.Owner', 
+                                   principals.prefix + login)
+            self.redirect(self.url('login')+'?'+urlencode({'login':login}))
         
 class CollectionsFolder(grok.Container):
     pass

Modified: Sandbox/luciano/kirbi/src/kirbi/app_templates/master.pt
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/app_templates/master.pt	2007-08-20 22:55:34 UTC (rev 79056)
+++ Sandbox/luciano/kirbi/src/kirbi/app_templates/master.pt	2007-08-20 23:07:47 UTC (rev 79057)
@@ -78,6 +78,8 @@
         
       </div>
     </div>
+    <div class="error_msg" tal:condition="exists:request/error_msg"
+       tal:content="request/error_msg" />
     <div class="content">
       <div metal:define-slot="content">
         Your content here...

Modified: Sandbox/luciano/kirbi/src/kirbi/collection.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/collection.py	2007-08-20 22:55:34 UTC (rev 79056)
+++ Sandbox/luciano/kirbi/src/kirbi/collection.py	2007-08-20 23:07:47 UTC (rev 79057)
@@ -60,8 +60,15 @@
         cover_name = 'covers/large/'+book.__name__+'.jpg'
         return self.static.get(cover_name,
                                self.static['covers/small-placeholder.jpg'])()
-        
 
+class AddFromPac(grok.View):
+    def render(self,manifestation_id,camefrom):
+        pac = grok.getSite()['pac']
+        book = pac[manifestation_id]
+        item = Item(book.__name__)
+        self.context.addItem(item)
+        self.redirect(camefrom)    
+
 class AddBookItems(grok.View):
 
     invalid_isbns = []
@@ -100,7 +107,7 @@
                 # Redirect to collection if nothing is pending and we came from
                 # a refresh (i.e. this is not the first visit to the form)
                 self.redirect(self.url(self.context))
-
+                
     def getInvalidISBNs(self):
         if self.invalid_isbns:
             return '\n'.join(self.invalid_isbns)

Modified: Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt	2007-08-20 22:55:34 UTC (rev 79056)
+++ Sandbox/luciano/kirbi/src/kirbi/pac_templates/index.pt	2007-08-20 23:07:47 UTC (rev 79057)
@@ -11,19 +11,31 @@
 
     <h3 tal:content="view/results_title">999 items matched the query</h3>
     <table tal:condition="view/results">
-        <tr tal:repeat="item view/results">
-            <th align="right" tal:content="repeat/item/number" />
+        <tr tal:repeat="manif view/results">
+            <th align="right" tal:content="repeat/manif/number" />
             <td align="center">
+                <a tal:attributes="name manif/__name__">
+                <form method="post" tal:attributes="action
+                    string:${view/application_url}/u/${request/principal/id}/addfrompac">
+                    <input type="hidden" name="manifestation_id"
+                        tal:attributes="value manif/__name__">
+                    <input type="hidden" name="camefrom"
+                        tal:attributes="value string:${view/url}#${manif/__name__}">
+                    <input type="submit" value="+" title="add to my collection" >
+                </form>
+                </a>
+            </td>
+            <td align="center">
                 <img class="cover"
-                     tal:attributes="src python:view.coverUrl(item)"
+                     tal:attributes="src python:view.coverUrl(manif)"
                      height="53" />
             </td>
             <td>
                 <dl>
-                    <dt><a tal:attributes="href python:view.url(item)"
-                        tal:content="item/filing_title">title goes here</a>
+                    <dt><a tal:attributes="href python:view.url(manif)"
+                        tal:content="manif/filing_title">title goes here</a>
                     </dt>
-                    <dd tal:content="item/creatorsLine">
+                    <dd tal:content="manif/creatorsLine">
                     </dd>
                 </dl>
             </td>

Modified: Sandbox/luciano/kirbi/src/kirbi/static/master.css
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/static/master.css	2007-08-20 22:55:34 UTC (rev 79056)
+++ Sandbox/luciano/kirbi/src/kirbi/static/master.css	2007-08-20 23:07:47 UTC (rev 79057)
@@ -145,6 +145,11 @@
     color: red;
 }
 
+.error_msg {
+    color: red;
+    padding: 5px;
+}
+
 form .row {
     clear: both;
     margin: 3px;



More information about the Checkins mailing list