changeset 79:a8a74f6bcf93

add some dates and fix some bugs!
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 05 Jul 2013 11:32:59 -0700
parents 5330cd62e179
children b01b6f6efd4e
files decoupage/formatters.py decoupage/templates/index.html setup.py
diffstat 3 files changed, 34 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/formatters.py	Tue Apr 16 00:45:31 2013 -0700
+++ b/decoupage/formatters.py	Fri Jul 05 11:32:59 2013 -0700
@@ -2,6 +2,7 @@
 
 import random
 import sys
+from datetime import datetime
 from fnmatch import fnmatch
 from pkg_resources import iter_entry_points
 
@@ -76,11 +77,12 @@
                         _files.append(f)
                         break
             else:
-                # use only files where the description is not None
-                if f['description'] is not None:
+                # use only files where the title or description is not None
+                if (f['description'] is not None) or (f.get('title') is not None):
                     _files.append(f)
         data['files'] = _files
 
+
 class Sort(FormatterBase):
     """
     determines how to sort the files in a directory;
@@ -200,6 +202,31 @@
                 f['title'] = f['description']
                 f['description'] = None
 
+class Datestamp(FormatterBase):
+    """
+    datestamps for modified times
+    """
+    # TODO:
+    # - currently we only do modified; TODO: created/modified/etc
+    # - use modified dateutil from bitsyblog;
+    # - e.g. javascript for things like e.g. "Yesterday"
+    key = 'modified'
+
+    def __init__(self, string):
+        FormatterBase.__init__(self, string)
+
+        # check formatting string now v later
+        datetime.now().strftime(self._string)
+
+    def __call__(self, request, data):
+        for f in data['files']:
+            _datetime = f.get(self.key)
+            try:
+                datestamp = _datetime.strftime(self._string)
+                f['datestamp'] = datestamp
+            except:
+                raise # TODO: handle more better
+
 class Links(FormatterBase):
     """
     allow list of links per item:
@@ -207,7 +234,7 @@
     """
 
     fatal = False
-    defaults = { 'separator': ';' }
+    defaults = {'separator': ';'}
 
 
     def __call__(self, request, data):
@@ -285,6 +312,7 @@
     def __call__(self, request, data):
         data['include'] = self.include
 
+###
 
 def formatters():
     formatters = {}
--- a/decoupage/templates/index.html	Tue Apr 16 00:45:31 2013 -0700
+++ b/decoupage/templates/index.html	Fri Jul 05 11:32:59 2013 -0700
@@ -22,6 +22,7 @@
               <a href="${link['link']}">${link['text']}</a>
             </span>
           </py:if>
+          <time class="date" py:if="'datestamp' in f">${f['datestamp']}</time>
       </li>
     </ul>
    </body>
--- a/setup.py	Tue Apr 16 00:45:31 2013 -0700
+++ b/setup.py	Fri Jul 05 11:32:59 2013 -0700
@@ -6,7 +6,7 @@
 except IOError:
     description = ''
 
-version = '0.11.2'
+version = '0.12'
 
 setup(name='decoupage',
       version=version,
@@ -47,6 +47,7 @@
       [decoupage.formatters]
       all = decoupage.formatters:All
       css = decoupage.formatters:CSS
+      datestamp = decoupage.formatters:Datestamp
       describe = decoupage.formatters:FilenameDescription
       icon = decoupage.formatters:Favicon
       ignore = decoupage.formatters:Ignore