changeset 100:82ee67b95a0c

sort by index order now works
author Jeff Hammel <k0scist@gmail.com>
date Tue, 23 Aug 2016 19:30:03 -0700
parents 2c7c4fda1a14
children 747c7e337c56
files decoupage/web.py setup.py
diffstat 2 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/web.py	Tue Aug 23 18:11:39 2016 -0700
+++ b/decoupage/web.py	Tue Aug 23 19:30:03 2016 -0700
@@ -34,6 +34,16 @@
 transformers = transformers()
 string = (str, unicode)
 
+class FileSorter(object):
+    def __init__(self, *keys):
+        self.keys = keys
+    def __call__(self, item):
+        try:
+            index = self.keys.index(item['name'])
+        except ValueError:
+            index = len(self.keys)
+        return (index, item['name'].lower(), item['name'])
+
 
 class Decoupage(object):
 
@@ -45,6 +55,7 @@
                  'template': 'index.html', # XXX see below
                  'template_directories': '', # list of directories to look for templates
                  'charset': 'utf-8', # content encoding for index.html files; -> `Content-Type: text/html; charset=ISO-8859-1`
+                 'file_sorter': FileSorter
                  }
 
     def __init__(self, **kw):
@@ -247,6 +258,13 @@
 
     ### internal methods
 
+    def file_sort_key(filename, keys):
+        try:
+            index = keys.index(filename)
+        except ValueError:
+            index = len(keys)
+        return (index, filename.lower(), filename)
+
     def filedata(self, path, directory, conf=None):
         conf = conf or OrderedDict()
         files = []
@@ -282,16 +300,21 @@
                 data['size'] =  os.path.getsize(filepath)
             files.append(data)
 
-        # TODO: deal with other links in conf
         for i in conf:
 
             if i in filenames or i.startswith('/'):
                 continue
+            # TODO: deal with other links in conf;
+            # this actually doesn't work because the ':' is magical to .ini files
             if i.startswith('http://') or i.startswith('https://'):
                 files.append({'path': i,
                               'name': i,
                               'type': link})
 
+        # TODO: sort files
+        files = sorted(files, key=self.file_sorter(*conf.keys()))
+
+        # get the description
         for f in files:
             f['description'] = conf.get(f['name'], None)
 
--- a/setup.py	Tue Aug 23 18:11:39 2016 -0700
+++ b/setup.py	Tue Aug 23 19:30:03 2016 -0700
@@ -6,7 +6,7 @@
 except IOError:
     description = ''
 
-version = '0.13.3'
+version = '0.14.0'
 
 setup(name='decoupage',
       version=version,
@@ -26,7 +26,7 @@
           'Paste',
           'PasteScript',
           'genshi',
-          'martINI>=0.4',
+          'martINI>=0.4.2',
           'contenttransformer>=0.3.3',
           'PyRSS2Gen',
          ],