Browse Source

Added a way to insert more example topics and posts.

sh4nks 10 years ago
parent
commit
21d36758cd
2 changed files with 35 additions and 1 deletions
  1. 26 0
      flaskbb/utils/populate.py
  2. 9 1
      manage.py

+ 26 - 0
flaskbb/utils/populate.py

@@ -205,3 +205,29 @@ def create_test_data():
             post = Post()
             post.content = "Test Post"
             post.save(user=user2, topic=topic)
+
+
+def insert_mass_data():
+    """
+    Creates 100 topics in the first forum and each topic has 100 posts.
+    """
+    user1 = User.query.filter_by(id=1).first()
+    user2 = User.query.filter_by(id=2).first()
+    forum = Forum.query.filter_by(id=1).first()
+
+    # create 1000 topics
+    for i in range(1, 101):
+
+        # create a topic
+        topic = Topic()
+        post = Post()
+
+        topic.title = "Test Title %s" % i
+        post.content = "Test Content"
+        topic.save(post=post, user=user1, forum=forum)
+
+        # create 100 posts in each topic
+        for j in range(1, 100):
+            post = Post()
+            post.content = "Test Post"
+            post.save(user=user2, topic=topic)

+ 9 - 1
manage.py

@@ -23,7 +23,7 @@ from flaskbb import create_app
 from flaskbb.extensions import db
 from flaskbb.utils.populate import (create_test_data, create_welcome_forum,
                                     create_admin_user, create_default_groups,
-                                    create_default_settings,
+                                    create_default_settings, insert_mass_data,
                                     update_settings_from_fixture)
 
 # Use the development configuration if available
@@ -167,5 +167,13 @@ def initflaskbb(username=None, password=None, email=None):
     app.logger.info("Congratulations! FlaskBB has been successfully installed")
 
 
+@manager.command
+def insertmassdata():
+    """Warning: This can take a long time!.
+    Creates 100 topics and each topic contains 100 posts.
+    """
+    insert_mass_data()
+
+
 if __name__ == "__main__":
     manager.run()