# HG changeset patch # User Jeff Hammel # Date 1472005803 25200 # Node ID 82ee67b95a0c3e3362b558638ed1aeb5e515ac3a # Parent 2c7c4fda1a144025977cb5e38bb8aaa59ad6143b sort by index order now works diff -r 2c7c4fda1a14 -r 82ee67b95a0c decoupage/web.py --- 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) diff -r 2c7c4fda1a14 -r 82ee67b95a0c setup.py --- 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', ],