INQ-24 js done, questions are from db now

This commit is contained in:
s441471 2018-12-12 09:12:36 +01:00
parent 978107b551
commit 870c4ff09d
2 changed files with 14 additions and 7 deletions

11
App.py
View File

@ -25,7 +25,12 @@ def home():
@app.route('/student',methods=['GET', 'POST'])
def student():
return render_template('student.html')
db = sqlite3.connect(DATABASE)
#db.row_factory = sql.Row
db_conn = db.cursor()
db_conn.execute("select * from question;")
questions = db_conn.fetchall()
return render_template('student.html', questions=questions)
@app.route('/ask', methods=['POST'])
def do_add():
@ -62,8 +67,8 @@ def upvote():
db = sqlite3.connect(DATABASE)
#db.row_factory = sql.Row
db_conn = db.cursor()
db_conn.execute("select * from user;")
print(db_conn.fetchone())
db_conn.execute("select * from question;")
print(db_conn.fetchall())
return '200'

View File

@ -19,9 +19,9 @@
<div class="card-content">
<span class="card-title card-title__body">Pytania studentów</span>
<ul id="questions-list">
<li>Pytanie odnośnie zadania domowego 12.11.2018<span class="counter"><i class="btn-thumb-up material-icons">thumb_up</i><span>12</span></span></li>
<li>Zagadnienia dotyczące egzaminu<span class="counter"><i class="btn-thumb-up material-icons">thumb_up</i><span>45</span></span></li>
<li>Czy 12 listopada odbędą się zajęcia?<span class="counter"><i class="btn-thumb-up material-icons">thumb_up</i><span>157</span></span></li>
{% for question in questions %}
<li>{{ question[3] }}<span class="counter"><i class="btn-thumb-up material-icons" id="{{ question[0] }}">thumb_up</i><span>{{ question[4] }}</span></span></li>
{% endfor %}
</ul>
</div>
</div>
@ -94,8 +94,10 @@
});
$('.btn-thumb-up').on('click', () => {
//alert(event.target.id)
var link = '/upvote/' + event.target.id;
$.ajax({
url: '/upvote',
url: link,
type: 'POST',
succes: function(response) {
alert(response)