Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
venv
*.pyc
.env
.venv
68 changes: 34 additions & 34 deletions blurbs.py

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import os


class Config(object):
DEBUG = False
TESTING = False
SECRET_KEY = '\xb7Fr\xbd7TQ\x7f9]\xafr\xf0\xa9\xe70Q\xbcY\xe8\xe8\x00v\xa6'
CSRF_ENABLED = True
#DATABASE_URI = 'sqlite:////tmp/badges.db'
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/badges.db'
DEBUG = False
TESTING = False
SECRET_KEY = "\xb7Fr\xbd7TQ\x7f9]\xafr\xf0\xa9\xe70Q\xbcY\xe8\xe8\x00v\xa6"
CSRF_ENABLED = True
# DATABASE_URI = 'sqlite:////tmp/badges.db'
SQLALCHEMY_DATABASE_URI = "sqlite:////tmp/badges.db"


class ProductionConfig(Config):
DEBUG = True
if 'DATABASE_URL' in os.environ.keys():
DATABASE_URI = os.environ['DATABASE_URL']
SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']
DEBUG = True
if "DATABASE_URL" in list(os.environ.keys()):
DATABASE_URI = os.environ["DATABASE_URL"]
SQLALCHEMY_DATABASE_URI = os.environ["DATABASE_URL"]


class DevelopmentConfig(Config):
DEBUG = True
DEBUG = True


class TestingConfig(Config):
TESTING = True
TESTING = True
238 changes: 134 additions & 104 deletions cosmoquiz_app.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# all the imports
#from __future__ import with_statement
#from contextlib import closing
from flask import Flask, request, session, make_response, g, redirect, url_for, abort, render_template, flash
# from __future__ import with_statement
# from contextlib import closing
from flask import (
Flask,
request,
session,
make_response,
g,
redirect,
url_for,
abort,
render_template,
flash,
)

import random
import os
Expand All @@ -17,128 +28,147 @@
from datetime import datetime



# configuration
#DATABASE = '/tmp/badges.db'
#USERNAME = 'admin'
#PASSWORD = 'default'
#SERVER_NAME = 'http://www.dancesportlife.com/cosmoquiz/'
#ROOT_PATH = '/home5/dancespo/public_html/cosmoquiz/'
#DEBUG = True
#SECRET_KEY = '\xb7Fr\xbd7TQ\x7f9]\xafr\xf0\xa9\xe70Q\xbcY\xe8\xe8\x00v\xa6'
#CSRF_ENABLED = True
# DATABASE = '/tmp/badges.db'
# USERNAME = 'admin'
# PASSWORD = 'default'
# SERVER_NAME = 'http://www.dancesportlife.com/cosmoquiz/'
# ROOT_PATH = '/home5/dancespo/public_html/cosmoquiz/'
# DEBUG = True
# SECRET_KEY = '\xb7Fr\xbd7TQ\x7f9]\xafr\xf0\xa9\xe70Q\xbcY\xe8\xe8\x00v\xa6'
# CSRF_ENABLED = True


# create application
app = Flask(__name__.split('.')[0])
app = Flask(__name__.split(".")[0])
app.config.from_object(__name__)
#app.config.from_object('config.DevelopmentConfig')
app.config.from_object('config.ProductionConfig')

#app.config.from_envvar('FLASKR_SETTINGS', silent=True)
# app.config.from_object('config.DevelopmentConfig')
app.config.from_object("config.ProductionConfig")

#app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
#app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/badges.db'
# app.config.from_envvar('FLASKR_SETTINGS', silent=True)

# app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/badges.db'


@app.route('/index')
@app.route('/')
@app.route("/index")
@app.route("/")
def start():
if ( ('results_computed' in session) and (session['results_computed']) ):
return (render_template('results.html',
blurb = blurbs.pick_blurb(session['skill_score_ndx_max'],session['self_id_score_ndx_max']),
skill=session['skill_label'],
skill_color = r.skill_colors(session['skill_score_ndx_max']),
selflabel=session['self_label'],
self_id_color = r.self_id_colors(session['self_id_score_ndx_max'])
))
else:
session['user_id'] = str(random.randint(1, 999999))

if app.config['DEBUG']:
print(session['user_id'])

return (render_template('index.html'))

@app.route('/q1')
if ("results_computed" in session) and (session["results_computed"]):
return render_template(
"results.html",
blurb=blurbs.pick_blurb(
session["skill_score_ndx_max"], session["self_id_score_ndx_max"]
),
skill=session["skill_label"],
skill_color=r.skill_colors(session["skill_score_ndx_max"]),
selflabel=session["self_label"],
self_id_color=r.self_id_colors(session["self_id_score_ndx_max"]),
)
else:
session["user_id"] = str(random.randint(1, 999999))

if app.config["DEBUG"]:
print((session["user_id"]))

return render_template("index.html")


@app.route("/q1")
def q1():
if app.config['DEBUG']:
print(session['user_id'])
return (render_template('question1.html'))

@app.route('/q2', methods=['post'])
if app.config["DEBUG"]:
print((session["user_id"]))
return render_template("question1.html")


@app.route("/q2", methods=["post"])
def q2():
data = request.form
q1 = data.getlist('id_name',type=float)
session['q1']= q1
return (render_template('question2.html'))
data = request.form
q1 = data.getlist("id_name", type=float)
session["q1"] = q1
return render_template("question2.html")

@app.route('/surveydetails')

@app.route("/surveydetails")
def surveydetails():
return (render_template('surveydetails.html'))
return render_template("surveydetails.html")


