From 15d543c34fe681da15dbb42d9c0f8c51c0bc4248 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Tue, 5 Feb 2019 14:38:41 +0100 Subject: [PATCH 001/120] Add list.html --- templates/list.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 templates/list.html diff --git a/templates/list.html b/templates/list.html new file mode 100644 index 000000000..fb8238433 --- /dev/null +++ b/templates/list.html @@ -0,0 +1,12 @@ + + + + + + + Ask Mate + + + + + \ No newline at end of file From 70f354dff81640deca2f9c8d5120e457538a0cb0 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 10:59:58 +0100 Subject: [PATCH 002/120] Add gitignore --- .gitignore | 3 +++ server.py | 0 2 files changed, 3 insertions(+) create mode 100644 server.py diff --git a/.gitignore b/.gitignore index dbed2ff1f..9bd77adbd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ __pycache__/ *.py[cod] *$py.class +# VS Code +.vscode + # C extensions *.so diff --git a/server.py b/server.py new file mode 100644 index 000000000..e69de29bb From 9daf269688816b6440074c9e715e7f147122171a Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 11:04:06 +0100 Subject: [PATCH 003/120] Add requiremnts.txt --- requiremnts.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 requiremnts.txt diff --git a/requiremnts.txt b/requiremnts.txt new file mode 100644 index 000000000..d88bff86c --- /dev/null +++ b/requiremnts.txt @@ -0,0 +1,6 @@ +Click==7.0 +Flask==1.0.2 +itsdangerous==1.1.0 +Jinja2==2.10 +MarkupSafe==1.1.0 +Werkzeug==0.14.1 \ No newline at end of file From 9fb69387614c047aeba594b079d0c35bf775eb61 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 11:15:03 +0100 Subject: [PATCH 004/120] Implement server to run --- server.py | 16 ++++++++++++++++ templates/list.html | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index e69de29bb..6d053ea23 100644 --- a/server.py +++ b/server.py @@ -0,0 +1,16 @@ +from flask import Flask, render_template, redirect, url_for, request + +app = Flask(__name__) + + +@app.route('/') +@app.route('/list') +def route_list(): + return render_template('list.html') + + +if __name__ == "__main__": + app.run( + debug=True, + port=5000 + ) \ No newline at end of file diff --git a/templates/list.html b/templates/list.html index fb8238433..409429f9c 100644 --- a/templates/list.html +++ b/templates/list.html @@ -7,6 +7,6 @@ Ask Mate - +

Ask Mate

\ No newline at end of file From 64fed7d6c4efe7d9764c32421d0e7f8bc9587ab1 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 11:27:06 +0100 Subject: [PATCH 005/120] Add connection.py --- connection.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 connection.py diff --git a/connection.py b/connection.py new file mode 100644 index 000000000..caa0ab733 --- /dev/null +++ b/connection.py @@ -0,0 +1,34 @@ +import csv +from datetime import datetime + + +def read_file(filename): + with open(filename, "r", encoding='utf-8') as f: + reader_file = csv.DictReader(f) + datas = [] + for line in reader_file: + datas.append(dict(line)) + return datas + + +def sort_file(): + questions = read_file('sample_data/question.csv') + questions.sort(key=lambda line: line['submission_time'], reverse=True) + return questions + + +def formatted_file(): + sorted_questions = sort_file() + datas = [] + for question in sorted_questions: + ts = int(question['submission_time']) + question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') + datas.append(question) + return datas + +""" +def write_to_file(filename, user_story): + with open(filename, 'a', encoding='utf-8') as csvfile: + datas_to_export = csv.DictWriter(csvfile) + datas_to_export.writerow(user_story) +""" \ No newline at end of file From 84584d2a6b6028031513c0af7964839d0faccb4f Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 11:32:42 +0100 Subject: [PATCH 006/120] Add question table to list.html --- templates/list.html | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/templates/list.html b/templates/list.html index 409429f9c..6e558b118 100644 --- a/templates/list.html +++ b/templates/list.html @@ -1,12 +1,47 @@ + - - - + + + + + + + + + Ask Mate

Ask Mate

+ + + + + + + + + + + + + + + {% for question in questions %} + + + + + + + + + + {% endfor %} + +
IdSubmission timeView numberVote numberTitleMessageImage
{{ question['id'] }}{{ question['submission_time'] }}{{ question['view_number'] }}{{ question['vote_number'] }}{{ question['title'] }}{{ question['message'] }}h{{ question['image'] }}
+ \ No newline at end of file From 00683489f286374a8c63d720ce380f72f5bc6f70 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 12:27:10 +0100 Subject: [PATCH 007/120] Change route_list func --- server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 6d053ea23..f7f0394bf 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,5 @@ from flask import Flask, render_template, redirect, url_for, request +import connection app = Flask(__name__) @@ -6,7 +7,8 @@ @app.route('/') @app.route('/list') def route_list(): - return render_template('list.html') + stored_questions = connection.formatted_file() + return render_template('list.html', questions=stored_questions) if __name__ == "__main__": From 620bcbb4a265e9bf99d4139699548e67b963b32c Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 12:28:40 +0100 Subject: [PATCH 008/120] Add data_manager layer --- data_manager.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 data_manager.py diff --git a/data_manager.py b/data_manager.py new file mode 100644 index 000000000..e69de29bb From e6a39b03aaaef2d80c395c792732b2ef00071c57 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 12:32:45 +0100 Subject: [PATCH 009/120] Add data logic from connection to data_manager --- connection.py | 18 ------------------ data_manager.py | 18 ++++++++++++++++++ server.py | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/connection.py b/connection.py index caa0ab733..5a70e817d 100644 --- a/connection.py +++ b/connection.py @@ -1,5 +1,4 @@ import csv -from datetime import datetime def read_file(filename): @@ -11,24 +10,7 @@ def read_file(filename): return datas -def sort_file(): - questions = read_file('sample_data/question.csv') - questions.sort(key=lambda line: line['submission_time'], reverse=True) - return questions - - -def formatted_file(): - sorted_questions = sort_file() - datas = [] - for question in sorted_questions: - ts = int(question['submission_time']) - question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') - datas.append(question) - return datas - -""" def write_to_file(filename, user_story): with open(filename, 'a', encoding='utf-8') as csvfile: datas_to_export = csv.DictWriter(csvfile) datas_to_export.writerow(user_story) -""" \ No newline at end of file diff --git a/data_manager.py b/data_manager.py index e69de29bb..e442fec57 100644 --- a/data_manager.py +++ b/data_manager.py @@ -0,0 +1,18 @@ +import connection +from datetime import datetime + + +def sort_file(): + questions = connection.read_file('sample_data/question.csv') + questions.sort(key=lambda line: line['submission_time'], reverse=True) + return questions + + +def formatted_file(): + sorted_questions = sort_file() + datas = [] + for question in sorted_questions: + ts = int(question['submission_time']) + question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') + datas.append(question) + return datas \ No newline at end of file diff --git a/server.py b/server.py index f7f0394bf..9f9779e83 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,5 @@ from flask import Flask, render_template, redirect, url_for, request -import connection +import data_manager app = Flask(__name__) @@ -7,7 +7,7 @@ @app.route('/') @app.route('/list') def route_list(): - stored_questions = connection.formatted_file() + stored_questions = data_manager.formatted_file() return render_template('list.html', questions=stored_questions) From 5a6e612a5a5d0b1a854a4852b7be4fa4a17ae155 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 12:36:54 +0100 Subject: [PATCH 010/120] Change formatted func --- data_manager.py | 2 +- server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data_manager.py b/data_manager.py index e442fec57..275e036b4 100644 --- a/data_manager.py +++ b/data_manager.py @@ -8,7 +8,7 @@ def sort_file(): return questions -def formatted_file(): +def format_file(): sorted_questions = sort_file() datas = [] for question in sorted_questions: diff --git a/server.py b/server.py index 9f9779e83..52e2e696e 100644 --- a/server.py +++ b/server.py @@ -7,7 +7,7 @@ @app.route('/') @app.route('/list') def route_list(): - stored_questions = data_manager.formatted_file() + stored_questions = data_manager.format_file() return render_template('list.html', questions=stored_questions) From 53ccdb8169887c3ddd7dc86cb6ec8559b3e6f44f Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Wed, 6 Feb 2019 12:49:11 +0100 Subject: [PATCH 011/120] add questiondetails --- server.py | 4 ++++ templates/questiondetails.html | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 templates/questiondetails.html diff --git a/server.py b/server.py index 6d053ea23..fa85cf772 100644 --- a/server.py +++ b/server.py @@ -8,6 +8,10 @@ def route_list(): return render_template('list.html') +@app.route('/question/') +def route_question_id(): + + return render_template('questiondetails.html') if __name__ == "__main__": app.run( diff --git a/templates/questiondetails.html b/templates/questiondetails.html new file mode 100644 index 000000000..4099f9a62 --- /dev/null +++ b/templates/questiondetails.html @@ -0,0 +1,13 @@ + + + + + + + Question Details | Ask Mate + + +

Question Details

+ + + \ No newline at end of file From 6a82d2a5a3108fb106cad68a198c38ae9d8bb6a8 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 12:58:01 +0100 Subject: [PATCH 012/120] Add layout.html --- templates/layout.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 templates/layout.html diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 000000000..bb5713d45 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + Ask Mate + + +
+ {% block content %}{% endblock %} +
+ + + + + + + + \ No newline at end of file From 8847be333f705d4b49043b9e896b86f99764fe36 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 13:09:05 +0100 Subject: [PATCH 013/120] Add layout.html and bootstrap --- templates/list.html | 78 +++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/templates/list.html b/templates/list.html index 6e558b118..04c07d99e 100644 --- a/templates/list.html +++ b/templates/list.html @@ -1,47 +1,35 @@ - - - - - - - +{% extends 'layout.html' %} - +{% block content %} +

Ask Mate

- - - - Ask Mate - - -

Ask Mate

- - - - - - - - - - - - - - - {% for question in questions %} - - - - - - - - - - {% endfor %} - -
IdSubmission timeView numberVote numberTitleMessageImage
{{ question['id'] }}{{ question['submission_time'] }}{{ question['view_number'] }}{{ question['vote_number'] }}{{ question['title'] }}{{ question['message'] }}h{{ question['image'] }}
- - - \ No newline at end of file +
+ + + + + + + + + + + + + + {% for question in questions %} + + + + + + + + + + {% endfor %} + +
IdSubmission timeView numberVote numberTitleMessageImage
{{ question['id'] }}{{ question['submission_time'] }}{{ question['view_number'] }}{{ question['vote_number'] }}{{ question['title'] }}{{ question['message'] }}h{{ question['image'] }}
+
+ +{% endblock %} \ No newline at end of file From b5664d16ce974118f95bb8eed364885e5660f3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Wed, 6 Feb 2019 13:23:13 +0100 Subject: [PATCH 014/120] Form in newquestion.html for adding a new question created --- data_manager.py | 2 +- server.py | 7 ++++++- templates/newquestion.html | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 templates/newquestion.html diff --git a/data_manager.py b/data_manager.py index 275e036b4..ff68086b3 100644 --- a/data_manager.py +++ b/data_manager.py @@ -15,4 +15,4 @@ def format_file(): ts = int(question['submission_time']) question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') datas.append(question) - return datas \ No newline at end of file + return datas diff --git a/server.py b/server.py index 52e2e696e..6cc17d606 100644 --- a/server.py +++ b/server.py @@ -11,8 +11,13 @@ def route_list(): return render_template('list.html', questions=stored_questions) +@app.route("/add-question") +def new_question(): + pass + + if __name__ == "__main__": app.run( debug=True, port=5000 - ) \ No newline at end of file + ) diff --git a/templates/newquestion.html b/templates/newquestion.html new file mode 100644 index 000000000..3fd0ea091 --- /dev/null +++ b/templates/newquestion.html @@ -0,0 +1,23 @@ + + + + + + + New Question | Ask Mate + + +

Adding a new question

+ +
+ + +
+ +
+
+ + +
+ + \ No newline at end of file From 501e31f22a36d4dfc9cb0490db899e0885c1777b Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Wed, 6 Feb 2019 13:26:09 +0100 Subject: [PATCH 015/120] add questiondetails a head --- templates/questiondetails.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 4099f9a62..cf14024f2 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -8,6 +8,8 @@

Question Details

- +

Title

+

Message

+

\ No newline at end of file From f36d02b93c0a2c808b126e006e8656376c5dacc0 Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Wed, 6 Feb 2019 14:58:12 +0100 Subject: [PATCH 016/120] add questiondetails html and route function --- server.py | 11 +++++++++-- templates/list.html | 4 ++-- templates/questiondetails.html | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/server.py b/server.py index 9d0a8b4b7..48f50c4b2 100644 --- a/server.py +++ b/server.py @@ -10,10 +10,17 @@ def route_list(): stored_questions = data_manager.format_file() return render_template('list.html', questions=stored_questions) + @app.route('/question/') -def route_question_id(): +def route_question_id(question_id): + stored_questions = data_manager.format_file() + return render_template('questiondetails.html', questions=stored_questions, id=question_id) + + +@app.route('/question//new-answer') +def route_new_answer(): + return render_template('new-answer.html') - return render_template('questiondetails.html') @app.route("/add-question") def new_question(): diff --git a/templates/list.html b/templates/list.html index 04c07d99e..4cc61791d 100644 --- a/templates/list.html +++ b/templates/list.html @@ -23,8 +23,8 @@

{{ question['title'] }} + {{ question['message'] }} {{ question['image'] }} {% endfor %} diff --git a/templates/questiondetails.html b/templates/questiondetails.html index cf14024f2..c058fe055 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -7,9 +7,35 @@ Question Details | Ask Mate -

Question Details

-

Title

-

Message

-

+
+ + + + + + + + + + + + + + {% for question in questions %} + {% if id == question['id'] %} + + + + + + + + + + {% endif %} + {% endfor %} + +
IdSubmission timeView numberVote numberTitleMessageImage
{{ question['id'] }}{{ question['submission_time'] }}{{ question['view_number'] }}{{ question['vote_number'] }}{{ question['title'] }}{{ question['message'] }}{{ question['image'] }}
+
\ No newline at end of file From d5f72ba41fe5c0698296966da445f97fef3ab12b Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 6 Feb 2019 15:01:17 +0100 Subject: [PATCH 017/120] Add new functions --- data_manager.py | 7 +++++-- server.py | 7 ++++++- templates/answer.html | 16 ++++++++++++++++ templates/layout.html | 2 +- util.py | 7 +++++++ 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 templates/answer.html create mode 100644 util.py diff --git a/data_manager.py b/data_manager.py index 275e036b4..f25e5cbb5 100644 --- a/data_manager.py +++ b/data_manager.py @@ -1,9 +1,12 @@ import connection from datetime import datetime +ANSWER_PATH = 'sample_data/answer.csv' +QUESTION_PATH = 'sample_data/question.csv' -def sort_file(): - questions = connection.read_file('sample_data/question.csv') + +def sort_file(file_name=QUESTION_PATH): + questions = connection.read_file(file_name) questions.sort(key=lambda line: line['submission_time'], reverse=True) return questions diff --git a/server.py b/server.py index 52e2e696e..18edb8120 100644 --- a/server.py +++ b/server.py @@ -8,7 +8,12 @@ @app.route('/list') def route_list(): stored_questions = data_manager.format_file() - return render_template('list.html', questions=stored_questions) + return render_template('list.html', questions=stored_questions, title="Welcome!") + + +@app.route('/new-answer', methods=['GET', 'POST']) +def add_new_answer(): + return render_template('answer.html', title="Add New Answer!") if __name__ == "__main__": diff --git a/templates/answer.html b/templates/answer.html new file mode 100644 index 000000000..6c1ce7bd8 --- /dev/null +++ b/templates/answer.html @@ -0,0 +1,16 @@ +{% extends 'layout.html' %} + +{% block content %} +

Post a new answer

+ +
+ +
+ +
+ + +
+{% endblock %} \ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html index bb5713d45..19ae4fe76 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -10,7 +10,7 @@ - Ask Mate + {{ title }} | Ask Mate
diff --git a/util.py b/util.py new file mode 100644 index 000000000..d3ac64cef --- /dev/null +++ b/util.py @@ -0,0 +1,7 @@ +import time + + +def get_current_time(): + return time.time() + +print(get_current_time()) \ No newline at end of file From 5be4945ed33840785b27e12b60ed11f1a667a094 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 7 Feb 2019 12:24:49 +0100 Subject: [PATCH 018/120] Style html files --- data_manager.py | 4 ++-- server.py | 4 ++-- templates/answer.html | 2 +- templates/list.html | 16 +++++++--------- templates/questiondetails.html | 17 ++++++----------- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/data_manager.py b/data_manager.py index 4b62eea3d..4d79fb021 100644 --- a/data_manager.py +++ b/data_manager.py @@ -5,9 +5,9 @@ QUESTION_PATH = 'sample_data/question.csv' -def sort_file(file_name=QUESTION_PATH): +def sort_file(file_name=QUESTION_PATH, dict_key='submission_time'): questions = connection.read_file(file_name) - questions.sort(key=lambda line: line['submission_time'], reverse=True) + questions.sort(key=lambda line: line[dict_key], reverse=True) return questions diff --git a/server.py b/server.py index e3fa0655a..1020608ea 100644 --- a/server.py +++ b/server.py @@ -23,8 +23,8 @@ def route_question_id(question_id): @app.route('/question//new-answer') -def route_new_answer(): - return render_template('new-answer.html') +def route_new_answer(question_id): + return render_template('answer.html') @app.route("/add-question") diff --git a/templates/answer.html b/templates/answer.html index 6c1ce7bd8..1211b2225 100644 --- a/templates/answer.html +++ b/templates/answer.html @@ -1,7 +1,7 @@ {% extends 'layout.html' %} {% block content %} -

Post a new answer

+

Post a new answer

\ No newline at end of file From 480a3aefac2efefdf1e0d2a1af37dc403f76c9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Thu, 7 Feb 2019 13:41:55 +0100 Subject: [PATCH 020/120] ID 103 user story completed, minor changes in connection and data_manager modules --- connection.py | 4 ++-- data_manager.py | 5 +++++ sample_data/question.csv | 1 + server.py | 23 ++++++++++++++++++++--- templates/newquestion.html | 4 ++-- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/connection.py b/connection.py index 5a70e817d..6685d8636 100644 --- a/connection.py +++ b/connection.py @@ -10,7 +10,7 @@ def read_file(filename): return datas -def write_to_file(filename, user_story): +def write_to_file(filename, user_story, fieldnames): with open(filename, 'a', encoding='utf-8') as csvfile: - datas_to_export = csv.DictWriter(csvfile) + datas_to_export = csv.DictWriter(csvfile, fieldnames=fieldnames) datas_to_export.writerow(user_story) diff --git a/data_manager.py b/data_manager.py index ff68086b3..ec5003cba 100644 --- a/data_manager.py +++ b/data_manager.py @@ -16,3 +16,8 @@ def format_file(): question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') datas.append(question) return datas + + +def generate_new_id(filename): + new_id = len(connection.read_file(filename)) + 1 + return new_id diff --git a/sample_data/question.csv b/sample_data/question.csv index e65825dc3..ed4b9ff5f 100644 --- a/sample_data/question.csv +++ b/sample_data/question.csv @@ -12,3 +12,4 @@ app.js (bundled file with webpack, including jquery)","images/image1.png" 2,1493015432,1364,57,"Drawing canvas with an image picked with Cordova Camera Plugin","I'm getting an image from device and drawing a canvas with filters using Pixi JS. It works all well using computer to get an image. But when I'm on IOS, it throws errors such as cross origin issue, or that I'm trying to use an unknown format. This is the code I'm using to draw the image (that works on web/desktop but not cordova built ios app)", + diff --git a/server.py b/server.py index d7baa723b..98a0c186d 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,8 @@ from flask import Flask, render_template, redirect, url_for, request import data_manager +import connection +import time + app = Flask(__name__) @@ -18,9 +21,23 @@ def route_question_id(question_id): -@app.route("/add-question") -def new_question(): - pass +@app.route("/add-question", methods=["GET", "POST"]) +def add_question(): + if request.method == "POST": + user_story = { + 'id': data_manager.generate_new_id('sample_data/question.csv'), + 'submission': int(time.time()), + 'view_number': 0, + 'vote_number': 0, + 'title': request.form["QuestionTitle"], + 'message': request.form["NewQuestion"], + 'image': "" + } + fieldnames = ['id', 'submission', 'view_number', 'vote_number', 'title', 'message', 'image'] + connection.write_to_file('sample_data/question.csv', user_story, fieldnames) + return redirect("url_for(route_question_id, question_id=user_story['id'])") + + return render_template("newquestion.html") if __name__ == "__main__": diff --git a/templates/newquestion.html b/templates/newquestion.html index 3fd0ea091..e3950e4be 100644 --- a/templates/newquestion.html +++ b/templates/newquestion.html @@ -9,9 +9,9 @@

Adding a new question

- + - +


From 4fa94011195dda8447e1936a9b98509e21e6014f Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 7 Feb 2019 13:43:37 +0100 Subject: [PATCH 021/120] Change label --- templates/answer.html | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/answer.html b/templates/answer.html index 1211b2225..7a1a4ecac 100644 --- a/templates/answer.html +++ b/templates/answer.html @@ -5,7 +5,6 @@

From 5d12bedd00de2878e38c9d54071a63ccc6d51220 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 7 Feb 2019 14:11:32 +0100 Subject: [PATCH 022/120] Style the html file --- data_manager.py | 2 +- sample_data/question.csv | 1 - server.py | 2 +- templates/newquestion.html | 33 ++++++++++++++++----------------- templates/questiondetails.html | 14 +------------- 5 files changed, 19 insertions(+), 33 deletions(-) diff --git a/data_manager.py b/data_manager.py index aa8ea3ed6..a349895fd 100644 --- a/data_manager.py +++ b/data_manager.py @@ -22,5 +22,5 @@ def format_file(): def generate_new_id(filename): - new_id = len(connection.read_file(filename)) + 1 + new_id = len(connection.read_file(filename)) return new_id diff --git a/sample_data/question.csv b/sample_data/question.csv index ed4b9ff5f..e65825dc3 100644 --- a/sample_data/question.csv +++ b/sample_data/question.csv @@ -12,4 +12,3 @@ app.js (bundled file with webpack, including jquery)","images/image1.png" 2,1493015432,1364,57,"Drawing canvas with an image picked with Cordova Camera Plugin","I'm getting an image from device and drawing a canvas with filters using Pixi JS. It works all well using computer to get an image. But when I'm on IOS, it throws errors such as cross origin issue, or that I'm trying to use an unknown format. This is the code I'm using to draw the image (that works on web/desktop but not cordova built ios app)", - diff --git a/server.py b/server.py index d8b53da94..d1a35fb35 100644 --- a/server.py +++ b/server.py @@ -44,7 +44,7 @@ def add_question(): } fieldnames = ['id', 'submission', 'view_number', 'vote_number', 'title', 'message', 'image'] connection.write_to_file('sample_data/question.csv', user_story, fieldnames) - return redirect("url_for(route_question_id, question_id=user_story['id'])") + return redirect(url_for('route_question_id', question_id=user_story['id'])) return render_template("newquestion.html") diff --git a/templates/newquestion.html b/templates/newquestion.html index e3950e4be..91d647883 100644 --- a/templates/newquestion.html +++ b/templates/newquestion.html @@ -1,23 +1,22 @@ - - - - - - - New Question | Ask Mate - - -

Adding a new question

+{% extends 'layout.html' %} + +{% block content %} +

Add new question

-
-
+
+ + +
+ +
+
+ +
-
-
+ + - - - \ No newline at end of file +{% endblock %} \ No newline at end of file diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 8021f993b..b3cfb6a3f 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -33,23 +33,11 @@

- - - Id - Submission time - Vote number - question_id - Message - - {% for answer in answers %} {% if id == question['question_id'] %} - {{ answer['id'] }} {{ answer['submission_time'] }} - {{ answer['vote_number'] }} - {{ answer['question_id'] }} {{ answer['message'] }} {% endif %} @@ -57,6 +45,6 @@

/new-answer">Post a new answer + Post a new answer

{% endblock %} \ No newline at end of file From 6bc78cf7f239bc7fb89000b3b30094b84708977d Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 7 Feb 2019 16:08:44 +0100 Subject: [PATCH 023/120] Fix bugs --- data_manager.py | 27 +++++++++++++++++++-------- server.py | 33 +++++++++++++++++++++------------ templates/answer.html | 5 ++--- templates/newquestion.html | 2 +- templates/questiondetails.html | 5 +++-- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/data_manager.py b/data_manager.py index a349895fd..2fa2553d3 100644 --- a/data_manager.py +++ b/data_manager.py @@ -11,14 +11,25 @@ def sort_file(file_name=QUESTION_PATH, dict_key='submission_time'): return questions -def format_file(): - sorted_questions = sort_file() - datas = [] - for question in sorted_questions: - ts = int(question['submission_time']) - question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') - datas.append(question) - return datas +def format_file(file_path): + if file_path == QUESTION_PATH: + sorted_questions = sort_file() + + datas = [] + for question in sorted_questions: + ts = int(question['submission_time']) + question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') + datas.append(question) + return datas + elif file_path == ANSWER_PATH: + sorted_answers = sort_file(file_name=ANSWER_PATH) + datas = [] + for answer in sorted_answers: + ts = int(answer['submission_time']) + answer['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') + datas.append(answer) + return datas + def generate_new_id(filename): diff --git a/server.py b/server.py index d1a35fb35..0d47ddf80 100644 --- a/server.py +++ b/server.py @@ -10,24 +10,33 @@ @app.route('/') @app.route('/list') def route_list(): - stored_questions = data_manager.format_file() + stored_questions = data_manager.format_file('sample_data/question.csv') return render_template('list.html', questions=stored_questions, title="Welcome!") -@app.route('/new-answer', methods=['GET', 'POST']) -def add_new_answer(): - return render_template('answer.html', title="Add New Answer!") - - @app.route('/question/') def route_question_id(question_id): - stored_questions = data_manager.format_file() - return render_template('questiondetails.html', questions=stored_questions, id=question_id) + stored_questions = data_manager.format_file('sample_data/question.csv') + stored_answers = data_manager.format_file('sample_data/answer.csv') + return render_template('questiondetails.html', questions=stored_questions, answers=stored_answers, id=question_id) -@app.route('/question//new-answer') +@app.route('/question//new-answer', methods=['GET', 'POST']) def route_new_answer(question_id): - return render_template('answer.html') + if request.method == "POST": + user_story = { + 'id': data_manager.generate_new_id('sample_data/answer.csv'), + 'submission': int(time.time()), + 'vote_number': 0, + 'question_id': question_id, + 'message': request.form["answer"], + 'image': "" + } + fieldnames = ['id', 'submission', 'vote_number', 'question_id', 'message', 'image'] + connection.write_to_file('sample_data/answer.csv', user_story, fieldnames) + return redirect(url_for('route_question_id', question_id=question_id)) + + return render_template('answer.html', title="Add New Answer!", question_id=question_id) @app.route("/add-question", methods=["GET", "POST"]) @@ -38,8 +47,8 @@ def add_question(): 'submission': int(time.time()), 'view_number': 0, 'vote_number': 0, - 'title': request.form["QuestionTitle"], - 'message': request.form["NewQuestion"], + 'title': request.form["question-title"], + 'message': request.form["new-question"], 'image': "" } fieldnames = ['id', 'submission', 'view_number', 'vote_number', 'title', 'message', 'image'] diff --git a/templates/answer.html b/templates/answer.html index 7a1a4ecac..a9467bc75 100644 --- a/templates/answer.html +++ b/templates/answer.html @@ -3,9 +3,8 @@ {% block content %}

