annotate decoupage/formats.py @ 57:884e6c805208

more stubbing for RSS
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 18 Nov 2010 08:32:45 -0800
parents 47acf12d01e1
children 1275124ed767
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
0e2b9e0507c5 add documentation for formats and a stub
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
1 """
0e2b9e0507c5 add documentation for formats and a stub
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
2 pluggable formats for directory listings
0e2b9e0507c5 add documentation for formats and a stub
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
3 """
0e2b9e0507c5 add documentation for formats and a stub
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
4
49
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 try:
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 import json as json
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 except ImportError:
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import simplejson as json
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9
54
0e2b9e0507c5 add documentation for formats and a stub
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
10 # TODO: convert this to a class
49
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 def format_json(data):
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 # fix datetime
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 for f in data['files']:
52
a2f09d749a3f work towards refactor letting links (and maybe other things in the future) dwell in a decoupage namespace
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
15 if 'modified' in f:
a2f09d749a3f work towards refactor letting links (and maybe other things in the future) dwell in a decoupage namespace
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
16 f['modified'] = f['modified'].ctime()
49
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 return 'application/json', json.dumps(data['files'])
ac693b8df32c add idea of formats and json format
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19
54
0e2b9e0507c5 add documentation for formats and a stub
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
20 class RSS(object):
57
884e6c805208 more stubbing for RSS
Jeff Hammel <jhammel@mozilla.com>
parents: 55
diff changeset
21 """RSS for indices"""
54
0e2b9e0507c5 add documentation for formats and a stub
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
22
57
884e6c805208 more stubbing for RSS
Jeff Hammel <jhammel@mozilla.com>
parents: 55
diff changeset
23 def __init__(self, app, count=10, cascade=False):
884e6c805208 more stubbing for RSS
Jeff Hammel <jhammel@mozilla.com>
parents: 55
diff changeset
24 self.app = app # the decoupage
884e6c805208 more stubbing for RSS
Jeff Hammel <jhammel@mozilla.com>
parents: 55
diff changeset
25 self.count = count
884e6c805208 more stubbing for RSS
Jeff Hammel <jhammel@mozilla.com>
parents: 55
diff changeset
26 self.cascade = cascade
884e6c805208 more stubbing for RSS
Jeff Hammel <jhammel@mozilla.com>
parents: 55
diff changeset
27
884e6c805208 more stubbing for RSS
Jeff Hammel <jhammel@mozilla.com>
parents: 55
diff changeset
28 def __call__(self, request, data):
54
0e2b9e0507c5 add documentation for formats and a stub
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
29 pass