@app.route('/faq')
@app.route("/faq")
def faq():
return (render_template('faq.html'))
return render_template("faq.html")


@app.route('/results', methods=['post'])
@app.route("/results", methods=["post"])
def results():
session['q2'] = [ float(request.form['scientist']),
float(request.form['engineer']),
float(request.form['bp']),
float(request.form['artist']),
float(request.form['researcher']),
float(request.form['stats']),
float(request.form['jack']),
float(request.form['leader']),
float(request.form['ent']),
float(request.form['dev']),
float(request.form['ds']) ]

#Inserting database write instead of dump to file
result = Result(str(session['q1']).strip('[]'), str(session['q2']).strip('[]'), session['user_id'], datetime.utcnow(),str(request.remote_addr))

#UPDATE THIS!
db.session.add(result)
db.session.commit()

#need to compute results to display, everything stored in session
r.compute_results(session, app.config['DEBUG'])

session['results_computed'] = True
#need to return a block of text to

if app.config['DEBUG']:
print "++++++++"
print session['skill_label']
print session['self_label']
print session.keys(), '\n'
print request.remote_addr
print datetime.utcnow()

return (render_template('results.html',
blurb = blurbs.pick_blurb(session['skill_score_ndx_max'],session['self_id_score_ndx_max']),
skill=session['skill_label'],
skill_color = r.skill_colors(session['skill_score_ndx_max']),
selflabel=session['self_label'],
self_id_color = r.self_id_colors(session['self_id_score_ndx_max'])
))

@app.route('/reset')
session["q2"] = [
float(request.form["scientist"]),
float(request.form["engineer"]),
float(request.form["bp"]),
float(request.form["artist"]),
float(request.form["researcher"]),
float(request.form["stats"]),
float(request.form["jack"]),
float(request.form["leader"]),
float(request.form["ent"]),
float(request.form["dev"]),
float(request.form["ds"]),
]

# Inserting database write instead of dump to file
result = Result(
str(session["q1"]).strip("[]"),
str(session["q2"]).strip("[]"),
session["user_id"],
datetime.utcnow(),
str(request.remote_addr),
)

# UPDATE THIS!
db.session.add(result)
db.session.commit()

# need to compute results to display, everything stored in session
r.compute_results(session, app.config["DEBUG"])

session["results_computed"] = True
# need to return a block of text to

if app.config["DEBUG"]:
print("++++++++")
print((session["skill_label"]))
print((session["self_label"]))
print((list(session.keys()), "\n"))
print((request.remote_addr))
print((datetime.utcnow()))

return render_template(
"results.html",
blurb=blurbs.pick_blurb(
session["skill_score_ndx_max"], session["self_id_score_ndx_max"]
),
skill=session["skill_label"],
skill_color=r.skill_colors(session["skill_score_ndx_max"]),
selflabel=session["self_label"],
self_id_color=r.self_id_colors(session["self_id_score_ndx_max"]),
)


@app.route("/reset")
def reset():
for key in session.keys():
del(session[key])
for key in list(session.keys()):
del session[key]

session["results_computed"] = False

session['results_computed'] = False
if app.config["DEBUG"]:
print((list(session.keys())))

if app.config['DEBUG']:
print session.keys()

return (start())
return start()


if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
db.create_all()
app.run(host="0.0.0.0", port=port)

33 changes: 17 additions & 16 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
from flask_sqlalchemy import SQLAlchemy
#from flask.ext.sqlalchemy import SQLAlchemy

# from flask.ext.sqlalchemy import SQLAlchemy
# comment to make a change

from cosmoquiz_app import app

db = SQLAlchemy(app)

class Result(db.Model):
__tablename__ = 'results'

id = db.Column(db.Integer, primary_key=True)
session_id = db.Column(db.Integer)
q1 = db.Column(db.String)
q2 = db.Column(db.String)
email = db.Column(db.String)
date_added = db.Column(db.DateTime)
ip = db.Column(db.String)
class Result(db.Model):
__tablename__ = "results"

id = db.Column(db.Integer, primary_key=True)
session_id = db.Column(db.Integer)
q1 = db.Column(db.String)
q2 = db.Column(db.String)
email = db.Column(db.String)
date_added = db.Column(db.DateTime)
ip = db.Column(db.String)

def __init__(self, q1, q2, session_id, date_added, ip):
self.session_id = session_id
self.q1 = q1
self.q2 = q2
self.date_added = date_added
self.ip = ip
def __init__(self, q1, q2, session_id, date_added, ip):
self.session_id = session_id
self.q1 = q1
self.q2 = q2
self.date_added = date_added
self.ip = ip
29 changes: 21 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
Flask==0.9
Flask-SQLAlchemy==0.16
Jinja2==2.6
SQLAlchemy==0.7.9
Werkzeug==0.8.3
ipython==2.1.0
psycopg2==2.5.3
wsgiref==0.1.2
backcall==0.2.0
Flask==2.0.1
Flask-SQLAlchemy==2.1
greenlet==1.1.0
ipython==7.24.1
itsdangerous==2.0.1
jedi==0.18.0
Jinja2==3.0.1
MarkupSafe==2.0.1
matplotlib-inline==0.1.2
mypy-extensions==0.4.3
parso==0.8.2
pathspec==0.8.1
pexpect==4.8.0
psycopg2-binary==2.8.6
ptyprocess==0.7.0
Pygments==2.9.0
SQLAlchemy==1.3.24
traitlets==5.0.5
wcwidth==0.2.5
Werkzeug==2.0.1
Loading