aboutsummaryrefslogtreecommitdiffstats
path: root/edaweb
diff options
context:
space:
mode:
Diffstat (limited to 'edaweb')
-rw-r--r--edaweb/app.py15
-rw-r--r--edaweb/database.py22
-rw-r--r--edaweb/templates/question.html.j222
-rw-r--r--edaweb/templates/questions.html.j26
4 files changed, 57 insertions, 8 deletions
diff --git a/edaweb/app.py b/edaweb/app.py
index ab2aa0c..0d4458a 100644
--- a/edaweb/app.py
+++ b/edaweb/app.py
@@ -17,7 +17,7 @@ import io
app = flask.Flask(__name__)
CONFIG = configparser.ConfigParser(interpolation = None)
-CONFIG.read(os.path.join(os.path.dirname(__file__), "edaweb.conf"))
+CONFIG.read(os.path.join(os.path.dirname(__file__), "..", "edaweb.conf"))
shown_images = set()
shown_sidebar_images = set()
@@ -27,7 +27,6 @@ def get_pfp_img(db:database.Database):
if len(shown_images) == len(dbimg):
shown_images = set()
folder = set(dbimg).difference(shown_images)
- print(folder)
choice = random.choice(list(folder))
shown_images.add(choice)
return choice
@@ -249,6 +248,18 @@ def serve_questions():
qnas_link = CONFIG.get("qnas", "url"),
qnas = db.get_qnas()
)
+
+@app.route("/question")
+def serve_question():
+ with database.Database() as db:
+ question_id = flask.request.args.get("id", type=int)
+ qna = db.get_qna(question_id)
+ return flask.render_template(
+ "question.html.j2",
+ **get_template_items("question from %s" % qna["qna"][2], db),
+ qnas_link = CONFIG.get("qnas", "url"),
+ qna = qna
+ )
if __name__ == "__main__":
try:
diff --git a/edaweb/database.py b/edaweb/database.py
index c6553a6..47e0f18 100644
--- a/edaweb/database.py
+++ b/edaweb/database.py
@@ -244,7 +244,27 @@ class Database:
with self.__connection.cursor() as cursor:
cursor.execute("SELECT * FROM qnas;")
return sorted(cursor.fetchall(), key = operator.itemgetter(2), reverse = True)
-
+
+ def get_qna(self, id_):
+ with self.__connection.cursor() as cursor:
+ cursor.execute("SELECT * FROM `qnas` WHERE `curiouscat_id` = %s;", (id_, ))
+ qna = {"qna": list(cursor.fetchone())}
+ cursor.execute("SELECT `curiouscat_id` FROM `qnas` WHERE `timestamp` < %s ORDER BY `timestamp` DESC LIMIT 1;", (qna["qna"][2], ))
+ try:
+ qna["previous"] = cursor.fetchone()[0]
+ except TypeError:
+ qna["previous"] = None
+ cursor.execute("SELECT `curiouscat_id` FROM `qnas` WHERE `timestamp` > %s ORDER BY `timestamp` LIMIT 1;", (qna["qna"][2], ))
+ try:
+ qna["next"] = cursor.fetchone()[0]
+ except TypeError:
+ qna["next"] = None
+
+ return qna
+
+if __name__ == "__main__":
+ with Database() as db:
+ print(db.get_qna(1098140963))
diff --git a/edaweb/templates/question.html.j2 b/edaweb/templates/question.html.j2
new file mode 100644
index 0000000..a9c7a0c
--- /dev/null
+++ b/edaweb/templates/question.html.j2
@@ -0,0 +1,22 @@
+{% extends "template.html.j2" %}
+{% block content %}
+ <aside>
+ {% if qna["previous"] != None %}
+ <a href="/question?id={{ qna['previous'] }}">← Previous</a>
+ {% endif %}
+ {% if qna["next"] != None %}
+ <a href="/question?id={{ qna['next'] }}">→ Next</a>
+ {% endif %}
+ <br>
+ <a href="/questions#{{ qna['qna'][0] }}">All questions</a>
+ </aside>
+
+ <h4><a href="{{ qnas_link }}">ask a question!</a></h4>
+ <dl>
+ <dt class="qnaheader">ID:</dt><dd>{{ qna["qna"][0] }}</dd>
+ <dt class="qnaheader">Question source:</dt><dd>{{ qna["qna"][-1] }}</dd>
+ <dt class="qnaheader">Answered at:</dt><dd>{{ qna["qna"][2] }}</dd>
+ <dt class="qnaheader">Question:</dt><dd>{{ qna["qna"][3] }}</dd>
+ <dt class="qnaheader">Answer:</dt><dd>{{ qna["qna"][4] }}</dd>
+ </dl>
+{% endblock %} \ No newline at end of file
diff --git a/edaweb/templates/questions.html.j2 b/edaweb/templates/questions.html.j2
index eb58380..a800941 100644
--- a/edaweb/templates/questions.html.j2
+++ b/edaweb/templates/questions.html.j2
@@ -3,11 +3,7 @@
<h4><a href="{{ qnas_link }}">ask a question!</a></h4>
<dl>
{% for id_, link, dt, question, answer, host in qnas %}
- {% if host == "curiouscat" %}
- <dt class="qnaheader"><a href="{{ link }}">{{ dt.isoformat() }}</a> - {{ host }}</dt>
- {% else %}
- <dt class="qnaheader">{{ dt.isoformat() }} - {{ host }}</dt>
- {% endif %}
+ <dt class="qnaheader" id="{{ id_ }}"><a href="question?id={{ id_ }}">{{ dt.isoformat() }}</a> - {{ host }}</dt>
<dd>
<dt class="question"><p>{{ question }}</p></dt>
<dd class="answer"><p>{{ answer }}</p></dd>