comparison decoupage/web.py @ 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 d327dc7de14f
children 0cc1af24602b
comparison
equal deleted inserted replaced
51:8002dcdb8e82 52:a2f09d749a3f
131 131
132 # get the configuraton 132 # get the configuraton
133 conf = self.conf(path) 133 conf = self.conf(path)
134 134
135 ### build data dictionary 135 ### build data dictionary
136 # TODO: separate these out into several formatters
136 files = self.filedata(path, directory, conf) 137 files = self.filedata(path, directory, conf)
137 data = {'path': path, 'files': files, 'request': request } 138 data = {'path': path, 'files': files, 'request': request }
138 139
139 # defaults; TODO: make this better 140 # defaults; TODO: make this better
140 # there shouldn't need to be defaults; 141 # there shouldn't need to be defaults;
206 return Response(content_type='text/html', body=res) 207 return Response(content_type='text/html', body=res)
207 208
208 209
209 ### internal methods 210 ### internal methods
210 211
211 def filedata(self, path, directory, conf): 212 def filedata(self, path, directory, conf=None):
213 conf = conf or {}
212 files = [] 214 files = []
213 215 filenames = os.listdir(directory)
214 for i in os.listdir(directory): 216 for i in filenames:
215 filepath = os.path.join(directory, i) 217 filepath = os.path.join(directory, i)
216 filetype = 'file' 218 filetype = 'file'
217 if os.path.isdir(filepath): 219 if os.path.isdir(filepath):
218 filetype = 'directory' 220 filetype = 'directory'
219 modified = os.path.getmtime(filepath) 221 modified = os.path.getmtime(filepath)
220 modified = datetime.fromtimestamp(modified) 222 modified = datetime.fromtimestamp(modified)
221 files.append({'path' : '%s/%s' % (path.rstrip('/'), i), 223 files.append({'path' : '%s/%s' % (path.rstrip('/'), i),
222 'name': i, 224 'name': i,
223 'size': os.path.getsize(filepath), 225 'size': os.path.getsize(filepath),
224 'modified': modified, 226 'modified': modified,
225 'description': conf.get(i.lower(), None),
226 'type': filetype}) 227 'type': filetype})
227 228
228 # TODO: deal with other links in conf 229 # TODO: deal with other links in conf
230 for i in conf:
231 if i in filenames or i.startswith('/'):
232 continue
233 if i.startswith('http://') or i.startswith('https://'):
234 files.append({'path': i,
235 'name': i,
236 'type': link})
237
238 for f in files:
239 f['description'] = conf.get(f['name'].lower(), None)
229 240
230 return files 241 return files
231 242
232 def conf(self, path, cascade=None): 243 def conf(self, path, cascade=None):
233 """returns configuration dictionary appropriate to a path""" 244 """returns configuration dictionary appropriate to a path"""