Permalink
Browse files

added createadmin command to manage.py; tweaked createadmin.py to run…

… correctly
  • Loading branch information...
1 parent cdc6837 commit eacedd2e5635789bb9cef90e990d38f2a26c7283 @Laukei Laukei committed Nov 2, 2016
Showing with 12 additions and 3 deletions.
  1. +5 −0 manage.py
  2. +7 −3 sdv/createadmin.py
View
@@ -4,6 +4,7 @@
from flask_script import Manager
from sdv import app
from sdv.createdb import init_db
+from sdv.createadmin import init_admin
from tools import copy_assets
import os
@@ -15,6 +16,10 @@ def createdb(drop_all=False):
"""Initialise Database."""
init_db(drop_all)
+@manager.command
+def createadmin(drop_all=False):
+ """Initialise Admin DB."""
+ init_admin()
@manager.command
def test():
View
@@ -1,12 +1,13 @@
# creates db for SDV-Summary
-import config
+from config import config
from flask import Flask
import os
import sys
from werkzeug.security import generate_password_hash
app = Flask(__name__)
-app.config.from_object(os.environ['SDV_APP_SETTINGS'].strip('"'))
+config_name = os.environ.get('SDV_APP_SETTINGS', 'development')
+app.config.from_object(config[config_name])
if sys.version_info >= (3, 0):
raw_input = input
@@ -35,7 +36,7 @@ def generate_admin():
c.execute('CREATE TABLE admin (id '+idcode+', username TEXT, password TEXT)')
connection.commit()
-if __name__ == "__main__":
+def init_admin():
a = raw_input('Generate database? (y/n): ')
if a == 'y':
generate_admin()
@@ -51,3 +52,6 @@ def generate_admin():
c.execute("INSERT INTO admin (username, password) VALUES ("+sqlesc+","+sqlesc+")",(user, generate_password_hash(password)))
connection.commit()
+if __name__ == "__main__":
+ init_admin()
+

0 comments on commit eacedd2

Please sign in to comment.