Post a new answer

-
- + +
diff --git a/templates/newquestion.html b/templates/newquestion.html index 91d647883..5dd1d044a 100644 --- a/templates/newquestion.html +++ b/templates/newquestion.html @@ -7,7 +7,7 @@

- +
diff --git a/templates/questiondetails.html b/templates/questiondetails.html index b3cfb6a3f..05b9a4632 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -32,10 +32,11 @@

Answers

{% for answer in answers %} - {% if id == question['question_id'] %} + {% if id == answer['question_id'] %} @@ -45,6 +46,6 @@

/new-answer" class="btn btn-primary">Post a new answer + Post a new answer {% endblock %} \ No newline at end of file From 6106a0f81f7e7ab62264ea66edd1762fedf1e737 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 7 Feb 2019 19:32:27 +0100 Subject: [PATCH 024/120] Add get_questions func --- data_manager.py | 5 ++++- server.py | 2 +- util.py | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/data_manager.py b/data_manager.py index 2fa2553d3..b611ecd44 100644 --- a/data_manager.py +++ b/data_manager.py @@ -29,7 +29,10 @@ def format_file(file_path): answer['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') datas.append(answer) return datas - + + +def get_questions(): + return format_file('sample_data/question.csv') def generate_new_id(filename): diff --git a/server.py b/server.py index 0d47ddf80..8fd43f960 100644 --- a/server.py +++ b/server.py @@ -10,7 +10,7 @@ @app.route('/') @app.route('/list') def route_list(): - stored_questions = data_manager.format_file('sample_data/question.csv') + stored_questions = data_manager.get_questions() return render_template('list.html', questions=stored_questions, title="Welcome!") diff --git a/util.py b/util.py index d3ac64cef..14e412ec2 100644 --- a/util.py +++ b/util.py @@ -3,5 +3,3 @@ def get_current_time(): return time.time() - -print(get_current_time()) \ No newline at end of file From 995f8ce3a2526534c131edeb47290b1c0f61493e Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 7 Feb 2019 19:38:21 +0100 Subject: [PATCH 025/120] Change path name in get_question func --- data_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_manager.py b/data_manager.py index b611ecd44..6ccca0051 100644 --- a/data_manager.py +++ b/data_manager.py @@ -32,7 +32,7 @@ def format_file(file_path): def get_questions(): - return format_file('sample_data/question.csv') + return format_file(QUESTION_PATH) def generate_new_id(filename): From 08d4c727aba1ccada6a80878ba3921ece8892e4c Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Fri, 8 Feb 2019 08:27:47 +0100 Subject: [PATCH 026/120] delete utc from both utcfromtimestamp in ddata_manager.py --- data_manager.py | 4 ++-- sample_data/answer.csv | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/data_manager.py b/data_manager.py index 6ccca0051..ac8d22950 100644 --- a/data_manager.py +++ b/data_manager.py @@ -18,7 +18,7 @@ def format_file(file_path): datas = [] for question in sorted_questions: ts = int(question['submission_time']) - question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') + question['submission_time'] = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') datas.append(question) return datas elif file_path == ANSWER_PATH: @@ -26,7 +26,7 @@ def format_file(file_path): datas = [] for answer in sorted_answers: ts = int(answer['submission_time']) - answer['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') + answer['submission_time'] = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') datas.append(answer) return datas diff --git a/sample_data/answer.csv b/sample_data/answer.csv index 3ddfa1ffb..700ec4c60 100644 --- a/sample_data/answer.csv +++ b/sample_data/answer.csv @@ -1,3 +1,6 @@ id,submission_time,vote_number,question_id,message,image 0,1493398154,4,0,"You need to use brackets: my_list = []", 1,1493088154,35,0,"Look it up in the Python docs", +2,1549610456,0,0,this is my new answer here, +3,1549610722,0,0,"from time stamp +", From 2fa7a0563fe724e22846a8d7e179b0584ac87b08 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 18 Feb 2019 13:46:19 +0100 Subject: [PATCH 027/120] Refactor format_file func --- data_manager.py | 24 +++++++----------------- templates/layout.html | 1 + templates/questiondetails.html | 2 +- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/data_manager.py b/data_manager.py index 6ccca0051..a4bdbbefb 100644 --- a/data_manager.py +++ b/data_manager.py @@ -12,23 +12,13 @@ def sort_file(file_name=QUESTION_PATH, dict_key='submission_time'): def format_file(file_path): - if file_path == QUESTION_PATH: - sorted_questions = sort_file() - - datas = [] - for question in sorted_questions: - ts = int(question['submission_time']) - question['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') - datas.append(question) - return datas - elif file_path == ANSWER_PATH: - sorted_answers = sort_file(file_name=ANSWER_PATH) - datas = [] - for answer in sorted_answers: - ts = int(answer['submission_time']) - answer['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') - datas.append(answer) - return datas + sorted_datas = sort_file(file_name=file_path) + datas = [] + for data in sorted_datas: + ts = int(data['submission_time']) + data['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') + datas.append(data) + return datas def get_questions(): diff --git a/templates/layout.html b/templates/layout.html index 19ae4fe76..06ce29378 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -6,6 +6,7 @@ + diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 05b9a4632..9487cbaaf 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -1,7 +1,7 @@ {% extends 'layout.html' %} {% block content %} -

Question Details

+

Question Details

