Example #1
0
def create_app():
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    static_dir = os.path.join(BASE_DIR, 'static')
    templates_dir = os.path.join(BASE_DIR, 'templates')

    app = Flask(__name__,
                static_folder=static_dir,
                template_folder=templates_dir)
    app.register_blueprint(blueprint=login, url_prefix='/user')
    app.register_blueprint(blueprint=classroom, url_prefix='/user')
    app.register_blueprint(blueprint=student, url_prefix='/user')
    app.register_blueprint(blueprint=role, url_prefix='/user')
    app.register_blueprint(blueprint=permissions, url_prefix='/user')
    app.register_blueprint(blueprint=user, url_prefix='/user')

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/fkquanxian'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # 设置session密钥
    app.config['SECRET_KEY'] = 'secret_key'

    db.init_app(app=app)

    with app.app_context():
        db.create_all()

    return app
Example #2
0
 def setUp(self):
     db.create_all()
     user = User(
         username="******",
         email="*****@*****.**",
         password="******",
     )
     db.session.add(user)
     db.session.commit()
Example #3
0
def db(app, request):
    """Session-wide test database."""
    if os.path.exists(TESTDB_PATH):
        os.unlink(TESTDB_PATH)

    def teardown():
        _db.drop_all()
        os.unlink(TESTDB_PATH)

    _db.app = app
    _db.create_all()
    setup.setup_db()

    request.addfinalizer(teardown)
    return _db
Example #4
0
def reset():
    if request.method == 'POST':
        r = request.json
        if 'password' in r.keys():
            if r['password'] == 'fangopass':
                with app.app_context():
                    db.drop_all()
                    db.create_all()
                    db.session.commit()
            else:
                return pass_needed()
        else:
            return pass_needed()

        return {'result': 'all clear'}, 200
Example #5
0
def load_dummy():
    if request.method == 'POST':
        r = request.json
        if 'password' in r.keys():
            if r['password'] == 'fangopass':
                with app.app_context():
                    db.drop_all()
                    db.create_all()
                    db.session.commit()

                    # with app.app_context():
                    load_dummy_on_db()

            else:
                return pass_needed()
        else:
            return pass_needed()

        return {'result': 'dummy loaded'}, 200
Example #6
0
def connect_db():
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////var/clusters/test.db'
    db.init_app(app)
    with app.app_context():
        # db.drop_all() # DEBUG uncomment to reset tables for debugging
        db.create_all()
Example #7
0
 def run(self, **kwargs):
     db.drop_all()
     db.create_all()
Example #8
0
 def run(self, **kwargs):
     print(db.engine)
     print(dir(db.engine))
     db.engine.echo = True
     r = db.create_all()
     print(r)
Example #9
0
import jwt

app = Flask(__name__,
            static_url_path="",
            template_folder="templates",
            static_folder="static")
api = Api(app)
database_file = "mysql://*****:*****@localhost/queries"
app.config["SQLALCHEMY_DATABASE_URI"] = database_file
app.secret_key = "any"
app.permanent_session_lifetime = timedelta(seconds=35)

db.init_app(app)

with app.app_context():
    db.create_all()


@app.route('/')
def sample():
    username = None
    if 'username' in session:
        username = session['username']
        return redirect('/login')
    return render_template("photography.html")


from routes.views import LoginPage

api.add_resource(LoginPage, '/login', endpoint="LoginPage")
Example #10
0
 def run(self, **kwargs):
     db.drop_all()
     db.create_all()
Example #11
0
 def run(self, **kwargs):
     print(db.engine)
     print(dir(db.engine))
     db.engine.echo = True
     r = db.create_all()
     print(r)
Example #12
0
def create_table():
    db.create_all()
from flask_sqlalchemy import SQLAlchemy
from models.models import db, ma
from controllers.pruebacontroller import prueba
from controllers.UserController import usuarios
from controllers.TodoController import tareas
from controllers.ProductController import products
from flask_cors import CORS

app = Flask(__name__)
app.config.from_object(DevelopmentConfig)
db.init_app(app)
ma.init_app(app)

CORS(app)


@app.route('/')
def index():
    return jsonify({'response': 'welcome to flask api'})


app.register_blueprint(prueba)
app.register_blueprint(usuarios)
app.register_blueprint(tareas)
app.register_blueprint(products)

if __name__ == '__main__':
    with app.app_context():
        db.create_all()  #crea todas las tablas que no esten creadas en la BD
    app.run(host='0.0.0.0', port=int(PORT), debug=True)
Example #14
0
# coding: utf-8
from flask import Flask, render_template
from flask.ext.restless import APIManager
from flask.ext.admin import Admin, BaseView
from flask.ext.admin.contrib.sqla import ModelView
from models.models import db,  User, Scheme, ChangeLog

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['UPLOAD_FOLDER'] = '/uploads'
db.init_app(app)
db.app = app
db.create_all()
admin = Admin(app)
admin.add_view(ModelView(User, db.session))
admin.add_view(ModelView(Scheme, db.session))
admin.add_view(ModelView(ChangeLog, db.session))


@app.route('/')
def home():
    return render_template('index.html')

manager = APIManager(app, flask_sqlalchemy_db=db)
manager.create_api(Scheme, methods=['GET', 'POST'])
manager.create_api(User, methods=['PUT', 'GET', 'POST'])
manager.create_api(ChangeLog, methods=['GET'])


if __name__ == '__main__':
    app.debug = True