Move remaining stuff in manage.py to application.
This commit is contained in:
parent
38da04a412
commit
7aee85c08f
47
manage.py
47
manage.py
@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
from flask.ext.script import Manager
|
|
||||||
from flask.ext.migrate import Migrate, MigrateCommand, stamp
|
|
||||||
|
|
||||||
from accountant import app, db
|
|
||||||
|
|
||||||
from accountant.api.models.users import User
|
|
||||||
|
|
||||||
manager = Manager(app)
|
|
||||||
|
|
||||||
migrate = Migrate(app, db)
|
|
||||||
|
|
||||||
manager.add_command('db', MigrateCommand)
|
|
||||||
|
|
||||||
|
|
||||||
@manager.command
|
|
||||||
def initdb():
|
|
||||||
""" Create the database ans stamp it. """
|
|
||||||
|
|
||||||
tables = db.engine.table_names()
|
|
||||||
|
|
||||||
if len(tables) > 1 and 'alembic_version' not in tables:
|
|
||||||
exit("Database already initialized.")
|
|
||||||
|
|
||||||
db.metadata.create_all(bind=db.engine)
|
|
||||||
stamp()
|
|
||||||
print("Database created.")
|
|
||||||
|
|
||||||
user_manager = Manager(usage="Manage users.")
|
|
||||||
|
|
||||||
manager.add_command('user', user_manager)
|
|
||||||
|
|
||||||
|
|
||||||
@user_manager.command
|
|
||||||
def add(email, password):
|
|
||||||
""" Add a new user. """
|
|
||||||
user = User()
|
|
||||||
user.email = email
|
|
||||||
user.password = User.hash_password(password)
|
|
||||||
|
|
||||||
db.session.add(user)
|
|
||||||
|
|
||||||
print("User '%s' successfully added." % email)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
manager.run()
|
|
Loading…
Reference in New Issue
Block a user