Просмотр исходного кода

Finally added a command to install flaskbb with a admin user.

sh4nks 11 лет назад
Родитель
Сommit
f04c2f3715
2 измененных файлов с 38 добавлено и 16 удалено
  1. 5 4
      flaskbb/utils/populate.py
  2. 33 12
      manage.py

+ 5 - 4
flaskbb/utils/populate.py

@@ -8,6 +8,7 @@
     :copyright: (c) 2014 by the FlaskBB Team.
     :copyright: (c) 2014 by the FlaskBB Team.
     :license: BSD, see LICENSE for more details.
     :license: BSD, see LICENSE for more details.
 """
 """
+from datetime import datetime
 from collections import OrderedDict
 from collections import OrderedDict
 
 
 from flaskbb.user.models import User, Group
 from flaskbb.user.models import User, Group
@@ -138,8 +139,8 @@ def create_admin_user(username, password, email):
     Creates the administrator user
     Creates the administrator user
     """
     """
     admin_group = Group.query.filter_by(admin=True).first()
     admin_group = Group.query.filter_by(admin=True).first()
-    user = User(username=username, password=password, email=email)
-    user.primary_group_id = admin_group.id
+    user = User(username=username, password=password, email=email,
+                date_joined=datetime.utcnow(), primary_group_id=admin_group.id)
     user.save()
     user.save()
 
 
 
 
@@ -154,11 +155,11 @@ def create_welcome_forum():
 
 
     user = User.query.filter_by(id=1).first()
     user = User.query.filter_by(id=1).first()
 
 
-    category = Forum(is_category=True, title="My Category")
+    category = Category(title="My Category", position=1)
     category.save()
     category.save()
 
 
     forum = Forum(title="Welcome", description="Your first forum",
     forum = Forum(title="Welcome", description="Your first forum",
-                  parent_id=category.id)
+                  category_id=category.id)
     forum.save()
     forum.save()
 
 
     topic = Topic(title="Welcome!")
     topic = Topic(title="Welcome!")

+ 33 - 12
manage.py

@@ -11,13 +11,13 @@
     :license: BSD, see LICENSE for more details.
     :license: BSD, see LICENSE for more details.
 """
 """
 from flask import current_app
 from flask import current_app
-from flask.ext.script import Manager, Shell, Server
+from flask.ext.script import Manager, Shell, Server, prompt, prompt_pass
 from flask.ext.migrate import MigrateCommand
 from flask.ext.migrate import MigrateCommand
 
 
 from flaskbb import create_app
 from flaskbb import create_app
 from flaskbb.extensions import db
 from flaskbb.extensions import db
-from flaskbb.utils.populate import (create_test_data, create_admin_user,
-                                    create_welcome_forum, create_default_groups)
+from flaskbb.utils.populate import (create_test_data, create_welcome_forum,
+                                    create_admin_user, create_default_groups)
 
 
 # Use the development configuration if available
 # Use the development configuration if available
 try:
 try:
@@ -57,7 +57,7 @@ def dropdb():
 
 
 @manager.command
 @manager.command
 def createall():
 def createall():
-    """Creates the database with some example content."""
+    """Creates the database with some testing content."""
 
 
     # Just for testing purposes
     # Just for testing purposes
     db.drop_all()
     db.drop_all()
@@ -66,23 +66,44 @@ def createall():
     create_test_data()
     create_test_data()
 
 
 
 
-# TODO: Implement this...
-@manager.command
-def create_admin():
+@manager.option('-u', '--username', dest='username')
+@manager.option('-p', '--password', dest='password')
+@manager.option('-e', '--email', dest='email')
+def create_admin(username, password, email):
     """Creates the admin user"""
     """Creates the admin user"""
 
 
-    db.create_all()
-    create_admin_user()
+    username = prompt("Username")
+    email = prompt("A valid email address")
+    password = prompt_pass("Password")
 
 
+    create_admin_user(username, email, password)
 
 
-@manager.command
-def create_default_data():
-    """This should be created by every flaskbb installation"""
 
 
+@manager.option('-u', '--username', dest='username')
+@manager.option('-p', '--password', dest='password')
+@manager.option('-e', '--email', dest='email')
+@manager.option('-d', '--dropdb', dest='dropdb', default=False)
+def initflaskbb(username, password, email, dropdb=False):
+    """Initializes FlaskBB with all necessary data"""
+
+    if dropdb:
+        app.logger.info("Dropping previous database...")
+        db.drop_all()
+
+    app.logger.info("Creating tables...")
     db.create_all()
     db.create_all()
+
+    app.logger.info("Creating default groups...")
     create_default_groups()
     create_default_groups()
+
+    app.logger.info("Creating admin user...")
+    create_admin(username, password, email)
+
+    app.logger.info("Creating welcome forum...")
     create_welcome_forum()
     create_welcome_forum()
 
 
+    app.logger.info("Congratulations! FlaskBB has been successfully installed")
+
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     manager.run()
     manager.run()