示例#1
0
    def setUp(self):
        application.app.testing = True
        self.app = application.app.test_client()
        self.students_score_cache = Database(index=1, redis_host='localhost')
        self.exams_cache = Database(index=2, redis_host='localhost')

        self.students_score_cache.save_entry('test_student_id', 'exam_01',
                                             '9.0')
        self.students_score_cache.save_entry('test_student_id', 'exam_02',
                                             '7.0')
        self.exams_cache.save_entry('exam_01', 'test_student_id', '9.0')
        self.exams_cache.save_entry('exam_01', 'test_student_id_2', '7.0')
        self.exams_cache.save_entry('exam_02', 'test_student_id', '7.0')
示例#2
0
def register():
    db = Database()
    if request.method == 'POST':

        form = request.form
        email1 = form['email']
        email2 = form['email2']
        if email1 != email2:
            flash('Emails do not match', 'info')
            return redirect(url_for('views.register'))

        user = create_database_user(form['email'], form['password'],
                                    form['username'])

        if validateCharacters(user):
            if db.check_existing_users(user['name'], user['email']):
                flash('Invalid Username/Email', 'info')
                return redirect(url_for('views.register'))
            else:
                db.insert_new_user(user)
                session[USERKEY] = user['name']
                return redirect(url_for('views.home'))

        else:
            return redirect(url_for('views.register'))

    return render_template('register.html')
示例#3
0
 def setupDatabase(self):
     from collections import OrderedDict
     self.db = Database('chat-advance.db')
     if not self.db.createConnection():
         EventManager.trigger(Event('Database.databaseConnectionFail'))
         return
     if not self.db.isTableExist(DataCenter.TABLE_FRIENDS):
         self.db.createTable(DataCenter.TABLE_SERVERS, OrderedDict([('name', Database.TYPE_TEXT),
                             ('url', Database.TYPE_TEXT), ('port', Database.TYPE_TEXT)]))
示例#4
0
def create_app():
    global app, db
    app = Flask(__name__)
    setup_logging(app.logger)
    banner(app.logger, ' web ')
    app.config['SECRET_KEY'] = os.getenv('SECRET_KEY').encode()
    db = Database()

    @app.teardown_appcontext
    def shutdown_session(exception=None):
        db.session.remove()
示例#5
0
def login():

    db = Database()
    current_user = session.get(USERKEY, None)

    if request.method == 'POST':
        loginValues = request.form

        user = create_database_user(loginValues['emailInput'],
                                    loginValues['passwordInput'])
        isValid = db.validate_user(user)

        if isValid:
            session[USERKEY] = db.get_user_info(user)['name']
            return redirect(url_for('views.home'))
        else:
            flash('Invalid email/password')
            return redirect(url_for('views.login', user=current_user))

    return render_template('login.html', user=current_user)
示例#6
0
def db():
    """A test database that is clean at the start of each test.

    You'll probably also want to patch the db object that the code under test
    is using, such as by making another fixture like so:

    @pytest.fixture(name='db_')
    def web_user_db(db):
        web.user.db = db
        yield db

    """
    database = Database('postgres:///lds-callings-test', echo=False)

    # Drop and recreate all of the tables. If the schema changes enough, this
    # might not work (some leftover tables?). Worst case, just recreate it:
    # $ dropdb lds-callings-test
    # $ createdb lds-callings-test
    database.drop_all()
    database.create_all()
    try:
        yield database
    finally:
        database.cleanup()
示例#7
0
from flask import request, flash, redirect, render_template
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--num_to_render',
                    default=150,
                    help="Number of records to render",
                    type=int)
parser.add_argument('--save',
                    default=True,
                    help="True or False, save database",
                    type=bool)
args = vars(parser.parse_args())
print('args are : {}'.format(args))

db = Database()


def export_data():
    if args['save']:
        print('Saving apartment data...')
        db.export_to_csv(db.data)
        db.export_to_json(db.data)
    else:
        print("'Saving option is turned off. Run script with '--save=True'")


@app.route('/', methods=['GET', 'POST'])
def main():
    db.read()
    b = min(args['num_to_render'], db.data.shape[0])
import os
from flask import Flask

app = Flask(__name__, static_url_path='/static')

from flask_restful import Api

api = Api(app)

prod = os.getenv('PROD_MODE', default='false')
PROD_MODE = prod.lower() in (1, 't', 'true')
print('Production mode:', PROD_MODE)
import application.config
if PROD_MODE:
    print('Load production configuration')
    app.config.from_object(config.Production())
else:
    print('Load development configuration')
    app.config.from_object(config.Development())

from application.database import Database

db = Database(app)

import application.routes
示例#9
0
def create_app():
    global db
    db = Database()