Skip to content
Browse files

Allow a post to iterate over its insides (with json pretty-printing)

  • Loading branch information...
1 parent e26e146 commit 33fafeac70f6c292d9b569dd5057f2a77b8764e6 @dustin dustin committed Jun 30, 2009
Showing with 15 additions and 5 deletions.
  1. +15 −5 models.py
View
20 models.py
@@ -45,10 +45,20 @@ class Post(db.Model):
def id(self):
return baseN(abs(hash(self.created)), 36)[0:6]
-
- def __str__(self):
+
+ def __iter__(self):
+ out = []
if self.form_data:
- return simplejson.dumps(self.form_data, indent=2)[2:-2]
+ for k,v in self.form_data.items():
+ try:
+ outval = simplejson.dumps(simplejson.loads(v), indent=2)
+ except ValueError:
+ outval = v
+ out.append((k, outval))
else:
- return self.body
-
+ out = (('body', self.body),)
+
+ return iter(out)
+
+ def __str__(self):
+ return '\n'.join("%s = %s" % (k,v) for k,v in self)

0 comments on commit 33fafea

Please sign in to comment.
Something went wrong with that request. Please try again.