{{ answer['submission_time'] }} {{ answer['message'] }}
From 3ab01f70f446dc3417d72f7b67d8c71e0c63c22a Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 18 Feb 2019 13:49:05 +0100 Subject: [PATCH 028/120] Add get_answers func --- data_manager.py | 6 +++++- server.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/data_manager.py b/data_manager.py index a4bdbbefb..91433990d 100644 --- a/data_manager.py +++ b/data_manager.py @@ -18,13 +18,17 @@ def format_file(file_path): ts = int(data['submission_time']) data['submission_time'] = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') datas.append(data) - return datas + return datas def get_questions(): return format_file(QUESTION_PATH) +def get_answers(): + return format_file(ANSWER_PATH) + + def generate_new_id(filename): new_id = len(connection.read_file(filename)) return new_id diff --git a/server.py b/server.py index 8fd43f960..0eb904924 100644 --- a/server.py +++ b/server.py @@ -16,8 +16,8 @@ def route_list(): @app.route('/question/') def route_question_id(question_id): - stored_questions = data_manager.format_file('sample_data/question.csv') - stored_answers = data_manager.format_file('sample_data/answer.csv') + stored_questions = data_manager.get_questions() + stored_answers = data_manager.get_answers() return render_template('questiondetails.html', questions=stored_questions, answers=stored_answers, id=question_id) From bd80c91332bb7514af0247edab90fb73c615fe1e Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 18 Feb 2019 13:57:21 +0100 Subject: [PATCH 029/120] Add an add_answer func to data manager --- data_manager.py | 15 +++++++++++++++ sample_data/answer.csv | 1 + server.py | 13 ++----------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/data_manager.py b/data_manager.py index 91433990d..d89f7f146 100644 --- a/data_manager.py +++ b/data_manager.py @@ -29,6 +29,21 @@ def get_answers(): return format_file(ANSWER_PATH) +def add_question(title, message): + user_story = { + 'id': generate_new_id(QUESTION_PATH), + 'submission': int(time.time()), + 'view_number': 0, + 'vote_number': 0, + 'title': title, + 'message': message, + 'image': "" + } + fieldnames = ['id', 'submission', 'view_number', 'vote_number', 'title', 'message', 'image'] + connection.write_to_file(QUESTION_PATH, user_story, fieldnames) + return user_story + + def generate_new_id(filename): new_id = len(connection.read_file(filename)) return new_id diff --git a/sample_data/answer.csv b/sample_data/answer.csv index 3ddfa1ffb..372c5e2bb 100644 --- a/sample_data/answer.csv +++ b/sample_data/answer.csv @@ -1,3 +1,4 @@ id,submission_time,vote_number,question_id,message,image 0,1493398154,4,0,"You need to use brackets: my_list = []", 1,1493088154,35,0,"Look it up in the Python docs", +2,1550494259,0,0,helllllllllllllllloo2, diff --git a/server.py b/server.py index 0eb904924..f57e4437d 100644 --- a/server.py +++ b/server.py @@ -24,18 +24,9 @@ def route_question_id(question_id): @app.route('/question//new-answer', methods=['GET', 'POST']) def route_new_answer(question_id): if request.method == "POST": - user_story = { - 'id': data_manager.generate_new_id('sample_data/answer.csv'), - 'submission': int(time.time()), - 'vote_number': 0, - 'question_id': question_id, - 'message': request.form["answer"], - 'image': "" - } - fieldnames = ['id', 'submission', 'vote_number', 'question_id', 'message', 'image'] - connection.write_to_file('sample_data/answer.csv', user_story, fieldnames) + user_story = data_manager.add_answer(question_id, request.form["answer"]) return redirect(url_for('route_question_id', question_id=question_id)) - + return render_template('answer.html', title="Add New Answer!", question_id=question_id) From 03018b36c655177675f714bb32a924229c956cc8 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 18 Feb 2019 13:59:14 +0100 Subject: [PATCH 030/120] Make add_question func --- data_manager.py | 14 ++++++++++++++ server.py | 12 +----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/data_manager.py b/data_manager.py index d89f7f146..d29ebfa13 100644 --- a/data_manager.py +++ b/data_manager.py @@ -44,6 +44,20 @@ def add_question(title, message): return user_story +def add_answer(question_id, message): + user_story = { + 'id': generate_new_id(ANSWER_PATH), + 'submission': int(time.time()), + 'vote_number': 0, + 'question_id': question_id, + 'message': message, + 'image': "" + } + fieldnames = ['id', 'submission', 'vote_number', 'question_id', 'message', 'image'] + connection.write_to_file(ANSWER_PATH, user_story, fieldnames) + return user_story + + def generate_new_id(filename): new_id = len(connection.read_file(filename)) return new_id diff --git a/server.py b/server.py index f57e4437d..85570186d 100644 --- a/server.py +++ b/server.py @@ -33,17 +33,7 @@ def route_new_answer(question_id): @app.route("/add-question", methods=["GET", "POST"]) def add_question(): if request.method == "POST": - user_story = { - 'id': data_manager.generate_new_id('sample_data/question.csv'), - 'submission': int(time.time()), - 'view_number': 0, - 'vote_number': 0, - 'title': request.form["question-title"], - 'message': request.form["new-question"], - 'image': "" - } - fieldnames = ['id', 'submission', 'view_number', 'vote_number', 'title', 'message', 'image'] - connection.write_to_file('sample_data/question.csv', user_story, fieldnames) + user_story = data_manager.add_question(request.form["question-title"], request.form["new-question"]) return redirect(url_for('route_question_id', question_id=user_story['id'])) return render_template("newquestion.html") From 3183ccac7d0fd8d2a733e262f61019caea291fb8 Mon Sep 17 00:00:00 2001 From: lterray Date: Mon, 28 Aug 2017 16:35:10 +0200 Subject: [PATCH 031/120] add sql sample data --- sample_data/askmatepart2-sample-data.sql | 127 +++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 sample_data/askmatepart2-sample-data.sql diff --git a/sample_data/askmatepart2-sample-data.sql b/sample_data/askmatepart2-sample-data.sql new file mode 100644 index 000000000..369355a65 --- /dev/null +++ b/sample_data/askmatepart2-sample-data.sql @@ -0,0 +1,127 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 9.5.6 +-- Dumped by pg_dump version 9.5.6 + +ALTER TABLE IF EXISTS ONLY public.question DROP CONSTRAINT IF EXISTS pk_question_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.answer DROP CONSTRAINT IF EXISTS pk_answer_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.answer DROP CONSTRAINT IF EXISTS fk_question_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.comment DROP CONSTRAINT IF EXISTS pk_comment_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.comment DROP CONSTRAINT IF EXISTS fk_question_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.comment DROP CONSTRAINT IF EXISTS fk_answer_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.question_tag DROP CONSTRAINT IF EXISTS pk_question_tag_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.question_tag DROP CONSTRAINT IF EXISTS fk_question_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.tag DROP CONSTRAINT IF EXISTS pk_tag_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.question_tag DROP CONSTRAINT IF EXISTS fk_tag_id CASCADE; + +DROP TABLE IF EXISTS public.question; +DROP SEQUENCE IF EXISTS public.question_id_seq; +CREATE TABLE question ( + id serial NOT NULL, + submission_time timestamp without time zone, + view_number integer, + vote_number integer, + title text, + message text, + image text +); + +DROP TABLE IF EXISTS public.answer; +DROP SEQUENCE IF EXISTS public.answer_id_seq; +CREATE TABLE answer ( + id serial NOT NULL, + submission_time timestamp without time zone, + vote_number integer, + question_id integer, + message text, + image text +); + +DROP TABLE IF EXISTS public.comment; +DROP SEQUENCE IF EXISTS public.comment_id_seq; +CREATE TABLE comment ( + id serial NOT NULL, + question_id integer, + answer_id integer, + message text, + submission_time timestamp without time zone, + edited_count integer +); + + +DROP TABLE IF EXISTS public.question_tag; +CREATE TABLE question_tag ( + question_id integer NOT NULL, + tag_id integer NOT NULL +); + +DROP TABLE IF EXISTS public.tag; +DROP SEQUENCE IF EXISTS public.tag_id_seq; +CREATE TABLE tag ( + id serial NOT NULL, + name text +); + + +ALTER TABLE ONLY answer + ADD CONSTRAINT pk_answer_id PRIMARY KEY (id); + +ALTER TABLE ONLY comment + ADD CONSTRAINT pk_comment_id PRIMARY KEY (id); + +ALTER TABLE ONLY question + ADD CONSTRAINT pk_question_id PRIMARY KEY (id); + +ALTER TABLE ONLY question_tag + ADD CONSTRAINT pk_question_tag_id PRIMARY KEY (question_id, tag_id); + +ALTER TABLE ONLY tag + ADD CONSTRAINT pk_tag_id PRIMARY KEY (id); + +ALTER TABLE ONLY comment + ADD CONSTRAINT fk_answer_id FOREIGN KEY (answer_id) REFERENCES answer(id); + +ALTER TABLE ONLY answer + ADD CONSTRAINT fk_question_id FOREIGN KEY (question_id) REFERENCES question(id); + +ALTER TABLE ONLY question_tag + ADD CONSTRAINT fk_question_id FOREIGN KEY (question_id) REFERENCES question(id); + +ALTER TABLE ONLY comment + ADD CONSTRAINT fk_question_id FOREIGN KEY (question_id) REFERENCES question(id); + +ALTER TABLE ONLY question_tag + ADD CONSTRAINT fk_tag_id FOREIGN KEY (tag_id) REFERENCES tag(id); + +INSERT INTO question VALUES (0, '2017-04-28 08:29:00', 29, 7, 'How to make lists in Python?', 'I am totally new to this, any hints?', NULL); +INSERT INTO question VALUES (1, '2017-04-29 09:19:00', 15, 9, 'Wordpress loading multiple jQuery Versions', 'I developed a plugin that uses the jquery booklet plugin (http://builtbywill.com/booklet/#/) this plugin binds a function to $ so I cann call $(".myBook").booklet(); + +I could easy managing the loading order with wp_enqueue_script so first I load jquery then I load booklet so everything is fine. + +BUT in my theme i also using jquery via webpack so the loading order is now following: + +jquery +booklet +app.js (bundled file with webpack, including jquery)', 'images/image1.png'); +INSERT INTO question VALUES (2, '2017-05-01 10:41:00', 1364, 57, 'Drawing canvas with an image picked with Cordova Camera Plugin', 'I''m getting an image from device and drawing a canvas with filters using Pixi JS. It works all well using computer to get an image. But when I''m on IOS, it throws errors such as cross origin issue, or that I''m trying to use an unknown format. +', NULL); +SELECT pg_catalog.setval('question_id_seq', 2, true); + +INSERT INTO answer VALUES (1, '2017-04-28 16:49:00', 4, 1, 'You need to use brackets: my_list = []', NULL); +INSERT INTO answer VALUES (2, '2017-04-25 14:42:00', 35, 1, 'Look it up in the Python docs', 'images/image2.jpg'); +SELECT pg_catalog.setval('answer_id_seq', 2, true); + +INSERT INTO comment VALUES (1, 0, NULL, 'Please clarify the question as it is too vague!', '2017-05-01 05:49:00'); +INSERT INTO comment VALUES (2, NULL, 1, 'I think you could use my_list = list() as well.', '2017-05-02 16:55:00'); +SELECT pg_catalog.setval('comment_id_seq', 2, true); + +INSERT INTO tag VALUES (1, 'python'); +INSERT INTO tag VALUES (2, 'sql'); +INSERT INTO tag VALUES (3, 'css'); +SELECT pg_catalog.setval('tag_id_seq', 3, true); + +INSERT INTO question_tag VALUES (0, 1); +INSERT INTO question_tag VALUES (1, 3); +INSERT INTO question_tag VALUES (2, 3); From d8d9229b36cb1a529b42dc79ba6ffe717602f524 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 18 Feb 2019 14:05:58 +0100 Subject: [PATCH 032/120] Add sql database to sample data --- data_manager.py | 1 + sample_data/answer.csv | 1 + sample_data/question.csv | 1 + 3 files changed, 3 insertions(+) diff --git a/data_manager.py b/data_manager.py index d29ebfa13..6dcb81545 100644 --- a/data_manager.py +++ b/data_manager.py @@ -1,5 +1,6 @@ import connection from datetime import datetime +import time ANSWER_PATH = 'sample_data/answer.csv' QUESTION_PATH = 'sample_data/question.csv' diff --git a/sample_data/answer.csv b/sample_data/answer.csv index 372c5e2bb..e212d8895 100644 --- a/sample_data/answer.csv +++ b/sample_data/answer.csv @@ -2,3 +2,4 @@ id,submission_time,vote_number,question_id,message,image 0,1493398154,4,0,"You need to use brackets: my_list = []", 1,1493088154,35,0,"Look it up in the Python docs", 2,1550494259,0,0,helllllllllllllllloo2, +3,1550494995,0,1,new answer, diff --git a/sample_data/question.csv b/sample_data/question.csv index e65825dc3..a1db79784 100644 --- a/sample_data/question.csv +++ b/sample_data/question.csv @@ -12,3 +12,4 @@ app.js (bundled file with webpack, including jquery)","images/image1.png" 2,1493015432,1364,57,"Drawing canvas with an image picked with Cordova Camera Plugin","I'm getting an image from device and drawing a canvas with filters using Pixi JS. It works all well using computer to get an image. But when I'm on IOS, it throws errors such as cross origin issue, or that I'm trying to use an unknown format. This is the code I'm using to draw the image (that works on web/desktop but not cordova built ios app)", +3,1550494973,0,0,new question,newwwwwww qqqqqqqqqqqq, From 4ce2b974ac659ef59b2c6499a60395a45fb856a4 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 18 Feb 2019 20:32:43 +0100 Subject: [PATCH 033/120] Add SQL database instead of csv file --- connection.py | 59 +++++++++++++++++++++++++++++++++++++---------- data_manager.py | 61 ++++++++++++++++++++++--------------------------- server.py | 10 ++++---- 3 files changed, 79 insertions(+), 51 deletions(-) diff --git a/connection.py b/connection.py index 6685d8636..6b46997e6 100644 --- a/connection.py +++ b/connection.py @@ -1,16 +1,51 @@ -import csv +# Creates a decorator to handle the database connection/cursor opening/closing. +# Creates the cursor with RealDictCursor, thus it returns real dictionaries, where the column names are the keys. +import os +import psycopg2 +import psycopg2.extras -def read_file(filename): - with open(filename, "r", encoding='utf-8') as f: - reader_file = csv.DictReader(f) - datas = [] - for line in reader_file: - datas.append(dict(line)) - return datas +def get_connection_string(): + # setup connection string + # to do this, please define these environment variables first + user_name = os.environ.get('PSQL_USER_NAME') + password = os.environ.get('PSQL_PASSWORD') + host = os.environ.get('PSQL_HOST') + database_name = os.environ.get('PSQL_DB_NAME') + env_variables_defined = user_name and password and host and database_name -def write_to_file(filename, user_story, fieldnames): - with open(filename, 'a', encoding='utf-8') as csvfile: - datas_to_export = csv.DictWriter(csvfile, fieldnames=fieldnames) - datas_to_export.writerow(user_story) + if env_variables_defined: + # this string describes all info for psycopg2 to connect to the database + return 'postgresql://{user_name}:{password}@{host}/{database_name}'.format( + user_name=user_name, + password=password, + host=host, + database_name=database_name + ) + else: + raise KeyError('Some necessary environment variable(s) are not defined') + + +def open_database(): + try: + connection_string = get_connection_string() + connection = psycopg2.connect(connection_string) + connection.autocommit = True + except psycopg2.DatabaseError as exception: + print('Database connection problem') + raise exception + return connection + + +def connection_handler(function): + def wrapper(*args, **kwargs): + connection = open_database() + # we set the cursor_factory parameter to return with a RealDictCursor cursor (cursor which provide dictionaries) + dict_cur = connection.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + ret_value = function(dict_cur, *args, **kwargs) + dict_cur.close() + connection.close() + return ret_value + + return wrapper \ No newline at end of file diff --git a/data_manager.py b/data_manager.py index dc349ae56..a25fb7cf4 100644 --- a/data_manager.py +++ b/data_manager.py @@ -2,61 +2,54 @@ from datetime import datetime import time -ANSWER_PATH = 'sample_data/answer.csv' -QUESTION_PATH = 'sample_data/question.csv' - -def sort_file(file_name=QUESTION_PATH, dict_key='submission_time'): - questions = connection.read_file(file_name) - questions.sort(key=lambda line: line[dict_key], reverse=True) +@connection.connection_handler +def get_questions(cursor): + cursor.execute("""SELECT * FROM question ORDER BY submission_time DESC;""") + questions = cursor.fetchall() return questions -def format_file(file_path): - sorted_datas = sort_file(file_name=file_path) - datas = [] - for data in sorted_datas: - ts = int(data['submission_time']) - data['submission_time'] = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') - datas.append(data) - return datas - - -def get_questions(): - return format_file(QUESTION_PATH) - +@connection.connection_handler +def get_answers(cursor): + cursor.execute("""SELECT * FROM answer ORDER BY submission_time DESC;""") + answers = cursor.fetchall() + return answers -def get_answers(): - return format_file(ANSWER_PATH) - -def add_question(title, message): +@connection.connection_handler +def add_question(cursor, title, message): user_story = { - 'id': generate_new_id(QUESTION_PATH), - 'submission': int(time.time()), + 'submission_time': datetime.now(), 'view_number': 0, 'vote_number': 0, 'title': title, 'message': message, 'image': "" } - fieldnames = ['id', 'submission', 'view_number', 'vote_number', 'title', 'message', 'image'] - connection.write_to_file(QUESTION_PATH, user_story, fieldnames) - return user_story + cursor.execute("""INSERT INTO question(submission_time, view_number, vote_number, title, message, image) + VALUES(%(submission_time)s, %(view_number)s, %(vote_number)s, %(title)s, %(message)s, %(image)s);""", + user_story) + + cursor.execute("""SELECT id FROM question + ORDER BY id DESC + LIMIT 1;""") + return cursor.fetchone()['id'] + +@connection.connection_handler +def add_answer(cursor, question_id, message): -def add_answer(question_id, message): user_story = { - 'id': generate_new_id(ANSWER_PATH), - 'submission': int(time.time()), + 'submission_time': datetime.now(), 'vote_number': 0, 'question_id': question_id, 'message': message, 'image': "" } - fieldnames = ['id', 'submission', 'vote_number', 'question_id', 'message', 'image'] - connection.write_to_file(ANSWER_PATH, user_story, fieldnames) - return user_story + + cursor.execute("""INSERT INTO answer(submission_time, vote_number, question_id, message, image) + VALUES(%(submission_time)s,%(vote_number)s,%(question_id)s, %(message)s,%(image)s);""", user_story) def generate_new_id(filename): diff --git a/server.py b/server.py index 830447d58..d3256332d 100644 --- a/server.py +++ b/server.py @@ -12,17 +12,17 @@ def route_list(): return render_template('list.html', questions=stored_questions, title="Welcome!") -@app.route('/question/') +@app.route('/question/') def route_question_id(question_id): stored_questions = data_manager.get_questions() stored_answers = data_manager.get_answers() return render_template('questiondetails.html', questions=stored_questions, answers=stored_answers, id=question_id) -@app.route('/question//new-answer', methods=['GET', 'POST']) +@app.route('/question//new-answer', methods=['GET', 'POST']) def route_new_answer(question_id): if request.method == "POST": - user_story = data_manager.add_answer(question_id, request.form["answer"]) + data_manager.add_answer(question_id, request.form["answer"]) return redirect(url_for('route_question_id', question_id=question_id)) return render_template('answer.html', title="Add New Answer!", question_id=question_id) @@ -31,8 +31,8 @@ def route_new_answer(question_id): @app.route("/add-question", methods=["GET", "POST"]) def add_question(): if request.method == "POST": - user_story = data_manager.add_question(request.form["question-title"], request.form["new-question"]) - return redirect(url_for('route_question_id', question_id=user_story['id'])) + user_story_id = data_manager.add_question(request.form["question-title"], request.form["new-question"]) + return redirect(url_for('route_question_id', question_id=user_story_id)) return render_template("newquestion.html") From 4199ee55c2eeb19c0087a5e210547581ecea2283 Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Tue, 19 Feb 2019 11:12:26 +0100 Subject: [PATCH 034/120] play around sample data --- sample_data/answer.csv | 4 ++++ sample_data/question.csv | 2 ++ 2 files changed, 6 insertions(+) diff --git a/sample_data/answer.csv b/sample_data/answer.csv index 700ec4c60..8f40623e2 100644 --- a/sample_data/answer.csv +++ b/sample_data/answer.csv @@ -4,3 +4,7 @@ id,submission_time,vote_number,question_id,message,image 2,1549610456,0,0,this is my new answer here, 3,1549610722,0,0,"from time stamp ", +4,1549610956,0,1,this is an other answer to Q 2, +5,1549613796,0,3,asdélkfjéldsakfj, +6,1549617230,0,0,this my answer, +7,1550496321,0,4,asdfadsfsa, diff --git a/sample_data/question.csv b/sample_data/question.csv index e65825dc3..a62f8f5a8 100644 --- a/sample_data/question.csv +++ b/sample_data/question.csv @@ -12,3 +12,5 @@ app.js (bundled file with webpack, including jquery)","images/image1.png" 2,1493015432,1364,57,"Drawing canvas with an image picked with Cordova Camera Plugin","I'm getting an image from device and drawing a canvas with filters using Pixi JS. It works all well using computer to get an image. But when I'm on IOS, it throws errors such as cross origin issue, or that I'm trying to use an unknown format. This is the code I'm using to draw the image (that works on web/desktop but not cordova built ios app)", +3,1549613789,0,0,adspkfjdséfkj,dsaéflkjadsfélksadjf, +4,1549617317,0,0,question,this is Gergo's question, From 8f895c54eef6f5831c9e91507852309ec1b5d5ba Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Tue, 19 Feb 2019 13:09:15 +0100 Subject: [PATCH 035/120] Add navbar.html to templates --- templates/navbar.html | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 templates/navbar.html diff --git a/templates/navbar.html b/templates/navbar.html new file mode 100644 index 000000000..566549bdf --- /dev/null +++ b/templates/navbar.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file From 3d89253e4106ce217715d986968c213ea6a53376 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Tue, 19 Feb 2019 13:09:37 +0100 Subject: [PATCH 036/120] Fix database id-s --- data_manager.py | 4 --- sample_data/askmatepart2-sample-data.sql | 8 ++--- templates/navbar.html | 37 ++++++++++++++++++------ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/data_manager.py b/data_manager.py index a25fb7cf4..eb633ed79 100644 --- a/data_manager.py +++ b/data_manager.py @@ -1,6 +1,5 @@ import connection from datetime import datetime -import time @connection.connection_handler @@ -52,6 +51,3 @@ def add_answer(cursor, question_id, message): VALUES(%(submission_time)s,%(vote_number)s,%(question_id)s, %(message)s,%(image)s);""", user_story) -def generate_new_id(filename): - new_id = len(connection.read_file(filename)) - return new_id diff --git a/sample_data/askmatepart2-sample-data.sql b/sample_data/askmatepart2-sample-data.sql index 369355a65..cfba8a0d5 100644 --- a/sample_data/askmatepart2-sample-data.sql +++ b/sample_data/askmatepart2-sample-data.sql @@ -95,8 +95,8 @@ ALTER TABLE ONLY comment ALTER TABLE ONLY question_tag ADD CONSTRAINT fk_tag_id FOREIGN KEY (tag_id) REFERENCES tag(id); -INSERT INTO question VALUES (0, '2017-04-28 08:29:00', 29, 7, 'How to make lists in Python?', 'I am totally new to this, any hints?', NULL); -INSERT INTO question VALUES (1, '2017-04-29 09:19:00', 15, 9, 'Wordpress loading multiple jQuery Versions', 'I developed a plugin that uses the jquery booklet plugin (http://builtbywill.com/booklet/#/) this plugin binds a function to $ so I cann call $(".myBook").booklet(); +INSERT INTO question VALUES (1, '2017-04-28 08:29:00', 29, 7, 'How to make lists in Python?', 'I am totally new to this, any hints?', NULL); +INSERT INTO question VALUES (2, '2017-04-29 09:19:00', 15, 9, 'Wordpress loading multiple jQuery Versions', 'I developed a plugin that uses the jquery booklet plugin (http://builtbywill.com/booklet/#/) this plugin binds a function to $ so I cann call $(".myBook").booklet(); I could easy managing the loading order with wp_enqueue_script so first I load jquery then I load booklet so everything is fine. @@ -105,9 +105,9 @@ BUT in my theme i also using jquery via webpack so the loading order is now foll jquery booklet app.js (bundled file with webpack, including jquery)', 'images/image1.png'); -INSERT INTO question VALUES (2, '2017-05-01 10:41:00', 1364, 57, 'Drawing canvas with an image picked with Cordova Camera Plugin', 'I''m getting an image from device and drawing a canvas with filters using Pixi JS. It works all well using computer to get an image. But when I''m on IOS, it throws errors such as cross origin issue, or that I''m trying to use an unknown format. +INSERT INTO question VALUES (3, '2017-05-01 10:41:00', 1364, 57, 'Drawing canvas with an image picked with Cordova Camera Plugin', 'I''m getting an image from device and drawing a canvas with filters using Pixi JS. It works all well using computer to get an image. But when I''m on IOS, it throws errors such as cross origin issue, or that I''m trying to use an unknown format. ', NULL); -SELECT pg_catalog.setval('question_id_seq', 2, true); +SELECT pg_catalog.setval('question_id_seq', 3, true); INSERT INTO answer VALUES (1, '2017-04-28 16:49:00', 4, 1, 'You need to use brackets: my_list = []', NULL); INSERT INTO answer VALUES (2, '2017-04-25 14:42:00', 35, 1, 'Look it up in the Python docs', 'images/image2.jpg'); diff --git a/templates/navbar.html b/templates/navbar.html index 566549bdf..9faf8ed82 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -1,10 +1,29 @@ - - - - - Title - - + From 9881f2e2ca1b957cd0b061a6c1e3616130f78018 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Tue, 19 Feb 2019 13:14:33 +0100 Subject: [PATCH 037/120] Implement the navbar --- templates/answer.html | 2 ++ templates/layout.html | 3 +++ templates/list.html | 2 ++ templates/navbar.html | 1 - templates/newquestion.html | 2 ++ templates/questiondetails.html | 2 ++ 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/templates/answer.html b/templates/answer.html index a9467bc75..c6ffb4c06 100644 --- a/templates/answer.html +++ b/templates/answer.html @@ -1,6 +1,8 @@ {% extends 'layout.html' %} {% block content %} + {% include 'navbar.html' %} +

