Created
February 7, 2013 02:09
-
-
Save gregorynicholas/4727815 to your computer and use it in GitHub Desktop.
Pretty prints a mongoengine.Document.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pprint_doc(doc, level=1): | |
| '''Pretty prints a `mongoengine.Document`.''' | |
| body = ['<', type(doc).__name__, ':'] | |
| # for field in sorted(doc._fields, key=lambda f: f.number): | |
| for key, field in doc._fields.iteritems(): | |
| value = doc[key] | |
| if value is not None: | |
| body.append('\n%s%s: %s' % (' '.join([' ' for idx in range(level)]), key, repr(value))) | |
| body.append('>') | |
| return ''.join(body) |
class PPrintMixin should inherit from object, mongoengine will inspect and will raise an AttributeError because of no __class__ attribute
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With a few tweaks to idea and implementation: