示例#1
0
def change_indices_type():

    selected_indices = request.args['selected_indices']
    plot_type = request.args['plot_type']
    User.set_user_session_data(session.get('user_id'), "selected_indices",
                               selected_indices)
    graphJSON = create_indices_plot(plot_type)

    return graphJSON
示例#2
0
def save():
    if request.method == 'POST':
        names = request.form["names"]
        email = request.form["email"]
        age = request.form["age"]
        try:
            User.create(names=names, email=email, age=age)
            return jsonify({"response": "Saved"})
        except IntegrityError:
            return jsonify({"response": "User already exists"})
    else:
        return jsonify({"response": "No data was sent"})
示例#3
0
def profile():
    session['logged_in'] = True
    if session.get('logged_in'):

        user_details = User.get_user_details(session.get('user_id'))

        return render_template('profile.html', user_details=user_details)

    else:
        return redirect(url_for('login'))
示例#4
0
def delete(id):
    if request.method == 'DELETE':
        try:
            user = User.get(User.id == id)
            user.delete_instance()
            return jsonify({"response": "Deleted Successfully"})
        except User.DoesNotExist:
            return jsonify({"response": "User Does Not Exist"})
    else:
        return jsonify({"response": "Failed To Delete"})
示例#5
0
def all():
    users = User.select()
    users_list = []
    for item in users:
        users_list.append({
            "id": item.id,
            "names": item.names,
            "email": item.email,
            "age": item.age
        })
    return jsonify(users_list)
示例#6
0
def fetch_user(id):
    try:
        item = User.get(User.id == id)
        return jsonify({
            "id": item.id,
            "names": item.names,
            "email": item.email,
            "age": item.age
        })
    except User.DoesNotExist:
        return jsonify({"response": "User does not exists"})
示例#7
0
def verify_user(username, password):
    '''API users verify decorator'''
    config = ConfigParser.ConfigParser()
    metaConfig = recursiveSearchFile(project_abdir, '*metaConfig.ini')[0]
    config.read(metaConfig)
    dbconfig = {
        'host': config.get('META', 'host'),
        'port': int(config.get('META', 'port')),
        'user': config.get('META', 'user'),
        'passwd': config.get('META', 'pwd'),
        'db': config.get('META', 'db'),
        'charset': 'utf8'
    }

    db = MySQL(dbconfig)
    sql = "select id,name,password_hash from users where name = '{username}'".format(
        username=username)
    db.query(sql)
    info = db.fetchOneRow()
    db.close()

    check_user = User(id=info[0], name=info[1], password_hash=info[2])

    if not check_user or not check_user.verify_password(password):
        error_msg = "[action]:verify user" \
                    "[status]:FAIL" \
                    "[username]:{username}" \
                    "[verify status]:{status}".format(username=check_user.name,
                                                      status=check_user.verify_password(password))
        logger.error(error_msg)
        return False

    exec_info = "[action]:verify user" \
                "[status]:OK" \
                "[username]:{username}".format(username=username)
    logger.info(exec_info)
    return True
示例#8
0
def update(id):
    if request.method == 'POST':
        names = request.form["names"]
        email = request.form["email"]
        age = request.form["age"]
        try:
            user = User.get(User.id == id)
            user.names = names
            user.email = email
            user.age = age
            user.save()
            return jsonify({"response": "Updated Successfully"})
        except User.DoesNotExist:
            return jsonify({"response": "User Does Not Exist"})
    else:
        return jsonify({"response": "Wrong Request"})
示例#9
0
def indices():
    if session.get('logged_in'):
        bar = create_indices_plot("Scatter")
        # get unique indices
        records_list = IndicesModel.get_indices()

        # get pre selected indices list
        selected_indices = User.get_user_session_data(session.get('user_id'),
                                                      "selected_indices")
        selected_indices_list = ""
        if selected_indices is not None and len(selected_indices) > 0:
            selected_indices_list = selected_indices[0]

        return render_template('reports/indices.html',
                               plot=bar,
                               unique_indices=records_list,
                               selected_indices_list=selected_indices_list)
    else:
        return redirect(url_for('login'))
示例#10
0
def signup():

    msg = ''
    if request.method == 'POST' and 'first_name' in request.form and 'email' in request.form and 'password' in request.form:

        first_name = request.form['first_name']
        last_name = request.form['last_name']
        email = request.form['email']
        password = request.form['password']

        result = User(first_name, last_name, email, password).create_account()

        if result <= 0:
            msg = 'Registration failed, please try again.'
            return render_template("signup.html", msg=msg)
        else:
            return redirect(url_for('login'))

    return render_template("signup.html")
示例#11
0
def login():

    msg = ''
    if request.method == 'POST' and 'email' in request.form and 'password' in request.form:
        # Create variables for easy access
        email = request.form['email']
        password = request.form['password']

        # verify user
        account = User.verify_user(email, password)

        if account:
            # Create session data
            session['logged_in'] = True
            session['user_name'] = account[1]
            session['user_id'] = account[4]
            # Redirect to home page
            return redirect(url_for('index'))
        else:
            # Account doesnt exist or username/password incorrect
            msg = 'Incorrect username/password!'
            return render_template("login.html", msg=msg)

    return render_template("login.html", msg='')
示例#12
0
    def get_indices_plot_data(cls, user_id):

        db_conn = DBConnection.get_connection()
        db_cursor = db_conn.cursor()

        try:

            query = """ CREATE TEMPORARY TABLE temp_table(
            		   entry_date DATE
            		 );
            	 	 insert into temp_table
            		 select entry_date from indices_data where index_id=1
            		 intersect
            		 select entry_date from indices_data where index_id=2
            		 intersect
            		 select entry_date from indices_data where index_id=3
					 intersect
            		 select entry_date from indices_data where index_id=4
					 intersect
            		 select entry_date from indices_data where index_id=5
					 intersect
            		 select entry_date from indices_data where index_id=6
					 intersect
            		 select entry_date from indices_data where index_id=7
					 intersect
            		 select entry_date from indices_data where index_id=9
					 intersect
            		 select entry_date from indices_data where index_id=13
					 intersect
            		 select entry_date from indices_data where index_id=14;

            		 SELECT ind.index_symbol,TO_CHAR(idata.entry_date :: DATE, 'dd/mm/yyyy') AS "entry_date",
                     ROUND(idata.adj_close,2) AS "adj_close" FROM  indices ind JOIN indices_data idata
                     ON ind.id = idata.index_id
            		 WHERE idata.entry_date IN (SELECT DISTINCT entry_date FROM temp_table)
                     ORDER BY index_symbol, idata.entry_date ASC """

            db_cursor.execute(query)
            records_list = db_cursor.fetchall()

            df_indices_data = pd.DataFrame(
                records_list,
                columns=["index_symbol", "entry_date", "adj_close"])
            df_indices_data['adj_close'] = df_indices_data['adj_close'].astype(
                float)

            # get user session data
            user_session_list = User.get_user_session_data(
                user_id, "selected_indices")
            if user_session_list is not None and len(user_session_list) > 0:
                selected_indices_list = user_session_list[0]
                selected_indices_list = selected_indices_list.split("_")
                df_indices_data = df_indices_data.loc[df_indices_data[
                    'index_symbol'].isin(selected_indices_list)]

            return df_indices_data

        except (Exception, psycopg2.Error) as error:
            raise ErrorFound(error)

        finally:
            db_conn.close()