Skip to content

Commit

Permalink
Allow a post to iterate over its insides (with json pretty-printing)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Jul 1, 2009
1 parent e26e146 commit 33fafea
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions models.py
Expand Up @@ -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.