changeset 55:47acf12d01e1

merge commit
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 18 Nov 2010 08:19:06 -0800
parents 0e2b9e0507c5 (current diff) a2f09d749a3f (diff)
children 0cc1af24602b
files decoupage/formats.py
diffstat 2 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/formats.py
+++ b/decoupage/formats.py
@@ -7,16 +7,17 @@ try:
 except ImportError:
   import simplejson as json
 
 # TODO: convert this to a class
 def format_json(data):
 
   # fix datetime
   for f in data['files']:
-    f['modified'] = f['modified'].ctime()
+    if 'modified' in f:
+      f['modified'] = f['modified'].ctime()
 
   return 'application/json', json.dumps(data['files'])
   
 class RSS(object):
 
   def __init__(self, n=10):
     pass
--- a/decoupage/web.py
+++ b/decoupage/web.py
@@ -128,16 +128,17 @@ class Decoupage(object):
         path = request.path_info.strip('/')
         directory = os.path.join(self.directory, path)
         path = '/%s' % path
         
         # get the configuraton
         conf = self.conf(path)
 
         ### build data dictionary
+        # TODO: separate these out into several formatters
         files = self.filedata(path, directory, conf)
         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
@@ -203,34 +204,44 @@ class Decoupage(object):
             raise
 
         # return response
         return Response(content_type='text/html', body=res)
 
 
     ### internal methods
 
-    def filedata(self, path, directory, conf):
+    def filedata(self, path, directory, conf=None):
+        conf = conf or {}
         files = []
-
-        for i in os.listdir(directory):
+        filenames = os.listdir(directory)
+        for i in filenames:
             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,
                           'size': os.path.getsize(filepath),
                           'modified': modified,
-                          'description': conf.get(i.lower(), None),
                           'type': filetype})
         
         # TODO: deal with other links in conf
+        for i in conf:
+            if i in filenames or i.startswith('/'):
+                continue
+            if i.startswith('http://') or i.startswith('https://'):
+                files.append({'path': i,
+                              'name': i,
+                              'type': link})
+            
+        for f in files:
+            f['description'] = conf.get(f['name'].lower(), None)
 
         return files
 
     def conf(self, path, cascade=None):
         """returns configuration dictionary appropriate to a path"""
         if cascade is None:
             cascase = self.cascade