Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit 7e2f40b

Browse files
committed
Add a simple ticket display page
1 parent 3ba22ed commit 7e2f40b

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

controllers/admin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,22 @@ def reset_exam():
29032903
return json.dumps({"status": "Success", "mess": "Successfully Reset Exam"})
29042904

29052905

2906+
# This displays the table that collects tickets across workers
2907+
# for this to work you will need to add a row to ``auth_group`` with the role ``admins``
2908+
# In addition any user that you want to have access to these tracebacks will need
2909+
# to have their user_id and the group id for admins added to the ``auth_membership`` table.
2910+
# This will require some manual sql manipulation.
2911+
@auth.requires_membership("admins")
2912+
def tickets():
2913+
ticks = db.executesql(
2914+
"""
2915+
select * from traceback order by timestamp desc
2916+
""",
2917+
as_dict=True,
2918+
)
2919+
return dict(tickets=ticks)
2920+
2921+
29062922
def killer():
29072923
print(routes_onerror)
29082924
x = 5 / 0 # noqa: F841

views/admin/tickets.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<h1>Quick Look at Tickets</h1>
2+
3+
<style>
4+
pre {
5+
background-color: lightgrey;
6+
display: none;
7+
}
8+
td {
9+
font-family: monospace;
10+
border: solid black 1px;
11+
}
12+
</style>
13+
<table style="width: 100%">
14+
<colgroup>
15+
<col />
16+
<col />
17+
<col style="width: 30%" />
18+
<col />
19+
<col />
20+
<col />
21+
<col />
22+
</colgroup>
23+
<tr>
24+
<th>ID</th>
25+
<th>timestamp</th>
26+
<th>Error Message</th>
27+
<th>Path</th>
28+
<th>Query String</th>
29+
<th>Hostname</th>
30+
<th>Traceback</th>
31+
</tr>
32+
{{ for ticket in tickets: }}
33+
<tr>
34+
<td>{{=ticket["id"]}}</td>
35+
<td>{{=ticket["timestamp"]}}</td>
36+
<td>{{=ticket["err_message"]}}</td>
37+
<td>{{=ticket["path"]}}</td>
38+
<td>{{=ticket["query_string"]}}</td>
39+
<td>{{=ticket["hostname"]}}</td>
40+
<td>
41+
<a href="#" onclick="showtb({{=ticket['id']}});">Show</a>
42+
<pre id="{{=ticket['id']}}">{{=ticket["traceback"]}}</pre>
43+
</td>
44+
</tr>
45+
{{ pass }}
46+
</table>
47+
48+
<h1>Traceback for ID: <span id="tktnum"></span></h1>
49+
<pre id="selectedtb"></pre>
50+
51+
<script>
52+
function showtb(theel) {
53+
let tbout = document.getElementById("selectedtb");
54+
let tb = document.getElementById(theel.toString()).innerText;
55+
tbout.innerHTML = tb;
56+
tbout.style.display = "block";
57+
let tktnum = document.getElementById("tktnum");
58+
tktnum.innerHTML = theel.toString();
59+
}
60+
</script>

0 commit comments

Comments
 (0)