Roger Haase avatar Roger Haase committed 0fbb432

improve display of archive member list, right align size, omit directories, remove T from timestamp

Comments (0)

Files changed (2)

MoinMoin/converter/_table.py

 from __future__ import absolute_import, division
 
 from MoinMoin.util.tree import moin_page
+from emeraldtree import ElementTree as ET
+
+WORDBREAK_LEN = 30
 
 class TableMixin(object):
     """
     Mixin to support building a DOM table.
     """
+    def add_numeric_class (self, cell, table_cell):
+        """
+        Add numeric class attribute if cell is numeric.
+        """
+        try:
+            float(cell)
+            table_cell.attrib[moin_page('class')] = 'moin-integer'
+        except:
+            pass
+
     def build_dom_table(self, rows, head=None, cls=None):
         """
         Build a DOM table with data from <rows>.
         if head is not None:
             table_head = moin_page.table_header()
             table_row = moin_page.table_row()
-            for cell in head:
-                table_cell = moin_page.table_cell(children=[cell, ])
+            for idx, cell in enumerate(head):
+                table_cell = moin_page.table_cell(children=[cell, ],)
+                if rows:
+                    # add "align: right" to heading cell if cell in first data row is numeric
+                    self.add_numeric_class(rows[0][idx], table_cell)
                 table_row.append(table_cell)
             table_head.append(table_row)
             table.append(table_head)
         for row in rows:
             table_row = moin_page.table_row()
             for cell in row:
-                table_cell = moin_page.table_cell(children=[cell, ])
+                if isinstance(cell, ET.Node) and isinstance(cell[0], unicode) and \
+                    len(cell[0].split()) == 1 and len(cell[0]) > WORDBREAK_LEN:
+                    # avoid destroying table layout by applying special styling to cells with long file name hyperlinks
+                    table_cell = moin_page.table_cell(children=[cell, ], attrib={moin_page.class_: 'moin-wordbreak'})
+                else:
+                    table_cell = moin_page.table_cell(children=[cell, ],)
+                    self.add_numeric_class(cell, table_cell)
                 table_row.append(table_cell)
             table_body.append(table_row)
         table.append(table_body)

MoinMoin/converter/archive_in.py

         return cls()
 
     def process_name(self, member_name):
+        name = unicode(member_name, 'utf-8')
         attrib = {
-            xlink.href: Iri(scheme='wiki', authority='', path='/'+self.item_name, query=u'do=get&member={0}'.format(member_name)),
+            xlink.href: Iri(scheme='wiki', authority='', path='/'+self.item_name, query=u'do=get&member={0}'.format(name)),
         }
-        return moin_page.a(attrib=attrib, children=[member_name, ])
+        return moin_page.a(attrib=attrib, children=[name, ])
 
     def process_datetime(self, dt):
-        return dt.isoformat()
+        return unicode(dt.isoformat(' '))
 
     def process_size(self, size):
         return unicode(size)
                          self.process_datetime(dt),
                          self.process_name(name),
                         ) for size, dt, name in contents]
-            table = self.build_dom_table(contents, head=[_("Size"), _("Date"), _("Name")], cls='zebra')
+            table = self.build_dom_table(contents, head=[_("Size"), _("Timestamp"), _("Name")], cls='zebra')
             body = moin_page.body(children=(table, ))
             return moin_page.page(children=(body, ))
         except ArchiveException as err:
             rows = []
             tf = tarfile.open(fileobj=fileobj, mode='r')
             for tinfo in tf.getmembers():
-                rows.append((
-                    tinfo.size,
-                    datetime.utcfromtimestamp(tinfo.mtime),
-                    tinfo.name,
-                ))
+                if tinfo.isfile():
+                    # display only normal files, not directories
+                    rows.append((
+                        tinfo.size,
+                        datetime.utcfromtimestamp(tinfo.mtime),
+                        tinfo.name,
+                    ))
             return rows
         except tarfile.TarError as err:
             raise ArchiveException(str(err))
             rows = []
             zf = zipfile.ZipFile(fileobj, mode='r')
             for zinfo in zf.filelist:
-                rows.append((
-                    zinfo.file_size,
-                    datetime(*zinfo.date_time), # y,m,d,h,m,s
-                    zinfo.filename,
-                ))
+                if not (zinfo.file_size == 0 and zinfo.filename.endswith('/')):
+                    # display only normal files, not directories
+                    rows.append((
+                        zinfo.file_size,
+                        datetime(*zinfo.date_time), # y,m,d,h,m,s
+                        zinfo.filename,
+                    ))
             return rows
         except (RuntimeError, zipfile.BadZipfile) as err:
             # RuntimeError is raised by zipfile stdlib module in case of
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.