-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
51 lines (40 loc) · 1.05 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from tee.models import Log
from tee.utils import last_n_lines
from django.contrib import admin
from django.utils.safestring import mark_safe
@admin.register(Log)
class LogAdmin(admin.ModelAdmin):
list_display = [
"command_name",
"started_on",
"finished_on",
"finished_successfully",
"last_5_lines",
]
readonly_fields = [
"started_on",
"finished_on",
"finished_successfully",
"command_name",
"args",
"stdout",
"stderr",
]
def finished_successfully(self, obj: Log):
if obj.exit_code == 0:
return True
return False
def last_5_lines(self, obj):
s = obj.stderr
if obj.traceback:
s = obj.traceback
else:
if obj.exit_code == 0:
s = obj.stdout
if not s:
s = obj.exit_value
r = last_n_lines(s, nlines=5)
if r is None:
return
return mark_safe(f"<pre>{r}</pre>")
last_5_lines.short_description = "Results"