<commit_before>from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.security import Security, SQLAlchemyUserDatastore
from flask.ext.security.utils import encrypt_password as encrypt


db = SQLAlchemy()

# After defining `db`, import auth models due to
# circular dependency.
from mhn.auth.models import User, Role
user_datastore = SQLAlchemyUserDatastore(db, User, Role)


def create_app():
    mhn = Flask(__name__)
    mhn.config.from_object('config')

    # Registering app on db instance.
    db.init_app(mhn)

    # Setup flask-security for auth.
    Security(mhn, user_datastore)

    # Registering blueprints.
    from api.views import api
    mhn.register_blueprint(api)

    from ui.views import ui
    mhn.register_blueprint(ui)

    return mhn


def create_clean_db():
    """
    Use from a python shell to create a fresh database.
    """
    mhn = create_app()
    mhn.test_request_context().push()
    db.create_all()
    user_datastore.create_user(email=mhn.config.get('SUPERUSER_EMAIL'),
                               password=encrypt(mhn.config.get('SUPERUSER_PASSWORD')))
    db.session.commit()<commit_msg>Adding admin role to default user.<commit_after>from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.security import Security, SQLAlchemyUserDatastore
from flask.ext.security.utils import encrypt_password as encrypt


db = SQLAlchemy()

# After defining `db`, import auth models due to
# circular dependency.
from mhn.auth.models import User, Role
user_datastore = SQLAlchemyUserDatastore(db, User, Role)


def create_app():
    mhn = Flask(__name__)
    mhn.config.from_object('config')

    # Registering app on db instance.
    db.init_app(mhn)

    # Setup flask-security for auth.
    Security(mhn, user_datastore)

    # Registering blueprints.
    from api.views import api
    mhn.register_blueprint(api)

    from ui.views import ui
    mhn.register_blueprint(ui)

    from auth.views import auth
    mhn.register_blueprint(auth)

    return mhn


def create_clean_db():
    """
    Use from a python shell to create a fresh database.
    """
    mhn = create_app()
    mhn.test_request_context().push()
    db.create_all()
    superuser = user_datastore.create_user(
            email=mhn.config.get('SUPERUSER_EMAIL'),
            password=encrypt(mhn.config.get('SUPERUSER_PASSWORD')))
    adminrole = user_datastore.create_role(name='admin', description='')
    user_datastore.add_role_to_user(superuser, adminrole)
    db.session.commit()
{'fraction_non_alphanumeric': 0.09251968503937008, 'fraction_numerical': 0.0, 'mean_word_length': 3.6623853211009174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2721946', 'n_tokens_mistral': 838, 'n_tokens_neox': 795, 'n_words': 196}