Can read and write the database now!
This commit is contained in:
parent
d023307ccd
commit
9d54ae67db
@ -18,7 +18,7 @@ class Response(db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
likert_result = db.Column(db.Integer, nullable=False)
|
likert_result = db.Column(db.Integer, nullable=False)
|
||||||
notes = db.Column(db.String(200))
|
notes = db.Column(db.String(200))
|
||||||
date_created = db.Column(db.DateTime, default=datetime.utcnow)
|
date_created = db.Column(db.DateTime, default=datetime.today())
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return "<Task %r>" % self.id
|
return "<Task %r>" % self.id
|
||||||
@ -31,18 +31,27 @@ with app.app_context():
|
|||||||
|
|
||||||
@app.route("/", methods=["GET", "POST"])
|
@app.route("/", methods=["GET", "POST"])
|
||||||
def testpage():
|
def testpage():
|
||||||
global data
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
data = request.form
|
likert_score = request.form["likertscale"]
|
||||||
print(data)
|
text_input = request.form["feedback"]
|
||||||
return redirect(url_for("datapage"))
|
print("new response: {likert_score_1} {text_input_1}".format(likert_score_1 = likert_score, text_input_1 = text_input))
|
||||||
|
new_response = Response(likert_result = likert_score, notes = text_input)
|
||||||
|
|
||||||
|
try:
|
||||||
|
db.session.add(new_response)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect("/") #url_for("datapage")
|
||||||
|
except:
|
||||||
|
return "There was a problem while adding the response to the Database"
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"layout1.html"
|
"layout1.html"
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route("/data")
|
@app.route("/data")
|
||||||
def datapage():
|
def datapage():
|
||||||
|
responses = Response.query.order_by(Response.id).all()
|
||||||
return render_template(
|
return render_template(
|
||||||
"data.html",
|
"data.html",
|
||||||
value = str(data)
|
responses = responses
|
||||||
)
|
)
|
@ -54,6 +54,11 @@ h2,h3 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input, label {
|
||||||
|
display: block;
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
.likert input {
|
.likert input {
|
||||||
max-width: 250px;
|
max-width: 250px;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
@ -8,8 +8,14 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h2>Task number 1</h2>
|
<h2>Task number 1 responses</h2>
|
||||||
<p>The Likertscale value is: {{ value }}</p>
|
{% for response in responses%}
|
||||||
|
<p>Likert score:</p>
|
||||||
|
{{response.likert_result}}
|
||||||
|
<p>Feedback:</p>
|
||||||
|
{{response.notes}}
|
||||||
|
<p>-------------------------------------------------------------------------</p>
|
||||||
|
{% endfor %}
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}"" />
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}"" /> <!-- styles.css {{ url_for('static', filename='styles.css')}}-->
|
||||||
<title>Testform</title>
|
<title>Testform</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -38,16 +38,10 @@
|
|||||||
<label><input name="likertscale" type="radio" value="5" /><span>I like it a lot</span></label>
|
<label><input name="likertscale" type="radio" value="5" /><span>I like it a lot</span></label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="likercontainer">
|
<label for="feedback">Additional Feedback: </label>
|
||||||
<div class="likert">
|
<textarea id="feedback" name="feedback" rows="3" cols="30" maxlength="200"></textarea>
|
||||||
<label><input name="likertscale2" type="radio" value="1" /><span>I dont like it at all</span></label>
|
|
||||||
<label><input name="likertscale2" type="radio" value="2" /><span>I dont like it</span></label>
|
<p><input id="submitbutton" type = "submit" value = "submit";"/></p>
|
||||||
<label><input name="likertscale2" type="radio" value="3" /><span>I am indifferent</span></label>
|
|
||||||
<label><input name="likertscale2" type="radio" value="4" /><span>I like it</span></label>
|
|
||||||
<label><input name="likertscale2" type="radio" value="5" /><span>I like it a lot</span></label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p><input type = "submit" value = "submit";"/></p>
|
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -54,6 +54,11 @@ h2,h3 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input, label {
|
||||||
|
display: block;
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
.likert input {
|
.likert input {
|
||||||
max-width: 250px;
|
max-width: 250px;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
Loading…
Reference in New Issue
Block a user