diff options
| author | jwansek <eddie.atten.ea29@gmail.com> | 2026-03-24 18:33:56 +0000 |
|---|---|---|
| committer | jwansek <eddie.atten.ea29@gmail.com> | 2026-03-24 18:33:56 +0000 |
| commit | 4303ff93359c42e61cb7362932a4433d4d51cf1b (patch) | |
| tree | c82b6dd3240f28158da924e0c7c8ea5d5bcb0262 | |
| parent | d0d10ab1c7179ab15a440f711909765140436851 (diff) | |
| download | boymoder.blog-4303ff93359c42e61cb7362932a4433d4d51cf1b.tar.gz boymoder.blog-4303ff93359c42e61cb7362932a4433d4d51cf1b.zip | |
Added page for each question
| -rw-r--r-- | edaweb/app.py | 15 | ||||
| -rw-r--r-- | edaweb/database.py | 22 | ||||
| -rw-r--r-- | edaweb/templates/question.html.j2 | 22 | ||||
| -rw-r--r-- | edaweb/templates/questions.html.j2 | 6 |
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> |
