From 6d8097d112fb5858cef3e688b5031493b9d5e522 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Thu, 26 Jul 2018 22:58:28 +0200 Subject: [PATCH] Add debug mode to help debug thread issues --- app.py | 14 ++++++++++++-- templates/note_debug.html | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 templates/note_debug.html diff --git a/app.py b/app.py index 9885a52..41dba64 100644 --- a/app.py +++ b/app.py @@ -232,8 +232,13 @@ def _get_file_url(url, size, kind): @app.template_filter() def remove_mongo_id(dat): + if isinstance(dat, list): + return [remove_mongo_id(item) for item in dat] if "_id" in dat: dat["_id"] = str(dat["_id"]) + for k, v in dat.items(): + if isinstance(v, dict): + dat[k] = remove_mongo_id(dat[k]) return dat @@ -1329,7 +1334,10 @@ def admin_thread(): abort(410) thread = _build_thread(data) - return render_template("note.html", thread=thread, note=data) + tpl = "note.html" + if request.args.get("debug"): + tpl = "note_debug.html" + return render_template(tpl, thread=thread, note=data) @app.route("/admin/new", methods=["GET"]) @@ -1539,7 +1547,9 @@ def admin_stream(): if request.args.get("debug_inbox"): q = {} - inbox_data, older_than, newer_than = paginated_query(DB.activities, q, limit=int(request.args.get('limit', 25))) + inbox_data, older_than, newer_than = paginated_query( + DB.activities, q, limit=int(request.args.get("limit", 25)) + ) return render_template( tpl, inbox_data=inbox_data, older_than=older_than, newer_than=newer_than diff --git a/templates/note_debug.html b/templates/note_debug.html new file mode 100644 index 0000000..af07a4b --- /dev/null +++ b/templates/note_debug.html @@ -0,0 +1,23 @@ +{% extends "layout.html" %} +{% import 'utils.html' as utils %} +{% block title %}{{ config.NAME }}: "{{ note.activity.object.content | html2plaintext | truncate(50) }}"{% endblock %} +{% block header %} + + + + + + + + + + +{% endblock %} +{% block content %} +
+{% include "header.html" %} +
{{ thread | remove_mongo_id | tojson(indent=4) }}
+{{ utils.display_thread(thread, likes=likes, shares=shares) }} +
+{% endblock %} +{% block links %}{% endblock %}