diff 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
line wrap: on
line diff
--- a/decoupage/formats.py	Thu Nov 18 08:36:07 2010 -0800
+++ b/decoupage/formats.py	Sun Nov 21 13:23:34 2010 -0800
@@ -7,22 +7,30 @@
 except ImportError:
   import simplejson as json
 
-# TODO: convert this to a class
-def format_json(data):
+class JSON(object):
+  """
+  JSON format for index pages
+  just (basically) return the data
+  """
+
+  def __init__(self, app, foo):
+    self.app = app
 
-  # fix datetime
-  for f in data['files']:
-    if 'modified' in f:
-      f['modified'] = f['modified'].ctime()
+  def __call__(self, request, data):
 
-  return 'application/json', json.dumps(data['files'])
+    # fix datetime
+    for f in data['files']:
+      if 'modified' in f:
+        f['modified'] = f['modified'].ctime()
+
+    return 'application/json', json.dumps(data['files'])
   
 class RSS(object):
   """RSS for indices"""
 
   def __init__(self, app, count=10, cascade=False):
     self.app = app # the decoupage
-    self.count = count
+    self.count = int(count)
     self.cascade = cascade
 
   def __call__(self, request, data):