Mercurial > hg > decoupage
changeset 52:a2f09d749a3f
work towards refactor letting links (and maybe other things in the future) dwell in a decoupage namespace
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 16 Nov 2010 21:14:25 -0800 |
parents | 8002dcdb8e82 |
children | 47acf12d01e1 |
files | decoupage/formats.py decoupage/web.py |
diffstat | 2 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/decoupage/formats.py Wed Nov 03 18:41:42 2010 -0700 +++ b/decoupage/formats.py Tue Nov 16 21:14:25 2010 -0800 @@ -7,7 +7,8 @@ # 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'])
--- a/decoupage/web.py Wed Nov 03 18:41:42 2010 -0700 +++ b/decoupage/web.py Tue Nov 16 21:14:25 2010 -0800 @@ -133,6 +133,7 @@ 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 } @@ -208,10 +209,11 @@ ### 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): @@ -222,10 +224,19 @@ '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