Post a new answer

diff --git a/templates/layout.html b/templates/layout.html index 06ce29378..ff0f6086b 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -5,8 +5,11 @@ + + + diff --git a/templates/list.html b/templates/list.html index ea2441377..495b7bb96 100644 --- a/templates/list.html +++ b/templates/list.html @@ -1,6 +1,8 @@ {% extends 'layout.html' %} {% block content %} + {% include 'navbar.html' %} +

Ask Mate

diff --git a/templates/navbar.html b/templates/navbar.html index 9faf8ed82..de89b1e3b 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -1,5 +1,4 @@
+ +
- - - - - - {% for question in questions %} - - - - + + + {% endfor %} diff --git a/templates/newquestion.html b/templates/newquestion.html index 00bc13ee0..63c4297be 100644 --- a/templates/newquestion.html +++ b/templates/newquestion.html @@ -3,7 +3,7 @@ {% block content %} {% include 'navbar.html' %} -

Add new question

+

Add new question

diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 55d956dfd..80c0567a6 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -3,45 +3,58 @@ {% block content %} {% include 'navbar.html' %} -

Question Details

+ {% for question in questions %} + {% if id == question['id'] %} -
-
Submission timeTitleView numberVote number
{{ question['submission_time'] }}{{ question['title'] }}{{ question['view_number'] }}{{ question['vote_number'] }} +
+ +
{{ question['view_number'] }}
+
Views
+
+
+
+ +
{{ question['vote_number'] }}
+
Votes
+
+
+ + +
{{ question['submission_time'] }}
+
- - - - - - - - - - - - - {% for question in questions %} - {% if id == question['id'] %} +

{{ question['title'] }}

+ +
+
IdSubmission timeView numberVote numberTitleMessageImage
+ + + - - - - - - + + + - {% endif %} - {% endfor %} - -
{{ question['id'] }}{{ question['submission_time'] }}{{ question['view_number'] }}{{ question['vote_number'] }}{{ question['title'] }}{{ question['message'] }} +
+ +
{{ question['view_number'] }}
+
Views
+
+
+
+ +
{{ question['vote_number'] }}
+
Votes
+
+
+
+

{{ question['message'] }}

+
+ +
{{ question['submission_time'] }}
+
+ + + + {% endif %} + {% endfor %}
-

Answers

+

Answers

{% for answer in answers %} {% if id == answer['question_id'] %} - - + {% endif %} {% endfor %} From f19e9727b31c4e670daa48ebd27160f6cfbda8e4 Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Tue, 19 Feb 2019 14:31:06 +0100 Subject: [PATCH 039/120] route_new_comment, add_comment, newcomment html --- data_manager.py | 19 +++++++++++++++---- server.py | 10 ++++++++++ templates/newcomment.html | 14 ++++++++++++++ templates/questiondetails.html | 3 ++- 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 templates/newcomment.html diff --git a/data_manager.py b/data_manager.py index a25fb7cf4..7680f102d 100644 --- a/data_manager.py +++ b/data_manager.py @@ -1,6 +1,6 @@ import connection from datetime import datetime -import time + @connection.connection_handler @@ -51,7 +51,18 @@ def add_answer(cursor, question_id, message): cursor.execute("""INSERT INTO answer(submission_time, vote_number, question_id, message, image) VALUES(%(submission_time)s,%(vote_number)s,%(question_id)s, %(message)s,%(image)s);""", user_story) +#this is Ivan's first task +#add comment to answer: +@connection.connection_handler +def add_comment(cursor, question_id, message): + + user_story = { + 'submission_time': datetime.now(), + 'question_id': question_id, + 'message': message, + } + + cursor.execute("""INSERT INTO comment(submission_time, question_id, message) + VALUES(%(submission_time)s,%(question_id)s, %(message)s;""", user_story) + -def generate_new_id(filename): - new_id = len(connection.read_file(filename)) - return new_id diff --git a/server.py b/server.py index d3256332d..4074f3151 100644 --- a/server.py +++ b/server.py @@ -36,6 +36,16 @@ def add_question(): return render_template("newquestion.html") +#this is Ivan's first task +#Add comment to answer: +@app.route('/answer//new-comment', methods=['GET', 'POST']) +def route_new_comment(answer_id): + if request.method == "POST": + data_manager.add_comment(question_id, request.form["answer"]) + return redirect(url_for('route_question_id', question_id=question_id)) + + return render_template('comment.html', title="Add New Comment!", question_id=question_id) + if __name__ == "__main__": app.run( diff --git a/templates/newcomment.html b/templates/newcomment.html new file mode 100644 index 000000000..826ada550 --- /dev/null +++ b/templates/newcomment.html @@ -0,0 +1,14 @@ +{% extends 'layout.html' %} + +{% block content %} +

Post a new comment

+ + + +
+ +
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 05b9a4632..0c1eab037 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -39,7 +39,8 @@

