[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Views/Browser - Contents.py:1.15 main.pt:1.17

runyaga runyaga@thisbox.com
Tue, 3 Dec 2002 12:43:48 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv8535

Modified Files:
	Contents.py main.pt 
Log Message:
added getSize which could be called formatSize
and unit tests to make sure they appear properly.
exposed this in pagetemplate



=== Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Contents.py 1.14 => 1.15 ===
--- Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Contents.py:1.14	Tue Dec  3 11:14:09 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Contents.py	Tue Dec  3 12:43:48 2002
@@ -48,6 +48,8 @@
             if title:
                 info['title'] = title
 
+            info['size'] = getSize(item[1])
+
             created = dc.created
             if created is not None:
                 info['created'] = formatTime(created)
@@ -82,10 +84,29 @@
 
         return self._index()
 
+# Below is prime material for localization.
+# We are a touchpoint that should contact the personalization
+# service so that users can see datetime and decimals
+
 def formatTime(in_date):
     format='%m/%d/%Y'
     undefined=u'N/A'
     if hasattr(in_date, 'strftime'):
        return in_date.strftime(format)
     return undefined
+
+def getSize(obj):
+    try:
+        size=int(obj.getSize())
+    except (AttributeError, ValueError):
+        return u'N/A'
+
+    result = u''
+    if size < 1024:
+        result = "1 KB"
+    elif size > 1048576:
+        result = "%0.02f MB" % (size / 1048576.0)
+    else:
+        result = "%d KB" % (size / 1024.0)
+    return result
 


=== Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/main.pt 1.16 => 1.17 ===
--- Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/main.pt:1.16	Tue Dec  3 11:15:07 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/main.pt	Tue Dec  3 12:43:48 2002
@@ -21,9 +21,9 @@
         <thead> 
           <tr>
             <th>&nbsp;</th>
-            <th>&nbsp;</th>
             <th>Name</th>
             <th>Title</th>
+            <th>Size</th>
             <th>Created</th>
             <th>Modified</th>
           </tr>
@@ -48,15 +48,14 @@
                  tal:content="structure item/icon|default"
                  >
               </a> 
-            </td>
-            <td> 
               <a href="#" 
                  tal:attributes="href 
                                  string:${url}/@@SelectedManagementView.html"
                  tal:content="item/id"
                  >foo</a> 
-            </td>          
+            </td>
             <td><span tal:content="item/title|default">&nbsp;</span></td>
+            <td><span tal:content="item/size|default">&nbsp;</span></td>
             <td><span tal:define="created item/created|default"
                       tal:content="created">&nbsp;</span></td>
             <td><span tal:define="modified item/modified|default"