changeset 48:af73a3fda723

add more metadata to files: modification time, type
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 03 Nov 2010 07:22:39 -0700
parents 0cfb84d788d6
children ac693b8df32c
files decoupage/web.py
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/web.py	Wed Oct 27 09:42:58 2010 -0700
+++ b/decoupage/web.py	Wed Nov 03 07:22:39 2010 -0700
@@ -7,8 +7,8 @@
 
 from contenttransformer.app import FileTypeTransformer
 from contenttransformer.app import transformers
+from datetime import datetime
 from formatters import formatters
-
 from genshi.builder import Markup
 from genshi.template import TemplateLoader
 from genshi.template.base import TemplateError
@@ -108,6 +108,7 @@
         """
         return response to a GET requst
         """
+        
         # ensure a sane path        
         path = request.path_info.strip('/')
         directory = os.path.join(self.directory, path)
@@ -121,6 +122,8 @@
         data = {'path': path, 'files': files, 'request': request }
 
         # defaults; TODO: make this better
+        # there shouldn't need to be defaults;
+        # iirc, genshi has a mode where these will default to None
         data['title'] = conf.get('/title')
         data['directory'] = directory
         data['include'] = None
@@ -165,7 +168,6 @@
                             break
                     else:
                         raise IOError("template %s not found" % template)
-                
         try:
             template = self.loader.load(template)
             res = template.generate(**data).render('html', doctype='html')
@@ -175,6 +177,7 @@
                 return self.fileserver(local_index)
             raise
 
+        # return response
         return Response(content_type='text/html', body=res)
 
 
@@ -183,15 +186,18 @@
     def filedata(self, path, directory, conf):
         files = []
 
-        # TODO: other items to add
-        # type: 'file' or 'directory'
-        # last_modified
-        # created
-
         for i in os.listdir(directory):
+            filepath = os.path.join(directory, i)
+            filetype = 'file'
+            if os.path.isdir(filepath):
+                filetype = 'directory'
+            modified = os.path.getmtime(filepath)
+            modified = datetime.fromtimestamp(modified)
             files.append({'path' : '%s/%s' % (path.rstrip('/'), i),
                           'name': i,
-                          'description': conf.get(i.lower(), None)})
+                          'modified': modified,
+                          'description': conf.get(i.lower(), None),
+                          'type': filetype})
         
         # TODO: deal with other links in conf