Format the codebase using Black (#2109)
This commit: 1. Formats all of our existing code using `black`. 2. Adds a note about using `black` to `CONTRIBUTING.rst`. 3. Runs `black --check` as part of CI (failing builds that aren't properly formatted).
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
from mongoengine import *
|
||||
|
||||
connect('tumblelog')
|
||||
connect("tumblelog")
|
||||
|
||||
|
||||
class Comment(EmbeddedDocument):
|
||||
content = StringField()
|
||||
name = StringField(max_length=120)
|
||||
|
||||
|
||||
class User(Document):
|
||||
email = StringField(required=True)
|
||||
first_name = StringField(max_length=50)
|
||||
last_name = StringField(max_length=50)
|
||||
|
||||
|
||||
class Post(Document):
|
||||
title = StringField(max_length=120, required=True)
|
||||
author = ReferenceField(User)
|
||||
@@ -18,54 +21,57 @@ class Post(Document):
|
||||
comments = ListField(EmbeddedDocumentField(Comment))
|
||||
|
||||
# bugfix
|
||||
meta = {'allow_inheritance': True}
|
||||
meta = {"allow_inheritance": True}
|
||||
|
||||
|
||||
class TextPost(Post):
|
||||
content = StringField()
|
||||
|
||||
|
||||
class ImagePost(Post):
|
||||
image_path = StringField()
|
||||
|
||||
|
||||
class LinkPost(Post):
|
||||
link_url = StringField()
|
||||
|
||||
|
||||
Post.drop_collection()
|
||||
|
||||
john = User(email='jdoe@example.com', first_name='John', last_name='Doe')
|
||||
john = User(email="jdoe@example.com", first_name="John", last_name="Doe")
|
||||
john.save()
|
||||
|
||||
post1 = TextPost(title='Fun with MongoEngine', author=john)
|
||||
post1.content = 'Took a look at MongoEngine today, looks pretty cool.'
|
||||
post1.tags = ['mongodb', 'mongoengine']
|
||||
post1 = TextPost(title="Fun with MongoEngine", author=john)
|
||||
post1.content = "Took a look at MongoEngine today, looks pretty cool."
|
||||
post1.tags = ["mongodb", "mongoengine"]
|
||||
post1.save()
|
||||
|
||||
post2 = LinkPost(title='MongoEngine Documentation', author=john)
|
||||
post2.link_url = 'http://tractiondigital.com/labs/mongoengine/docs'
|
||||
post2.tags = ['mongoengine']
|
||||
post2 = LinkPost(title="MongoEngine Documentation", author=john)
|
||||
post2.link_url = "http://tractiondigital.com/labs/mongoengine/docs"
|
||||
post2.tags = ["mongoengine"]
|
||||
post2.save()
|
||||
|
||||
print('ALL POSTS')
|
||||
print("ALL POSTS")
|
||||
print()
|
||||
for post in Post.objects:
|
||||
print(post.title)
|
||||
#print '=' * post.title.count()
|
||||
# print '=' * post.title.count()
|
||||
print("=" * 20)
|
||||
|
||||
if isinstance(post, TextPost):
|
||||
print(post.content)
|
||||
|
||||
if isinstance(post, LinkPost):
|
||||
print('Link:', post.link_url)
|
||||
print("Link:", post.link_url)
|
||||
|
||||
print()
|
||||
print()
|
||||
|
||||
print('POSTS TAGGED \'MONGODB\'')
|
||||
print("POSTS TAGGED 'MONGODB'")
|
||||
print()
|
||||
for post in Post.objects(tags='mongodb'):
|
||||
for post in Post.objects(tags="mongodb"):
|
||||
print(post.title)
|
||||
print()
|
||||
|
||||
num_posts = Post.objects(tags='mongodb').count()
|
||||
num_posts = Post.objects(tags="mongodb").count()
|
||||
print('Found %d posts with tag "mongodb"' % num_posts)
|
||||
|
||||
Reference in New Issue
Block a user