Post a new comment {% endif %} {% endfor %} From 144fb37f28a43d5bfe5a6fd8d5f205ac8ca26069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Tue, 19 Feb 2019 14:37:10 +0100 Subject: [PATCH 040/120] Implementing "Vote" function for questions --- connection.py | 2 +- data_manager.py | 23 +++++++++++++++++++++++ server.py | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/connection.py b/connection.py index 6b46997e6..c9bda939a 100644 --- a/connection.py +++ b/connection.py @@ -48,4 +48,4 @@ def wrapper(*args, **kwargs): connection.close() return ret_value - return wrapper \ No newline at end of file + return wrapper diff --git a/data_manager.py b/data_manager.py index c4b15def8..4978172ec 100644 --- a/data_manager.py +++ b/data_manager.py @@ -66,3 +66,26 @@ def search_in_answer_table(cursor, searched_word): {searched_word: '%' + searched_word + '%'}) searched_data = cursor.fetchall() return searched_data + + +def vote_up_question(cursor, question_id): + + variables = { + 'question_id': question_id + } + + cursor.execute("""UPDATE question + SET vote_number = vote_number+1 + WHERE id = %(question_id)s;""", variables) + + +@connection.connection_handler +def vote_down_question(cursor, question_id): + + variables = { + 'question_id': question_id + } + + cursor.execute("""UPDATE question + SET vote_number = vote_number-1 + WHERE id = %(question_id)s;""", variables) diff --git a/server.py b/server.py index 1b91e3389..6427c71cc 100644 --- a/server.py +++ b/server.py @@ -36,11 +36,26 @@ def add_question(): return render_template("newquestion.html") + @app.route("/searched", methods=["GET", "POST"]) def search(): pass +@app.route("/question//vote-up", methods=['GET', 'POST']) +def vote_up(question_id): + if request.method == 'POST': + data_manager.vote_up_question(question_id) + return redirect(url_for('route_question_id', question_id=question_id)) + + +@app.route("/question//vote-down", methods=['GET', 'POST']) +def vote_down(question_id): + if request.method == 'POST': + data_manager.vote_down_question(question_id) + return redirect(url_for('route_question_id', question_id=question_id)) + + if __name__ == "__main__": app.run( debug=True, From 35bab4a8307d64e8272ade6cef6ad8cff8117faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Tue, 19 Feb 2019 14:49:51 +0100 Subject: [PATCH 041/120] Correcting "Vote" function for questions --- data_manager.py | 1 + server.py | 4 ++-- templates/questiondetails.html | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/data_manager.py b/data_manager.py index 4978172ec..5af1e7140 100644 --- a/data_manager.py +++ b/data_manager.py @@ -68,6 +68,7 @@ def search_in_answer_table(cursor, searched_word): return searched_data +@connection.connection_handler def vote_up_question(cursor, question_id): variables = { diff --git a/server.py b/server.py index 6427c71cc..98c758a53 100644 --- a/server.py +++ b/server.py @@ -43,14 +43,14 @@ def search(): @app.route("/question//vote-up", methods=['GET', 'POST']) -def vote_up(question_id): +def vote_up_question(question_id): if request.method == 'POST': data_manager.vote_up_question(question_id) return redirect(url_for('route_question_id', question_id=question_id)) @app.route("/question//vote-down", methods=['GET', 'POST']) -def vote_down(question_id): +def vote_down_question(question_id): if request.method == 'POST': data_manager.vote_down_question(question_id) return redirect(url_for('route_question_id', question_id=question_id)) diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 80c0567a6..5bdebe539 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -35,6 +35,14 @@

python
{{ question['submission_time'] }}
+

@@ -63,4 +71,4 @@

Post a new answer -{% endblock %} \ No newline at end of file +{% endblock %} From 95bc871a98b5856d78b85c4a7bab3dbace1a7abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Wed, 20 Feb 2019 11:05:51 +0100 Subject: [PATCH 042/120] Interpreting "Vote" function for answers --- data_manager.py | 26 ++++++++++++++++++++++++++ server.py | 14 ++++++++++++++ templates/questiondetails.html | 14 ++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/data_manager.py b/data_manager.py index 5af1e7140..2afd27e6c 100644 --- a/data_manager.py +++ b/data_manager.py @@ -90,3 +90,29 @@ def vote_down_question(cursor, question_id): cursor.execute("""UPDATE question SET vote_number = vote_number-1 WHERE id = %(question_id)s;""", variables) + + +@connection.connection_handler +def vote_up_answer(cursor, question_id, answer_id): + + variables = { + 'question_id': question_id, + 'answer_id': answer_id + } + + cursor.execute("""UPDATE answer + SET vote_number = vote_number+1 + WHERE question_id = %(question_id)s AND id = %(answer_id)s;""", variables) + + +@connection.connection_handler +def vote_down_answer(cursor, question_id, answer_id): + + variables = { + 'question_id': question_id, + 'answer_id': answer_id + } + + cursor.execute("""UPDATE answer + SET vote_number = vote_number-1 + WHERE question_id = %(question_id)s AND id = %(answer_id)s;""", variables) diff --git a/server.py b/server.py index 98c758a53..2dc870146 100644 --- a/server.py +++ b/server.py @@ -56,6 +56,20 @@ def vote_down_question(question_id): return redirect(url_for('route_question_id', question_id=question_id)) +@app.route("/question///vote-up", methods=['GET', 'POST']) +def vote_up_answer(question_id, answer_id): + if request.method == 'POST': + data_manager.vote_up_answer(question_id, answer_id) + return redirect(url_for('route_question_id', question_id=question_id)) + + +@app.route("/question///vote-down", methods=['GET', 'POST']) +def vote_down_answer(question_id, answer_id): + if request.method == 'POST': + data_manager.vote_down_answer(question_id, answer_id) + return redirect(url_for('route_question_id', question_id=question_id)) + + if __name__ == "__main__": app.run( debug=True, diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 5bdebe539..0f7219013 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -56,6 +56,12 @@

{{ answer['vote_number'] }} +
Votes
+ +

+ {% endif %} {% endfor %} From d568152adb55ce4c5b48831d46918ed8814c86df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Wed, 20 Feb 2019 11:50:55 +0100 Subject: [PATCH 043/120] Reworked "Vote" function display --- templates/questiondetails.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 0f7219013..8b3b0646e 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -36,11 +36,12 @@

{{ question['submission_time'] }}

@@ -70,11 +71,12 @@

{{ answer['submission_time'] }}

From 8bbb31eaf14968172ac04ddcd7ce86abb8332d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Wed, 20 Feb 2019 13:54:28 +0100 Subject: [PATCH 044/120] minor correction in questiondetails.html --- templates/questiondetails.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 8b3b0646e..9d5f052ea 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -6,7 +6,7 @@ {% for question in questions %} {% if id == question['id'] %} -

{{ question['title'] }}

+

{{ question['title'] }}

{{ answer['submission_time'] }}{{ answer['message'] }} +
+

{{ answer['message'] }}

+
+ +
{{ answer['submission_time'] }}
+
+
+ +
+
+ +
+

{{ answer['message'] }}

@@ -63,6 +69,14 @@

python

{{ answer['submission_time'] }}
+
+ +
+
+ +
+
+
Vote
- +
- +
+
Vote
- +
- +
From f7c9a6315c8849d8ecf399f9f7c7bb2acc1bd767 Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Wed, 20 Feb 2019 13:57:47 +0100 Subject: [PATCH 045/120] all day's work disappeared, P.s. git .fuckoff --- templates/questiondetails.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 0c1eab037..05b9a4632 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -39,8 +39,7 @@

Post a new comment +

{% endif %} {% endfor %} From f73b2f36cd04bf7719a90fd4bcf8845a9749cc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Wed, 20 Feb 2019 14:15:49 +0100 Subject: [PATCH 046/120] Visual update + data_manager function for reading comment table --- data_manager.py | 7 +++++++ templates/list.html | 14 +++++++------- templates/questiondetails.html | 28 +++++++++++++++------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/data_manager.py b/data_manager.py index 2afd27e6c..8ffc821d3 100644 --- a/data_manager.py +++ b/data_manager.py @@ -16,6 +16,13 @@ def get_answers(cursor): return answers +@connection.connection_handler +def get_comments(cursor): + cursor.execute("""SELECT * FROM comment ORDER BY submission_time DESC""") + comments = cursor.fetchall() + return comments + + @connection.connection_handler def add_question(cursor, title, message): user_story = { diff --git a/templates/list.html b/templates/list.html index 87a0ad159..3e1607187 100644 --- a/templates/list.html +++ b/templates/list.html @@ -15,6 +15,13 @@

{% for question in questions %}

+ - {% endfor %} diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 9d5f052ea..062848460 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -14,6 +14,14 @@

+ + - + + {% endif %} From 78e8dc2868a0c14e43db6e9ef3b0ef2fabe93a12 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 20 Feb 2019 22:52:08 +0100 Subject: [PATCH 051/120] Add footer to webpage --- templates/footer.html | 4 ++++ templates/layout.html | 1 + templates/navbar.html | 8 ++++---- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 templates/footer.html diff --git a/templates/footer.html b/templates/footer.html new file mode 100644 index 000000000..6e5bae383 --- /dev/null +++ b/templates/footer.html @@ -0,0 +1,4 @@ +
+

We're working hard Monday through Friday, starting bright and early with a cup of lightly creamed coffee.

+ +
\ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html index 325337057..cb1dbaaf6 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -19,6 +19,7 @@
{% block content %}{% endblock %}
+ {% include 'footer.html' %} diff --git a/templates/navbar.html b/templates/navbar.html index dc7eb684d..7514a05cb 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -6,17 +6,17 @@
{{ answer['submission_time'] }}
-
- - + + + + Editke +
+ + +
- -
{{ answer['submission_time'] }}
+
From 94ec892108d888f8c7982d07e66e01c565532230 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 21 Feb 2019 11:46:12 +0100 Subject: [PATCH 054/120] Change data_manager --- data_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/data_manager.py b/data_manager.py index 121e6d1fa..806638bc7 100644 --- a/data_manager.py +++ b/data_manager.py @@ -8,6 +8,7 @@ def get_questions(cursor): questions = cursor.fetchall() return questions + @connection.connection_handler def get_latest5_questions(cursor): cursor.execute("""SELECT * FROM question ORDER BY submission_time DESC LIMIT 5;""") From ad10969c100cb2e7e201cab867de7c08e2001bab Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 21 Feb 2019 14:26:45 +0100 Subject: [PATCH 055/120] Change layout --- server.py | 8 +------- templates/questiondetails.html | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/server.py b/server.py index a205eee85..d0574edc9 100644 --- a/server.py +++ b/server.py @@ -32,6 +32,7 @@ def route_new_answer(question_id): return render_template('answer.html', title="Add New Answer!", question_id=question_id) + @app.route('/answer//edit', methods=['GET', 'POST']) def edit_answer(answer_id): answers = data_manager.get_answers() @@ -92,13 +93,6 @@ def search(): return redirect(url_for('route_list')) -# @app.route('/answer//delete', methods=['GET', 'POST']) -# def delete_answer(answer_id): -# if request.method == 'POST': -# data_manager.delete_answer(answer_id) -# return redirect(url_for('route_list')) - - @app.route("/question//vote-up", methods=['GET', 'POST']) def vote_up_question(question_id): if request.method == 'POST': diff --git a/templates/questiondetails.html b/templates/questiondetails.html index b6293637b..31b21bea4 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -53,6 +53,7 @@

Answers

+
{{ answer['message'] }}
+ + +
{{ question['submission_time'] }}
+
@@ -29,13 +36,6 @@

Votes

- - -
{{ question['submission_time'] }}
-
+
+

{{ question['message'] }}

+
+ +
{{ question['submission_time'] }}
+
@@ -28,13 +36,6 @@

Votes

-
-

{{ question['message'] }}

-
- -
{{ question['submission_time'] }}
-
Vote
@@ -57,12 +58,7 @@

{{ answer['vote_number'] }} -
Votes
- -

{{ answer['message'] }}

@@ -70,6 +66,12 @@

python

{{ answer['submission_time'] }}
+ +
{{ answer['vote_number'] }}
+
Votes
+
+
Vote
From 14d2028332685fd98f4141c679610eb0c055b96e Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 20 Feb 2019 20:34:36 +0100 Subject: [PATCH 047/120] Implement search feature --- data_manager.py | 15 ++++---------- server.py | 15 ++++++++++++-- templates/navbar.html | 4 ++-- templates/search.html | 47 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 templates/search.html diff --git a/data_manager.py b/data_manager.py index c4b15def8..17b90b9ed 100644 --- a/data_manager.py +++ b/data_manager.py @@ -53,16 +53,9 @@ def add_answer(cursor, question_id, message): @connection.connection_handler -def search_in_question_table(cursor, searched_word): - cursor.execute("""SELECT * FROM question WHERE title LIKE %(searched_word)s OR message LIKE %(searched_word)s;""", - {searched_word: '%' + searched_word + '%'}) - searched_data = cursor.fetchall() - return searched_data - - -@connection.connection_handler -def search_in_answer_table(cursor, searched_word): - cursor.execute("""SELECT * FROM answer WHERE message LIKE %(searched_word)s;""", - {searched_word: '%' + searched_word + '%'}) +def search_in(cursor, searched_word): + cursor.execute("""SELECT question.* FROM question LEFT JOIN answer ON question.id = answer.question_id + WHERE (LOWER(title) LIKE %(searched_word)s OR LOWER(answer.message) LIKE %(searched_word)s OR LOWER(question.message) LIKE %(searched_word)s);""", + {'searched_word': '%' + searched_word + '%'}) searched_data = cursor.fetchall() return searched_data diff --git a/server.py b/server.py index 1b91e3389..994f6fbbf 100644 --- a/server.py +++ b/server.py @@ -36,9 +36,20 @@ def add_question(): return render_template("newquestion.html") -@app.route("/searched", methods=["GET", "POST"]) + +@app.route("/search") def search(): - pass + searched_word = request.args.get('q').lower() + if searched_word is not None: + questions = data_manager.search_in(searched_word) + updated_questions = [] + for question in questions: + if question not in updated_questions: + updated_questions.append(question) + print(updated_questions) + + return render_template('search.html', searched_word=searched_word, questions=updated_questions) + return redirect(url_for('route_list')) if __name__ == "__main__": diff --git a/templates/navbar.html b/templates/navbar.html index de89b1e3b..dc7eb684d 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -20,8 +20,8 @@ - - + + diff --git a/templates/search.html b/templates/search.html new file mode 100644 index 000000000..0bacf374a --- /dev/null +++ b/templates/search.html @@ -0,0 +1,47 @@ +{% extends 'layout.html' %} + +{% block content %} + {% include 'navbar.html' %} + + +

Questions

+
+ + + + + + {% for question in questions %} + + + + + + {% endfor %} + + + +
+
+ +
{{ question['view_number'] }}
+
Views
+
+
+
+ +
{{ question['vote_number'] }}
+
Votes
+
+
+ + +
{{ question['submission_time'] }}
+
+
+ +{% endblock %} \ No newline at end of file From c0ef78899e9bbedaeeec8e0485f31936a3a03014 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 20 Feb 2019 20:48:56 +0100 Subject: [PATCH 048/120] Change datetime.now() with no microseconds --- data_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_manager.py b/data_manager.py index 19ef82a96..f148bcef5 100644 --- a/data_manager.py +++ b/data_manager.py @@ -19,7 +19,7 @@ def get_answers(cursor): @connection.connection_handler def add_question(cursor, title, message): user_story = { - 'submission_time': datetime.now(), + 'submission_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'view_number': 0, 'vote_number': 0, 'title': title, @@ -41,7 +41,7 @@ def add_question(cursor, title, message): def add_answer(cursor, question_id, message): user_story = { - 'submission_time': datetime.now(), + 'submission_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'vote_number': 0, 'question_id': question_id, 'message': message, From c68565ccf54f278609d37e84654f1886764ac783 Mon Sep 17 00:00:00 2001 From: Krisztian Juhasz Date: Wed, 20 Feb 2019 21:22:27 +0100 Subject: [PATCH 049/120] update an answer function added --- data_manager.py | 23 +++++++++++++++++++++++ server.py | 17 ++++++++++++++++- templates/edit_answer.html | 20 ++++++++++++++++++++ templates/navbar.html | 4 ++-- templates/questiondetails.html | 2 ++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 templates/edit_answer.html diff --git a/data_manager.py b/data_manager.py index 2afd27e6c..622bd18a3 100644 --- a/data_manager.py +++ b/data_manager.py @@ -8,6 +8,12 @@ def get_questions(cursor): questions = cursor.fetchall() return questions +@connection.connection_handler +def get_latest5_questions(cursor): + cursor.execute("""SELECT * FROM question ORDER BY submission_time DESC LIMIT 5;""") + questions = cursor.fetchall() + return questions + @connection.connection_handler def get_answers(cursor): @@ -52,6 +58,23 @@ def add_answer(cursor, question_id, message): VALUES(%(submission_time)s,%(vote_number)s,%(question_id)s, %(message)s,%(image)s);""", user_story) +@connection.connection_handler +def get_update(cursor,answer_id , message): + time = datetime.now() + cursor.execute("""UPDATE answer SET message = %(message)s,submission_time = %(time)s WHERE id=%(answer_id)s;""", + {"message":message, 'answer_id':answer_id,'time':time}) + +@connection.connection_handler +def get_question_id(cursor, answer_id): + cursor.execute(""" + SELECT * FROM answer + WHERE id=%(id)s LIMIT 1 + """, + {'id': answer_id}) + return cursor.fetchone()['question_id'] + + + @connection.connection_handler def search_in_question_table(cursor, searched_word): cursor.execute("""SELECT * FROM question WHERE title LIKE %(searched_word)s OR message LIKE %(searched_word)s;""", diff --git a/server.py b/server.py index 2dc870146..1bf922947 100644 --- a/server.py +++ b/server.py @@ -6,10 +6,14 @@ @app.route('/') +def route_main(): + stored_questions = data_manager.get_latest5_questions() + return render_template('list.html', questions=stored_questions, title="Welcome!")\ + @app.route('/list') def route_list(): stored_questions = data_manager.get_questions() - return render_template('list.html', questions=stored_questions, title="Welcome!") + return render_template('list.html', questions=stored_questions, title="Welcome!")\ @app.route('/question/') @@ -27,6 +31,17 @@ def route_new_answer(question_id): return render_template('answer.html', title="Add New Answer!", question_id=question_id) +@app.route('/answer//edit', methods=['GET', 'POST']) +def edit_answer(answer_id): + answers = data_manager.get_answers() + question_id = data_manager.get_question_id(answer_id) + if request.method == "POST": + new_message = request.form['answer'] + data_manager.get_update(answer_id,new_message) + return redirect(f'/question/{question_id}') + + return render_template('edit_answer.html', answer_id=answer_id, answers=answers) + @app.route("/add-question", methods=["GET", "POST"]) def add_question(): diff --git a/templates/edit_answer.html b/templates/edit_answer.html new file mode 100644 index 000000000..c380bd446 --- /dev/null +++ b/templates/edit_answer.html @@ -0,0 +1,20 @@ +{% extends 'layout.html' %} + +{% block content %} + {% include 'navbar.html' %} + +

Edit answer

+ +
+ +
+ {% for answer in answers %} + {% if answer_id == answer['id'] %} + + {% endif %} + {% endfor %} +
+ + +
+{% endblock %} \ No newline at end of file diff --git a/templates/navbar.html b/templates/navbar.html index de89b1e3b..6956dd537 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -1,5 +1,5 @@
Vote
From 22322b161f5cb8401064bceb8ac17d8c873007d7 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Wed, 20 Feb 2019 22:08:36 +0100 Subject: [PATCH 050/120] Implement delete answer --- data_manager.py | 6 ++++++ server.py | 7 +++++++ templates/questiondetails.html | 19 +++++++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/data_manager.py b/data_manager.py index f148bcef5..61602af89 100644 --- a/data_manager.py +++ b/data_manager.py @@ -52,6 +52,12 @@ def add_answer(cursor, question_id, message): VALUES(%(submission_time)s,%(vote_number)s,%(question_id)s, %(message)s,%(image)s);""", user_story) +@connection.connection_handler +def delete_answer(cursor, answer_id): + cursor.execute("""DELETE FROM answer WHERE id = %(answer_id)s;""", + {'answer_id': answer_id}) + + @connection.connection_handler def search_in(cursor, searched_word): cursor.execute("""SELECT question.* FROM question LEFT JOIN answer ON question.id = answer.question_id diff --git a/server.py b/server.py index 3ce007cf6..4453393e0 100644 --- a/server.py +++ b/server.py @@ -52,6 +52,13 @@ def search(): return redirect(url_for('route_list')) +@app.route('/answer//delete', methods=['GET', 'POST']) +def delete_answer(answer_id): + if request.method == 'POST': + data_manager.delete_answer(answer_id) + return redirect(url_for('route_list')) + + @app.route("/question//vote-up", methods=['GET', 'POST']) def vote_up_question(question_id): if request.method == 'POST': diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 9d5f052ea..94078133a 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -33,10 +33,15 @@

python -
{{ question['submission_time'] }}
+
{{ question['submission_time'] }}
+
+
+ +
+

-
Vote
+
Vote
@@ -68,16 +73,22 @@

python -
{{ answer['submission_time'] }}
+
{{ answer['submission_time'] }}
+
+
+ +
+

-
Vote
+
Vote
+
From 761fee52b0a5fec603d119db565af3560c84eeb4 Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Thu, 21 Feb 2019 11:43:29 +0100 Subject: [PATCH 053/120] Delete answer feature done --- data_manager.py | 29 +++++++---------------------- server.py | 10 +++++----- templates/questiondetails.html | 25 ++++++++++--------------- 3 files changed, 22 insertions(+), 42 deletions(-) diff --git a/data_manager.py b/data_manager.py index d9dc79db6..3aa24f80b 100644 --- a/data_manager.py +++ b/data_manager.py @@ -8,6 +8,10 @@ def get_questions(cursor): questions = cursor.fetchall() return questions + + + + @connection.connection_handler def get_latest5_questions(cursor): cursor.execute("""SELECT * FROM question ORDER BY submission_time DESC LIMIT 5;""") @@ -24,7 +28,8 @@ def get_answers(cursor): @connection.connection_handler def delete_answer(cursor, answer_id): - cursor.execute("""delete FROM answer where id=%(answer_id)s;""", {'answer_id': answer_id}) + cursor.execute("""DELETE FROM comment WHERE answer_id=%(answer_id)s;""", {'answer_id': answer_id}) + cursor.execute("""DELETE FROM answer WHERE id=%(answer_id)s;""", {'answer_id': answer_id}) @@ -36,20 +41,6 @@ def get_comments(cursor): return comments - - -# Ivan's delete_comments -@connection.connection_handler -def delete_comments(cursor, comment_id): - cursor.execute("""DELETE FROM comment WHERE id=%(comment_id)s;""", {'comment_id': comment_id}) - - - - - - - - @connection.connection_handler def add_question(cursor, title, message): user_story = { @@ -104,13 +95,7 @@ def delete_comments(cursor, comment_id): cursor.execute("""DELETE FROM comment WHERE id=%(comment_id)s;""", {'comment_id': comment_id}) -@connection.connection_handler -def delete_answer(cursor, answer_id): - cursor.execute("""DELETE FROM answer WHERE id = %(answer_id)s;""", - {'answer_id': answer_id}) - - -@connection.connection_handler +@connection.connection_handler def get_update(cursor,answer_id , message): time = datetime.now() cursor.execute("""UPDATE answer SET message = %(message)s,submission_time = %(time)s WHERE id=%(answer_id)s;""", diff --git a/server.py b/server.py index 58ba3d1a2..a205eee85 100644 --- a/server.py +++ b/server.py @@ -92,11 +92,11 @@ def search(): return redirect(url_for('route_list')) -@app.route('/answer//delete', methods=['GET', 'POST']) -def delete_answer(answer_id): - if request.method == 'POST': - data_manager.delete_answer(answer_id) - return redirect(url_for('route_list')) +# @app.route('/answer//delete', methods=['GET', 'POST']) +# def delete_answer(answer_id): +# if request.method == 'POST': +# data_manager.delete_answer(answer_id) +# return redirect(url_for('route_list')) @app.route("/question//vote-up", methods=['GET', 'POST']) diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 0b7af257e..358fefc51 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -72,9 +72,16 @@

{{ answer['submission_time'] }} -
- -
+
+ + + + Editke +
+ +
+
+

{% for comment in comments %} {% if comment['answer_id'] == answer['id'] %} @@ -88,18 +95,6 @@

Post a new comment - -
{{ answer['submission_time'] }}
-
- - - - Editke -
- -
-
-

{% for answer in answers %} @@ -74,17 +75,27 @@

+

Comments

+ Post a new comment + {% for comment in comments %} {% if comment['answer_id'] == answer['id'] %} - {{ comment['message'] }}
-
{{ comment['submission_time'] }}
- - - -
+
+

{{ comment['message'] }}

+
{{ comment['submission_time'] }}
+
+
+ +
+ +
+
+ + {% endif %} {% endfor %} - Post a new comment + @@ -110,7 +121,5 @@

Post a new answer {% endblock %} From ca102ca451de5196edd5ef5af64612beb4829ae2 Mon Sep 17 00:00:00 2001 From: Krisztian Juhasz Date: Thu, 21 Feb 2019 14:46:36 +0100 Subject: [PATCH 056/120] sort questions function added --- data_manager.py | 7 ++++--- server.py | 12 +++++++++--- templates/list.html | 13 +++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/data_manager.py b/data_manager.py index 0f4f81c69..54911c1bc 100644 --- a/data_manager.py +++ b/data_manager.py @@ -1,17 +1,18 @@ import connection +from psycopg2.extensions import AsIs from datetime import datetime @connection.connection_handler def get_questions(cursor): - cursor.execute("""SELECT * FROM question ORDER BY submission_time DESC;""") + cursor.execute("""SELECT * FROM question ORDER BY submission_time DESC LIMIT 5;""") questions = cursor.fetchall() return questions @connection.connection_handler -def get_latest5_questions(cursor): - cursor.execute("""SELECT * FROM question ORDER BY submission_time DESC LIMIT 5;""") +def get_latest5_questions(cursor,order,direction): + cursor.execute("""SELECT * FROM question ORDER BY %(order)s %(direction)s;""", {"order": AsIs(order), "direction":AsIs(direction.upper())}) questions = cursor.fetchall() return questions diff --git a/server.py b/server.py index d0574edc9..f458a7df5 100644 --- a/server.py +++ b/server.py @@ -4,15 +4,21 @@ app = Flask(__name__) - @app.route('/') def route_main(): - stored_questions = data_manager.get_latest5_questions() + stored_questions = data_manager.get_questions() return render_template('list.html', questions=stored_questions, title="Welcome!")\ -@app.route('/list') +@app.route('/list',methods=['GET']) def route_list(): stored_questions = data_manager.get_questions() + if request.method == "GET": + order = request.args.get('order_by') + direction = request.args.get('direction') + if order == None: + order = 'submission_time' + direction = 'desc' + stored_questions = data_manager.get_latest5_questions(order,direction) return render_template('list.html', questions=stored_questions, title="Welcome!")\ diff --git a/templates/list.html b/templates/list.html index 3e1607187..f2326ca63 100644 --- a/templates/list.html +++ b/templates/list.html @@ -12,6 +12,19 @@

+ {% for question in questions %} From 9a1a82cf12ed98755c7de5d9d204d162300eb684 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Thu, 21 Feb 2019 14:47:49 +0100 Subject: [PATCH 057/120] Get Krisz changes --- templates/questiondetails.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/questiondetails.html b/templates/questiondetails.html index 31b21bea4..356a9e741 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -81,7 +81,7 @@

+

{{ comment['message'] }}

{{ comment['submission_time'] }}
From 7b52ca3194b5f580447ef0ab38cc9ba7f8b96027 Mon Sep 17 00:00:00 2001 From: ivanmatiz Date: Thu, 21 Feb 2019 14:54:55 +0100 Subject: [PATCH 058/120] delete question b version --- data_manager.py | 8 ++++++-- server.py | 14 ++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/data_manager.py b/data_manager.py index 3aa24f80b..6c7297947 100644 --- a/data_manager.py +++ b/data_manager.py @@ -9,7 +9,12 @@ def get_questions(cursor): return questions - +@connection.connection_handler +def delete_question(cursor, question_id): + cursor.execute("""DELETE FROM question_tag WHERE question_id=%(question_id)s;""", {'question_id': question_id}) + cursor.execute("""DELETE FROM comment WHERE question_id=%(question_id)s;""", {'question_id': question_id}) + cursor.execute("""DELETE FROM answer WHERE question_id=%(question_id)s;""", {'question_id': question_id}) + cursor.execute("""DELETE FROM question WHERE id=%(id)s;""", {'id': question_id}) @connection.connection_handler @@ -33,7 +38,6 @@ def delete_answer(cursor, answer_id): -# Ivan's get_comments @connection.connection_handler def get_comments(cursor): cursor.execute("""SELECT * FROM comment ORDER BY submission_time DESC;""") diff --git a/server.py b/server.py index a205eee85..552aaa480 100644 --- a/server.py +++ b/server.py @@ -24,6 +24,13 @@ def route_question_id(question_id): return render_template('questiondetails.html', questions=stored_questions, answers=stored_answers, id=question_id, comments=stored_comments) +@app.route('/question//delete', methods=['GET', 'POST']) +def delete_question(question_id): + if request.method == "POST": + data_manager.delete_question(question_id) + return redirect(url_for('route_list')) + + @app.route('/question//new-answer', methods=['GET', 'POST']) def route_new_answer(question_id): if request.method == "POST": @@ -32,6 +39,7 @@ def route_new_answer(question_id): return render_template('answer.html', title="Add New Answer!", question_id=question_id) + @app.route('/answer//edit', methods=['GET', 'POST']) def edit_answer(answer_id): answers = data_manager.get_answers() @@ -92,12 +100,6 @@ def search(): return redirect(url_for('route_list')) -# @app.route('/answer//delete', methods=['GET', 'POST']) -# def delete_answer(answer_id): -# if request.method == 'POST': -# data_manager.delete_answer(answer_id) -# return redirect(url_for('route_list')) - @app.route("/question//vote-up", methods=['GET', 'POST']) def vote_up_question(question_id): From 03f7095cc1dc7fe738bebfaf8e6fc69898493d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Thu, 21 Feb 2019 16:14:33 +0100 Subject: [PATCH 059/120] Implemented adding comment to questions and editing comment functions --- data_manager.py | 58 ++++++++++++++++++++++++++++------ server.py | 56 ++++++++++++++++++++++++-------- templates/edit_comment.html | 20 ++++++++++++ templates/newcomment.html | 6 +++- templates/questiondetails.html | 16 ++++++++++ 5 files changed, 132 insertions(+), 24 deletions(-) create mode 100644 templates/edit_comment.html diff --git a/data_manager.py b/data_manager.py index 0f4f81c69..22fbf15f3 100644 --- a/data_manager.py +++ b/data_manager.py @@ -74,16 +74,26 @@ def add_answer(cursor, question_id, message): @connection.connection_handler -def add_comment(cursor, answer_id, message): +def add_comment(cursor, question_id, answer_id, message): + if question_id == '': + user_story = { + 'submission_time': datetime.now(), + 'message': message, + 'answer_id': answer_id + } - user_story = { - 'submission_time': datetime.now(), - 'message': message, - 'answer_id': answer_id - } + cursor.execute("""INSERT INTO comment(submission_time, answer_id, message) + VALUES(%(submission_time)s, %(answer_id)s, %(message)s);""", user_story) + + elif answer_id == '': + user_story = { + 'submission_time': datetime.now(), + 'message': message, + 'question_id': question_id + } - cursor.execute("""INSERT INTO comment(submission_time, answer_id, message) - VALUES(%(submission_time)s,%(answer_id)s, %(message)s);""", user_story) + cursor.execute("""INSERT INTO comment(submission_time, question_id, message) + VALUES(%(submission_time)s, %(question_id)s, %(message)s);""", user_story) @connection.connection_handler @@ -95,7 +105,27 @@ def delete_comments(cursor, comment_id): def get_update(cursor,answer_id , message): time = datetime.now() cursor.execute("""UPDATE answer SET message = %(message)s,submission_time = %(time)s WHERE id=%(answer_id)s;""", - {"message":message, 'answer_id':answer_id,'time':time}) + {"message": message, 'answer_id': answer_id, 'time': time}) + + +@connection.connection_handler +def get_update_for_comment(cursor, comment_id, message): + time = datetime.now() + cursor.execute("""UPDATE comment SET + message = %(message)s, + submission_time = %(time)s, + edited_count = %(count)s + WHERE id=%(comment_id)s;""", {"message": message, 'comment_id': comment_id, 'time': time, 'count': 1}) + + +@connection.connection_handler +def get_new_update_for_comment(cursor, comment_id, message): + time = datetime.now() + cursor.execute("""UPDATE comment SET + message = %(message)s, + submission_time = %(time)s, + edited_count = edited_count + 1 + WHERE id=%(comment_id)s;""", {"message": message, 'comment_id': comment_id, 'time': time}) @connection.connection_handler @@ -108,6 +138,16 @@ def get_question_id(cursor, answer_id): return cursor.fetchone()['question_id'] +@connection.connection_handler +def get_question_id_for_comment(cursor, comment_id): + cursor.execute(""" + SELECT * FROM comment + WHERE id=%(id)s LIMIT 1 + """, + {'id': comment_id}) + return cursor.fetchone()['question_id'] + + @connection.connection_handler def search_in(cursor, searched_word): cursor.execute("""SELECT question.* FROM question LEFT JOIN answer ON question.id = answer.question_id diff --git a/server.py b/server.py index a205eee85..7a4f4c25c 100644 --- a/server.py +++ b/server.py @@ -8,20 +8,29 @@ @app.route('/') def route_main(): stored_questions = data_manager.get_latest5_questions() + return render_template('list.html', questions=stored_questions, title="Welcome!")\ + + @app.route('/list') def route_list(): stored_questions = data_manager.get_questions() return render_template('list.html', questions=stored_questions, title="Welcome!")\ + @app.route('/question/') def route_question_id(question_id): stored_questions = data_manager.get_questions() stored_answers = data_manager.get_answers() stored_comments = data_manager.get_comments() - return render_template('questiondetails.html', questions=stored_questions, answers=stored_answers, id=question_id, comments=stored_comments) + + return render_template('questiondetails.html', + questions=stored_questions, + answers=stored_answers, + id=question_id, + comments=stored_comments) @app.route('/question//new-answer', methods=['GET', 'POST']) @@ -32,6 +41,7 @@ def route_new_answer(question_id): return render_template('answer.html', title="Add New Answer!", question_id=question_id) + @app.route('/answer//edit', methods=['GET', 'POST']) def edit_answer(answer_id): answers = data_manager.get_answers() @@ -60,13 +70,39 @@ def add_question(): return render_template("newquestion.html") -@app.route('/answer//new-comment', methods=['GET', 'POST']) -def route_new_comment(answer_id): +@app.route('/question//new-comment', methods=['GET', 'POST']) +@app.route('/answer//new-comment', methods=['GET', 'POST']) +def route_new_comment(question_id='', answer_id=''): if request.method == "POST": - data_manager.add_comment(answer_id, request.form["comment"]) - return redirect(url_for('route_list')) + if question_id == '': + data_manager.add_comment(question_id, answer_id, request.form["comment"]) + return redirect(url_for('route_list')) + elif answer_id == '': + data_manager.add_comment(question_id, answer_id, request.form["comment"]) + return redirect(url_for('route_list')) - return render_template('newcomment.html', title="Add New Comment!", answer_id=answer_id) + return render_template('newcomment.html', title="Add New Comment!", answer_id=answer_id, question_id=question_id) + + +@app.route('/comment//edit', methods=['GET', 'POST']) +def edit_comment(comment_id): + comments = data_manager.get_comments() + question_id = data_manager.get_question_id_for_comment(comment_id) + if request.method == "POST": + edit_counter = '' + for comment in comments: + if comment['id'] == comment_id: + edit_counter = comment['edited_count'] + if edit_counter is None: + new_message = request.form['comment'] + data_manager.get_update_for_comment(comment_id, new_message) + return redirect('/') + elif edit_counter is not None: + new_message = request.form['comment'] + data_manager.get_new_update_for_comment(comment_id, new_message) + return redirect('/') + + return render_template('edit_comment.html', comment_id=comment_id, comments=comments) @app.route('/comments//delete', methods=['GET', 'POST']) @@ -76,7 +112,6 @@ def delete_comment(comment_id): return redirect(url_for('route_list')) - @app.route("/search") def search(): searched_word = request.args.get('q').lower() @@ -92,13 +127,6 @@ def search(): return redirect(url_for('route_list')) -# @app.route('/answer//delete', methods=['GET', 'POST']) -# def delete_answer(answer_id): -# if request.method == 'POST': -# data_manager.delete_answer(answer_id) -# return redirect(url_for('route_list')) - - @app.route("/question//vote-up", methods=['GET', 'POST']) def vote_up_question(question_id): if request.method == 'POST': diff --git a/templates/edit_comment.html b/templates/edit_comment.html new file mode 100644 index 000000000..899b62fd8 --- /dev/null +++ b/templates/edit_comment.html @@ -0,0 +1,20 @@ +{% extends 'layout.html' %} + +{% block content %} + {% include 'navbar.html' %} + +

Edit comment

+ + + +
+ {% for comment in comments %} + {% if comment_id == comment['id'] %} + + {% endif %} + {% endfor %} +
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/newcomment.html b/templates/newcomment.html index da473cbea..9555fb1ad 100644 --- a/templates/newcomment.html +++ b/templates/newcomment.html @@ -2,13 +2,17 @@ {% block content %}

Post a new comment

- + {% if answer_id == '' %} +
+ {% else %} + {% endif %}
+ {% endblock %} \ No newline at end of file diff --git a/templates/questiondetails.html b/templates/questiondetails.html index b6293637b..4de1e65de 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -21,6 +21,20 @@

python

{{ question['submission_time'] }}
+
+ {% for comment in comments %} + {% if comment['question_id'] == question['id'] %} + {{ comment['message'] }}
+
Edited {{ comment['edited_count'] }} times
+
{{ comment['submission_time'] }}
+ Edit +
+ + +
+ {% endif %} + {% endfor %} + Post a new comment

@@ -77,7 +91,9 @@

Edited {{ comment['edited_count'] }} times

{{ comment['submission_time'] }}
+ Edit
From d0b9af607b6f4a5232f5b9582c09f0bb213713c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Fri, 22 Feb 2019 13:21:51 +0100 Subject: [PATCH 060/120] Question comment buttons corrected --- server.py | 1 + templates/questiondetails.html | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server.py b/server.py index a1b72dd39..65f35f927 100644 --- a/server.py +++ b/server.py @@ -4,6 +4,7 @@ app = Flask(__name__) + @app.route('/') def route_main(): stored_questions = data_manager.get_questions() diff --git a/templates/questiondetails.html b/templates/questiondetails.html index d450d5131..f1cf7a9ce 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -30,14 +30,18 @@

Edited {{ comment['edited_count'] }} times -
{{ comment['submission_time'] }}
- Edit -
- -
-
+
+

{{ comment['message'] }}

+
Edited {{ comment['edited_count'] }} times
+
{{ comment['submission_time'] }}
+
+ Edit +
+ +
+
+
+
{% endif %} {% endfor %} Post a new comment @@ -113,8 +117,6 @@

Date: Mon, 4 Mar 2019 15:02:29 +0100 Subject: [PATCH 062/120] modified sql for sprint 3 (added users table) --- sample_data/askmatepart2-sample-data.sql | 42 ++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/sample_data/askmatepart2-sample-data.sql b/sample_data/askmatepart2-sample-data.sql index cfba8a0d5..322b3817f 100644 --- a/sample_data/askmatepart2-sample-data.sql +++ b/sample_data/askmatepart2-sample-data.sql @@ -6,15 +6,19 @@ -- Dumped by pg_dump version 9.5.6 ALTER TABLE IF EXISTS ONLY public.question DROP CONSTRAINT IF EXISTS pk_question_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.question DROP CONSTRAINT IF EXISTS fk_user_id CASCADE; ALTER TABLE IF EXISTS ONLY public.answer DROP CONSTRAINT IF EXISTS pk_answer_id CASCADE; ALTER TABLE IF EXISTS ONLY public.answer DROP CONSTRAINT IF EXISTS fk_question_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.answer DROP CONSTRAINT IF EXISTS fk_user_id CASCADE; ALTER TABLE IF EXISTS ONLY public.comment DROP CONSTRAINT IF EXISTS pk_comment_id CASCADE; ALTER TABLE IF EXISTS ONLY public.comment DROP CONSTRAINT IF EXISTS fk_question_id CASCADE; ALTER TABLE IF EXISTS ONLY public.comment DROP CONSTRAINT IF EXISTS fk_answer_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.comment DROP CONSTRAINT IF EXISTS fk_user_id CASCADE; ALTER TABLE IF EXISTS ONLY public.question_tag DROP CONSTRAINT IF EXISTS pk_question_tag_id CASCADE; ALTER TABLE IF EXISTS ONLY public.question_tag DROP CONSTRAINT IF EXISTS fk_question_id CASCADE; ALTER TABLE IF EXISTS ONLY public.tag DROP CONSTRAINT IF EXISTS pk_tag_id CASCADE; ALTER TABLE IF EXISTS ONLY public.question_tag DROP CONSTRAINT IF EXISTS fk_tag_id CASCADE; +ALTER TABLE IF EXISTS ONLY public.users DROP CONSTRAINT IF EXISTS pk_user_id CASCADE; DROP TABLE IF EXISTS public.question; DROP SEQUENCE IF EXISTS public.question_id_seq; @@ -25,7 +29,8 @@ CREATE TABLE question ( vote_number integer, title text, message text, - image text + image text, + user_id integer ); DROP TABLE IF EXISTS public.answer; @@ -36,7 +41,8 @@ CREATE TABLE answer ( vote_number integer, question_id integer, message text, - image text + image text, + user_id integer ); DROP TABLE IF EXISTS public.comment; @@ -47,7 +53,8 @@ CREATE TABLE comment ( answer_id integer, message text, submission_time timestamp without time zone, - edited_count integer + edited_count integer, + user_id integer ); @@ -65,6 +72,20 @@ CREATE TABLE tag ( ); +DROP TABLE IF EXISTS public.users; +DROP SEQUENCE IF EXISTS public.users_id_seq; +CREATE TABLE users ( + id serial NOT NULL, + username varchar(255) NOT NULL, + salt varchar(255) NOT NULL, + password varchar(255) NOT NULL, + registration_date date NOT NULL DEFAULT CURRENT_DATE +); + + +ALTER TABLE ONLY users + ADD CONSTRAINT pk_user_id PRIMARY KEY (id); + ALTER TABLE ONLY answer ADD CONSTRAINT pk_answer_id PRIMARY KEY (id); @@ -83,9 +104,18 @@ ALTER TABLE ONLY tag ALTER TABLE ONLY comment ADD CONSTRAINT fk_answer_id FOREIGN KEY (answer_id) REFERENCES answer(id); +ALTER TABLE ONLY comment + ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users(id); + ALTER TABLE ONLY answer ADD CONSTRAINT fk_question_id FOREIGN KEY (question_id) REFERENCES question(id); +ALTER TABLE ONLY answer + ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users(id); + +ALTER TABLE ONLY question + ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users(id); + ALTER TABLE ONLY question_tag ADD CONSTRAINT fk_question_id FOREIGN KEY (question_id) REFERENCES question(id); @@ -113,8 +143,8 @@ INSERT INTO answer VALUES (1, '2017-04-28 16:49:00', 4, 1, 'You need to use brac INSERT INTO answer VALUES (2, '2017-04-25 14:42:00', 35, 1, 'Look it up in the Python docs', 'images/image2.jpg'); SELECT pg_catalog.setval('answer_id_seq', 2, true); -INSERT INTO comment VALUES (1, 0, NULL, 'Please clarify the question as it is too vague!', '2017-05-01 05:49:00'); -INSERT INTO comment VALUES (2, NULL, 1, 'I think you could use my_list = list() as well.', '2017-05-02 16:55:00'); +INSERT INTO comment VALUES (1, 1, NULL, 'Please clarify the question as it is too vague!', '2017-05-01 05:49:00'); +INSERT INTO comment VALUES (2, NULL, 2, 'I think you could use my_list = list() as well.', '2017-05-02 16:55:00'); SELECT pg_catalog.setval('comment_id_seq', 2, true); INSERT INTO tag VALUES (1, 'python'); @@ -122,6 +152,6 @@ INSERT INTO tag VALUES (2, 'sql'); INSERT INTO tag VALUES (3, 'css'); SELECT pg_catalog.setval('tag_id_seq', 3, true); -INSERT INTO question_tag VALUES (0, 1); +INSERT INTO question_tag VALUES (1, 2); INSERT INTO question_tag VALUES (1, 3); INSERT INTO question_tag VALUES (2, 3); From 955a1e62b667eca03c7f0545c549e9593db5909d Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 4 Mar 2019 16:48:56 +0100 Subject: [PATCH 063/120] Make register func to render the registe.html --- server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server.py b/server.py index 5418e5ed6..db59d94ee 100644 --- a/server.py +++ b/server.py @@ -172,6 +172,11 @@ def login(): return render_template('login.html') +@app.route("/register") +def register(): + return render_template('register.html') + + if __name__ == "__main__": app.run( debug=True, From 684d4c62d1338312fad0c044bf412bb663a97e99 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 4 Mar 2019 17:35:59 +0100 Subject: [PATCH 064/120] Add register page --- server.py | 2 +- templates/navbar.html | 2 +- templates/register.html | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 templates/register.html diff --git a/server.py b/server.py index db59d94ee..2be2afe38 100644 --- a/server.py +++ b/server.py @@ -172,7 +172,7 @@ def login(): return render_template('login.html') -@app.route("/register") +@app.route("/registration") def register(): return render_template('register.html') diff --git a/templates/navbar.html b/templates/navbar.html index 55bc367b7..00ff0c2e6 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -13,7 +13,7 @@ From 84af3126058d1a4ff5a2843b45c7eda72608e982 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 4 Mar 2019 17:56:32 +0100 Subject: [PATCH 067/120] Chane post comment font --- templates/newcomment.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/newcomment.html b/templates/newcomment.html index 9555fb1ad..821461624 100644 --- a/templates/newcomment.html +++ b/templates/newcomment.html @@ -1,7 +1,7 @@ {% extends 'layout.html' %} {% block content %} -

Post a new comment

+

Post a new comment

{% if answer_id == '' %}
{% else %} From 5c053c80e47b5f8a76da199f1dd07d83751480de Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 4 Mar 2019 19:41:52 +0100 Subject: [PATCH 068/120] Make simple user_page --- server.py | 10 ++++-- static/css/main.css | 34 ++++++++++++++++++- templates/user_profile.html | 68 +++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 templates/user_profile.html diff --git a/server.py b/server.py index 2be2afe38..231071a74 100644 --- a/server.py +++ b/server.py @@ -11,7 +11,7 @@ def route_main(): return render_template('list.html', questions=stored_questions, title="Welcome!") -@app.route('/list',methods=['GET']) +@app.route('/list', methods=['GET']) def route_list(): stored_questions = data_manager.get_questions() if request.method == "GET": @@ -20,7 +20,7 @@ def route_list(): if order == None: order = 'submission_time' direction = 'desc' - stored_questions = data_manager.get_latest5_questions(order,direction) + stored_questions = data_manager.get_latest5_questions(order, direction) return render_template('list.html', questions=stored_questions, title="Welcome!")\ @@ -177,6 +177,12 @@ def register(): return render_template('register.html') +@app.route("/user") +def profile(): + stored_questions = data_manager.get_questions() + return render_template('user_profile.html', questions=stored_questions) + + if __name__ == "__main__": app.run( debug=True, diff --git a/static/css/main.css b/static/css/main.css index 7f301f0c7..b78fb5919 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1,3 +1,5 @@ +/********** Register and login css **********/ + .wrapper { margin-top: 40px; } @@ -44,4 +46,34 @@ height: 1px; margin-top: 0px !important; margin-bottom: 0px !important; -} \ No newline at end of file +} + +/*********** Profile css **********/ + +.user_name { + font-family: 'Fredericka the Great', Tahoma, sans-serif; + margin-top: 8px; + margin-bottom: 40px; +} + +.profile-head .nav-tabs{ + margin-bottom:5%; +} + +.profile-head .nav-tabs .nav-link { + font-weight: 600; + border: none; +} + +.nav-item-profile { + font-family: 'Fredericka the Great', Tahoma, sans-serif; + font-size: 18px; +} + +.row-header { + margin-bottom: 28px; +} + +.row-questions { + margin-bottom: 16px; +} diff --git a/templates/user_profile.html b/templates/user_profile.html new file mode 100644 index 000000000..8228a571c --- /dev/null +++ b/templates/user_profile.html @@ -0,0 +1,68 @@ +{% extends 'layout.html' %} + +{% block content %} + {% include 'navbar.html' %} + +
+ +
+
+ +
+
+ +
+
+

+ Here should be the user name! +

+ +
+
+
+
+ {% for question in questions %} +
+
+ + +
{{ question['submission_time'] }}
+ +
+
+
+ +
{{ question['view_number'] }}
+
Views
+
+
+
+
+
+ +
{{ question['vote_number'] }}
+
Votes
+
+
+
+

+ +
+ {% endfor %} + +
+ + +{% endblock %} \ No newline at end of file From 457fdb70cd6eb8c198963246ac73ed479cf8a010 Mon Sep 17 00:00:00 2001 From: Andras Molnar Date: Mon, 4 Mar 2019 19:48:25 +0100 Subject: [PATCH 069/120] Add default user picture to profile page --- static/css/main.css | 9 ++++++++- static/img/user.png | Bin 0 -> 6758 bytes templates/user_profile.html | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 static/img/user.png diff --git a/static/css/main.css b/static/css/main.css index b78fb5919..1c2b485b3 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -56,7 +56,14 @@ margin-bottom: 40px; } -.profile-head .nav-tabs{ +.profile-img img { + width: 80%; + height: 100%; + margin-top: 8px; + border-radius: 50%; +} + +.profile-head .nav-tabs { margin-bottom:5%; } diff --git a/static/img/user.png b/static/img/user.png new file mode 100644 index 0000000000000000000000000000000000000000..c422791623e540565801fa23ffead60d379c32ab GIT binary patch literal 6758 zcmb_>2UwEryEs`{NsgA86SZL}iVOEjP1H0)bKoc~O z7zSH=#@EH2;qGwQkU*!Z<5ywSL#h4{HVkHL7V3{DP>2k~Ng~OYW}-AzR;7gSJ!PWg zrt5%m@V6wM@x`1ABs!mSbRnFh5DZQ!nVBMtLk%GUR3Zb92&MYbf(%1Vlz!7SgvP7O z8cK-YAPkC$(%(Y4J2)XM>48LquDUjofYQ`Npwa4@I=X1IrW!&ErKzQXg5GGPrjDU5 z+E7am@y|;M;ud)7v?12&&_BGOnTgUF2E*S_Ln9<4L_I`XogPTi&@?bGSf!z*g@hoG zL18ooJ`_m{QvO51iWo!)^z~=>(rJiQiujZCV1|hjBbqco`0)pPxZ4q{-5|0%}5g${BF^CxOxi9z(>Kmufs)5?F4A>IAYj8*|5X$+49 z`a(v*`&rQm!BirRVQXcg1nsDw@;zmU($$BwsHcO{(?X&3H8u57`q~Cs+6S$yEw%Lx z^mYEw_;Zp=BTu&!7jo(CL1EJizG;ok0&eL-$8mI-?OP4tRnuZFOP)s)7DKuN5)S z_bl<$p+Gtn@ms@&zW+u7l-~dECBN9jhDTXGO*V=A0=QIWE58j0m86w=<)wf zFv$P1^JjvELpc9!@`uXroj;TR3zDSO^K zoKfa&bKxmxaZy}vQB|hZ5?h;L+5Aj1WD2E58`DI=3S;K!0_ILO>tVw45MH{d>B(1(aJXVgoEMu#*wj8Y zntfy{XGW{n(Wxt$88-VP^RBaNUOm)Uk~hl$gu~ z+siqYiX|ANk}CA@*p<_uo=jg>&mHL?6*fzFQ&>gVO2AsP$z%DY4Q-U2t)8!L;c}!TdT%Wh zxsA3Oh+*xY^Yj)wrc4hke?fWV?28egHTe@F_ljTq*^J)p5T+^HXi47~o*-16|Q)YgOB$30{wr)s9rYO;0_s9$wY;S5ITn z6FCuQWH8RX_kCAkZ~01Rey59lvvLx=DbA}TrYhgtc*^Mxxy|DvkLRZfepWliosF!V ze>bGYmQ34|SM9nDyoF=1N`#YMGh}}+Wws;+dji&^D=pqyz#g8xJ?W??P!}&ke}$oP zAf*{LX1lvy$HldG9f9Zs43K&trrNLAtj99v4emJHET1(NcWZ5iBcds#I4$VMJpURdT+O*$ivj^ik&ZjjOmDn(ShRy0I z1D9UA)Cl@>GvfHqo#~O_IrFCk1#WH#?>agM&fma&6j6@bAAL3d(Ruh?uCyk? zuv;XP<5A;3n27oSPy2O#1{gws4guYy+NTXQUs=_zWSQ!{Hk%>i{n*wktg$-q!awk5 z5ejbMKE5Oriwb)Jdk)BmqdM)7ZC#;J5W*D-P()zw0jg)ypM=;^uUN*6>3W^EMQX-| z@wSO$zP%)>4xh!P{FW2Wc2ioNnErsk9{??f6qM7E( zA@g@no~9D86n5-qmSMNpMeaz%*3_Mtv~CVIwHN~EE@RWns_1)@`PWK|?M-hV=Si^9 zL+u@GbNL)a3^gxDK6wjeBQ|yF&cM}cLg0 zHucJ-vrPlz)?`AFLCX2At?FP{fm3|7B%u4ghQeU>8$zrj$W;LnZ|@lqu&H%cCv1>m zMNtTFSAnbjBos0SlOU}h!a+*RAl5gFE}X^KhLauL12(4p55XL7um;Yl_2+m z<_ucAZSJ=1he7Pvx>%)7M`h3uj#UL6h%>Nc+$$GV&>RQMs8|CI*S-6rxQ9lIuKms) z$=4%)qx+qODE{|UvMV$skZX~Qg8}Q!$%IhSlEa2I$@~&Wj_hG`@`bgjsplIllKI;~ z2QZ5J25r(8C;>r=ky|Pu^>hkhyS-QxO&tW-=J4W({zfTj2sHu;-XW*(=bb0=W!H%e zOzUG)L&*-{%~wyFGSR-X^(W4llhYpiBY5OYSF!~ulOr%LOYf;r2C=ENzF#AR!iq>o z$=>HJ81fk^;I2DoG79#kG&xhY93}^y0N}TY7%F4(8s5pAtXi^M$hEGFzF6c&F0#!9 zBuN_BvGcJRT5YC-+7Q={V|TbGt<1^F%*e0oX!En``t(e+M*9%5jH3BL3EZ)nLl6@R z3+A0ifD6xk;5aW*FkUo9;J6rDqW>+ip&GI!Xns0Bk#$aM9yU96!rLE70{LOb_v2E7L-$BoAJzg$YJtfFBALJLgi$V6 zS^+WJT@{Q3kd9Ic<379Pf^IyX$kyEhJrc8p6NwnJ+-n4Qofmz z?du#5vN;yl|4ObyyL>v z(jy2kVVfcIL#FHwk)7D|Pz2~0{*9*&z7Cl97`EYp$oU_A-I6(MPU*;An{b!gB97XN z@J!AZ)5_4kk_++sfIWGCdCbLL8GX0pQM?WcXfg3dWpY?C`}V^^&}>A24rJ7whp>$n;XkWm;O1gurzpGc8ze?^14}xtrEx+pv2c%$ zZ{qtlR>v0Ay}ZE<+zxS~r3Acku5(kdMcRY}FW;~47fjcn#$4}k1HA^1eHyw|Zl|x; zBXR>5H*}jyA?)WqQsw4{_LvotjoLC65Pk2qH2e)9>7pL4m`BUBR~wm}+bstR&lyUkXX zi+wH-;Zs?Ls$fap>$3gW?rZ#)o>(?y9oJ8ptQTHop?%X-`>lOOCi0cLY0qvBeINe< z)eK`H3e>qdxrCm6eebM0WZPfY+u!?C)<`Xm_OG~-GFe>+gj`i1IN&zq6G zs^fh}dU5_^n2{)(wN)+n?D%1f|D6iM$QHd`J7i`;@k7qTQZZ{0;p0JLTO^?>WoV*# zF)6o?XVeq{`3)z?7CD?$T+GT)gEHs#5AaygG*C+w)T#S<+U#1fs!W-fwQg3ur(z*z z7Y6C@qJ&pgvGn@f!SNkyi>s1xW1AK;@=d+ndkf7J;~=kDK{4N4T?1vwYB0*k>+g!J zix35QQg2`1#PB}TDMTR#c~KR5tViy5uQhpaBR2)A3#}xf^j=-j(e>PZ@Yq35v-`ef zf>^GWEW{t4eIz_@?l`0_jn;I5*9kUj5MD%mN^BqrH$ zPSm48F6T{ze$c!6iewyFBCaR1W%k`0T1wF5gMyt|jyM%_vMsR%VkR~$YW8V)O3S2A zq@ALYvr7`#b2QokE{;wg)&1)D;z&%v?`pW)Pz`JEc#vG1TvjMps_SnsvGzk%I3`u? z&&MFGky^$*;~~s`(@@QCuEx{pehKB;efO3pTT`QV@#yP-%q=xf%X<4GOBNjF7pmi* z&&_X=-yMv4Q8~ZR{H?e^3H;U`FMf$klX5`{C96Hzd*!;L-N)$ef4UOt*OwI)sdEY| zbH|rQ9(rtcTcgmedPQy{=&@Ssn1(OR_(S!u%~Zw2TmSR$Y|laD`A6X&Yq*`mUD`C1 z9d%oMr&Fh!$uLw*N- zV;=W(PIq@%z+9U|#;#C2d3-2-v_fiLfMQNB4|U`%Gi`3;o-8Z+Y<|e8JR5skBellp zr-Xu)0n`_@G3iG2Y;^G7o@@OJSNlzCqlR#HabKHq#p5c$$uhiteb#Z~*sTEae5HSG zeYPx#I6F|YNzzf9;)?CQyioJGx-l+7d;p|>7)?;Rgjj$hK7 zS*`PnuJiehzZ4>8pG!V0!k5o1WEA$d)!uSW=r{3ewj;|JHZ6Dl2vuFzK?;KxRd$J| zIDATtODM*6zsB?8ANt|rDk_%PKbf$6IeKoN9hGs6rmdf7uRQ_jb)8;+@$^d;Q9R;e zti4LeMmGAYXX6p9>0)G)T+v}=875`cDMs)65wkl5YYvewEeYw5M;pH{?U@#wO-b0- z#F@NhJK>*0pEXYX?CD)+^xY*8|CODzR<8YoE+@*< z$0lNQxqT|)F$bGnv;pTn?>}-=M($F@0h||;!|k$NQI37Sa4nj<95ZgZ$#odMm&?1K zU0}nk6)Vc++fB^b^>TL*TEauVBgabDLJ<<`K6K|#XH_TVNyKd}1;_v^SIb|mgQE3MbU#|@o+sYwvrx##m?mE>UKn~*o2Q;vy_FCuqDV9tZ;O}S8@dyqT0A*A>>Q@4kl z2_EJ$9qQn#TfrY8PVaX{R?2PXC}wPS@dQ3}Wr1KB45=;CE2aPwPq^pcEZ#Rg)8xtvh@W%lx5w z6UtU!)Yv%&W6ZiN&fO3L#d5)?{fFfc?tlOO4GYHlTZVNO-)9%;vU6* z@9|lF$+qq;cP@ikCo6d70pB+C5ce#T*w2@U>u@ubHSZcz`B!c<7 zE}ee&Gw|%|=fZ(^UwrpI^mac8#Z#8pgN7PwYF62nLR+eSWo-CfY5j|btMDPa9}kVK zg};LGN}>Y!tuknzCa2&I6RufLI~(mL42afqH%Lb1q$XRC8|U5SQC9Jkit;>$^AYN0 zKj8S7u&j+wH1#V`fmcR;bB0pau4cUL6J9TBfOLuxsrH5YQbu^`+O^4~%v4-RZBz%& zYm6vRd~f9})0fjDy7p@6lAP^q=YpSM$=3mUz3Za`>{C`UO_I=Sq}XwfIA zy#Zm#1D9FfpAiCqiV52*uLfgVA}W8nki`w(|7;TS*MW}MAja{{`4 zzMe>RA}72s2coG5pteb9y*LM8uL2l%?oC+*m_3ndwF=M`P5reBP$$lrd9n&%*2%li zhvdM(t)%@{X<8}xwTJb%r2#WuxCe^0UTJ{07jwh~_NXQ3it$a5!~HpndLRV%?UBt! zg3vEQl_r}nQ;7t<*nDm-5~N*T)4a=X%$6FO@nv@Q{u=Z3PvAJLj=DDW}KMZW^i%xh+Dv&jR?_Iv}TAXyzG3^x;cx9(}e~V(nMZrM=zlnSE}G zB!*Csi?8Fn?W?;>=p8TO4KZR#N|7}*^htDG#$XojCgdHM=@NE zvkzb?wy{H*J>`er5~jI5PR>RX5$oPk3L~BtN)Xw%r7D6^~kXtUONQ_ekeh zX`GV<)Sa1MeU{UX(OlUJyM!H+4wu7ljPb{lcgKX z-yLAeAAAkTb`G|i4ykX7`*NQ!JO7@i-E%Bdd*sh6zkwyBlA$9NN{rNqkY!XssK{B| zA>{G&gs7q`Is0zIn!?Y=ZgPJHdLfi|j2}+84%zucK`sK6Bwr}U$`s?Wa8a9|;4eq`C)Gab8jSkN1DL>hF@Y=edIl8_@Juuj(*XL?s?49%-={rKdAO_$jivmQ zpUf&i+Gz@A_GhKz;9wMhK1UAUz4L8v?Q3TWd%Z|OZ-0_N#~N6F*|bv(37VF}ZYsVR z(0{?5{kif(M(8SL;+vl09rBt-9e!tknedb5yH0Y)SJq3x`0ib;F;3T!tN;AiT02_h J9XxUIKLEN|s0jc7 literal 0 HcmV?d00001 diff --git a/templates/user_profile.html b/templates/user_profile.html index 8228a571c..fcd2e7543 100644 --- a/templates/user_profile.html +++ b/templates/user_profile.html @@ -7,7 +7,7 @@
- + profile picture
From 475cdb0f2aa42ca07191cfc8647eab71c6dbc404 Mon Sep 17 00:00:00 2001 From: Krisztian Juhasz Date: Tue, 5 Mar 2019 10:59:30 +0100 Subject: [PATCH 070/120] Edit question added --- data_manager.py | 6 ++++++ server.py | 17 +++++++++++++++++ templates/edit_question.html | 31 +++++++++++++++++++++++++++++++ templates/questiondetails.html | 2 ++ 4 files changed, 56 insertions(+) create mode 100644 templates/edit_question.html diff --git a/data_manager.py b/data_manager.py index 5aea21edd..e9d706992 100644 --- a/data_manager.py +++ b/data_manager.py @@ -115,6 +115,12 @@ def get_update(cursor,answer_id , message): cursor.execute("""UPDATE answer SET message = %(message)s,submission_time = %(time)s WHERE id=%(answer_id)s;""", {"message": message, 'answer_id': answer_id, 'time': time}) +@connection.connection_handler +def get_update_question(cursor,question_id , message,title): + time = datetime.now() + cursor.execute("""UPDATE question SET message = %(message)s,submission_time = %(time)s,title = %(title)s WHERE id=%(question_id)s;""", + {"message": message, 'question_id': question_id, 'time': time, 'title': title}) + @connection.connection_handler def get_update_for_comment(cursor, comment_id, message): diff --git a/server.py b/server.py index 65f35f927..920a7d451 100644 --- a/server.py +++ b/server.py @@ -45,6 +45,9 @@ def delete_question(question_id): return redirect(url_for('route_list')) + + + @app.route('/question//new-answer', methods=['GET', 'POST']) def route_new_answer(question_id): if request.method == "POST": @@ -54,6 +57,20 @@ def route_new_answer(question_id): return render_template('answer.html', title="Add New Answer!", question_id=question_id) + +@app.route('/question//edit', methods=['GET', 'POST']) +def edit_question(question_id): + questions = data_manager.get_questions() + if request.method == "POST": + new_message = request.form['message'] + new_title = request.form['title'] + data_manager.get_update_question(question_id,new_message,new_title) + return redirect(f'/question/{question_id}') + + + return render_template('edit_question.html', questions=questions, question_id=question_id) + + @app.route('/answer//edit', methods=['GET', 'POST']) def edit_answer(answer_id): answers = data_manager.get_answers() diff --git a/templates/edit_question.html b/templates/edit_question.html new file mode 100644 index 000000000..8df231c6d --- /dev/null +++ b/templates/edit_question.html @@ -0,0 +1,31 @@ +{% extends 'layout.html' %} + +{% block content %} + {% include 'navbar.html' %} + +

Edit question

+ + + {% for question in questions %} + {% if question_id == question['id'] %} +
+ + + + +
+ + + +
+
+ +
+ + + + {% endif %} + {% endfor %} + + +{% endblock %} \ No newline at end of file diff --git a/templates/questiondetails.html b/templates/questiondetails.html index f1cf7a9ce..fce5841d1 100644 --- a/templates/questiondetails.html +++ b/templates/questiondetails.html @@ -22,6 +22,7 @@

python
{{ question['submission_time'] }}
+ Etus
@@ -39,6 +40,7 @@

+


From fb42a551630c1e98a318c4493ec798dbf812e1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Gerg=C5=91?= Date: Tue, 5 Mar 2019 13:05:29 +0100 Subject: [PATCH 071/120] registration function implemented --- data_manager.py | 10 ++++++++++ server.py | 13 +++++++++++-- templates/register.html | 4 ++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/data_manager.py b/data_manager.py index 5aea21edd..868dd4d53 100644 --- a/data_manager.py +++ b/data_manager.py @@ -213,3 +213,13 @@ def vote_down_answer(cursor, question_id, answer_id): cursor.execute("""UPDATE answer SET vote_number = vote_number-1 WHERE question_id = %(question_id)s AND id = %(answer_id)s;""", variables) + + +@connection.connection_handler +def registration(cursor, username, hashed_password): + user_details = { + 'username': username, + 'password': hashed_password + } + cursor.execute("""INSERT INTO users(username, password) + VALUES(%(username)s, %(password)s);""", user_details) diff --git a/server.py b/server.py index 2be2afe38..78a27bf54 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,6 @@ from flask import Flask, render_template, redirect, url_for, request +import bcrypt +import os import data_manager @@ -172,9 +174,16 @@ def login(): return render_template('login.html') -@app.route("/registration") +@app.route("/registration", methods=['GET', 'POST']) def register(): - return render_template('register.html') + if request.method == 'GET': + return render_template('register.html') + elif request.method == 'POST': + username = request.form['username'] + password = request.form['password'] + hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()) + data_manager.registration(username, hashed_password) + return redirect(url_for('route_main')) if __name__ == "__main__": diff --git a/templates/register.html b/templates/register.html index f337705d0..40c9882fa 100644 --- a/templates/register.html +++ b/templates/register.html @@ -8,10 +8,10 @@