comparison decoupage/formats.py @ 59:07cf168aa98c

make formats classes that can take arguments
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 21 Nov 2010 13:23:34 -0800
parents 1275124ed767
children cf18ea0313f9
comparison
equal deleted inserted replaced
58:1275124ed767 59:07cf168aa98c
5 try: 5 try:
6 import json as json 6 import json as json
7 except ImportError: 7 except ImportError:
8 import simplejson as json 8 import simplejson as json
9 9
10 # TODO: convert this to a class 10 class JSON(object):
11 def format_json(data): 11 """
12 JSON format for index pages
13 just (basically) return the data
14 """
12 15
13 # fix datetime 16 def __init__(self, app, foo):
14 for f in data['files']: 17 self.app = app
15 if 'modified' in f:
16 f['modified'] = f['modified'].ctime()
17 18
18 return 'application/json', json.dumps(data['files']) 19 def __call__(self, request, data):
20
21 # fix datetime
22 for f in data['files']:
23 if 'modified' in f:
24 f['modified'] = f['modified'].ctime()
25
26 return 'application/json', json.dumps(data['files'])
19 27
20 class RSS(object): 28 class RSS(object):
21 """RSS for indices""" 29 """RSS for indices"""
22 30
23 def __init__(self, app, count=10, cascade=False): 31 def __init__(self, app, count=10, cascade=False):
24 self.app = app # the decoupage 32 self.app = app # the decoupage
25 self.count = count 33 self.count = int(count)
26 self.cascade = cascade 34 self.cascade = cascade
27 35
28 def __call__(self, request, data): 36 def __call__(self, request, data):
29 import pdb; pdb.set_trace() 37 import pdb; pdb.set_trace()