Skip to content
Snippets Groups Projects
Commit 42125e09 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Debug logs as own app

parent fa10bbaa
No related branches found
No related tags found
1 merge request!86Merge school-apps
Showing
with 227 additions and 95 deletions
from django.contrib import admin
from .models import DebugLogGroup, DebugLog
class DebugLogAdmin(admin.ModelAdmin):
readonly_fields = ["id", "group", "return_code", "filename", "updated_at"]
class DebugLogGroupAdmin(admin.ModelAdmin):
readonly_fields = ["id"]
# Register your models here.
admin.site.register(DebugLogGroup, DebugLogGroupAdmin)
admin.site.register(DebugLog, DebugLogAdmin)
from django.apps import AppConfig
class DebugConfig(AppConfig):
name = 'debug'
# Generated by Django 2.2.1 on 2019-05-22 14:03
# Generated by Django 2.2.1 on 2019-05-23 13:59
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('timetable', '0010_debugloggroup'),
]
operations = [
migrations.CreateModel(
name='DebugLogGroup',
fields=[
('id', models.CharField(max_length=100, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, verbose_name='Name')),
('desc_as_pre',
models.CharField(blank=True, max_length=250, verbose_name='Beschreibung, dargestellt als HTML-PRE')),
],
options={
'verbose_name': 'Debug-Log-Gruppe',
'verbose_name_plural': 'Debug-Log-Gruppen',
},
),
migrations.CreateModel(
name='DebugLog',
fields=[
('id', models.CharField(max_length=100, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, verbose_name='Name')),
('return_code', models.IntegerField(blank=True, null=True, verbose_name='UNIX-Rückgabecode')),
('filename', models.FilePathField(match='*.log', path='/home/wethjo/dev/school-apps/schoolapps/latex',
('filename', models.FilePathField(match='.*.log', path='/home/wethjo/dev/school-apps/schoolapps/latex',
verbose_name='Dateiname zur Logdatei')),
('updated_at',
models.DateTimeField(default=django.utils.timezone.now, verbose_name='Aktualisierungszeitpunkt')),
('group',
models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL,
related_name='logs', to='timetable.DebugLogGroup', verbose_name='Gruppe')),
related_name='logs', to='debug.DebugLogGroup', verbose_name='Gruppe')),
],
options={
'verbose_name': 'Debug-Log',
......
import os
from django.db import models
from django.utils import timezone
from schoolapps.settings import BASE_DIR
class DebugLogGroup(models.Model):
# Meta
id = models.CharField(primary_key=True, blank=False, max_length=100, verbose_name="ID")
name = models.CharField(blank=False, max_length=200, verbose_name="Name")
desc_as_pre = models.CharField(blank=True, max_length=250, verbose_name="Beschreibung, dargestellt als HTML-PRE")
class Meta:
verbose_name = "Debug-Log-Gruppe"
verbose_name_plural = "Debug-Log-Gruppen"
def __str__(self):
return self.name or self.id
def is_successful(self):
successful = True
for log in self.logs.all():
if not log.is_successful():
successful = False
return successful
DEBUG_LOG_DIR = os.path.join(BASE_DIR, "latex")
class DebugLog(models.Model):
# Meta
id = models.CharField(primary_key=True, blank=False, max_length=100, verbose_name="ID")
name = models.CharField(blank=False, max_length=200, verbose_name="Name")
group = models.ForeignKey(DebugLogGroup, on_delete=models.SET_NULL, default=None, null=True, blank=True,
related_name="logs", verbose_name="Gruppe") # If null, it wouldn't be displayed
# Data
return_code = models.IntegerField(blank=True, null=True, verbose_name="UNIX-Rückgabecode")
filename = models.FilePathField(path=DEBUG_LOG_DIR, match=".*.log",
verbose_name="Dateiname zur Logdatei")
updated_at = models.DateTimeField(blank=False, default=timezone.now, verbose_name="Aktualisierungszeitpunkt")
class Meta:
verbose_name = "Debug-Log"
verbose_name_plural = "Debug-Logs"
def __str__(self):
return self.name or self.id
def get_file_content(self):
if self.filename:
print(self.filename)
f = open(os.path.join(DEBUG_LOG_DIR, self.filename), "r")
content = f.read()
f.close()
return content
else:
return ""
def is_successful(self):
return self.return_code == 0
def get_log_group_by_id(id):
p, _ = DebugLogGroup.objects.get_or_create(id=id)
return p
def register_log_with_filename(id, group_id, filename, return_code):
p, _ = DebugLog.objects.get_or_create(id=id)
group = get_log_group_by_id(group_id)
p.group = group
p.return_code = return_code
p.filename = filename
p.updated_at = timezone.now()
p.save()
{% include 'partials/header.html' %}
{% load material_form %}
{% load martortags %}
<link rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<main>
<a class="btn-flat waves-effect waves-teal right btn-flat-medium" href="{% url "debug_logs" %}"><i
class="material-icons refresh center">refresh</i></a>
<h4>Debuggingtool</h4>
{% for group in groups %}
<a href="#{{ group.id }}" class="btn-flat waves-effect waves-katharineum"><i class="material-icons left">arrow_forward</i> {{ group.name }}
</a>
{% endfor %}
{% for group in groups %}
<div class="card" id="{{ group.id }}">
<div class="card-content">
<i class="material-icons right {{ group.is_successful|yesno:"green,red" }}-text medium">{{ group.is_successful|yesno:"check_circle,error" }}</i>
<span class="card-title">{{ group.name }}</span>
<pre>{{ group.desc_as_pre|default:" " }}</pre>
{% for log in group.logs.all %}
<div>
<i class="material-icons right {{ log.is_successful|yesno:"green,red" }}-text small">{{ log.is_successful|yesno:"check_circle,error" }}</i>
<h5>{{ log.name }} </h5>
<p><i class="material-icons left">access_time</i> {{ log.updated_at }}</p>
<pre><code class="plaintext scroll-fix">RETURN CODE: {{ log.return_code }}
{{ log.get_file_content }}
</code></pre>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</main>
{% include 'partials/footer.html' %}
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
path("", views.debugging_tool),
path("logs/", views.debugging_tool, name="debug_logs")
]
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from debug.models import DebugLogGroup
@login_required
# @permission_required("timetable.")
def debugging_tool(request):
groups = DebugLogGroup.objects.all()
return render(request, "debug/debug.html", {"groups": groups})
......@@ -41,6 +41,7 @@ ALLOWED_HOSTS = [
INSTALLED_APPS = [
'django_pdb',
'dashboard.apps.DashboardConfig',
"debug.apps.DebugConfig",
'aub.apps.AubConfig',
'untisconnect.apps.UntisconnectConfig',
'timetable.apps.TimetableConfig',
......
......@@ -62,6 +62,7 @@ urlpatterns = [
#########
# Admin #
#########
path("debug/", include("debug.urls")),
path('settings/', include('dbsettings.urls')),
path('admin/', admin.site.urls),
......
......@@ -431,4 +431,8 @@ i.collapsible-trigger {
.scroll-fix {
max-height: 300px;
overflow: scroll;
}
.waves-effect.waves-katharineum .waves-ripple {
background-color: rgba(218, 31, 61, 0.65);
}
\ No newline at end of file
......@@ -130,11 +130,6 @@
<span class="badge new primary-color ">SMART PLAN</span>
</a>
</li>
{# <li>#}
{# <a href="{% url 'timetable_admin_all' %}">#}
{# <i class="material-icons">grid_on</i> Alle Pläne#}
{# </a>#}
{# </li>#}
<li>
<a href="{% url 'timetable_quicklaunch' %}">
<i class="material-icons">grid_on</i> Alle Pläne
......@@ -153,7 +148,7 @@
</li>
{% endif %}
<li>
<a href="{% url 'timetable_debugging_tool' %}">
<a href="{% url 'debug_logs' %}">
<i class="material-icons">error</i> Debuggingtool
</a>
</li>
......
from django.contrib import admin
# Register your models here.
from timetable.models import Hint, DebugLog, DebugLogGroup
from timetable.models import Hint
def refresh_cache(modeladmin, request, queryset):
......@@ -17,14 +17,7 @@ class HintAdmin(admin.ModelAdmin):
actions = [refresh_cache]
class DebugLogAdmin(admin.ModelAdmin):
readonly_fields = ["id", "group", "return_code", "filename", "updated_at"]
class DebugLogGroupAdmin(admin.ModelAdmin):
readonly_fields = ["id"]
admin.site.register(Hint, HintAdmin)
admin.site.register(DebugLogGroup)
admin.site.register(DebugLog, DebugLogAdmin)
......@@ -4,6 +4,9 @@ import subprocess
from schoolapps.settings import BASE_DIR
# from .models import register_log_with_filename
def convert_markdown_2_latex(s):
try:
# Write markdown file
......@@ -12,13 +15,15 @@ def convert_markdown_2_latex(s):
md_file.close()
# Execute pandoc to convert markdown to latex
bash_command = "pandoc --from markdown --to latex --output {} {}".format(
bash_command = "pandoc --log={} --from markdown --to latex --output {} {}".format(
os.path.join(BASE_DIR, "latex", "m2l.log"),
os.path.join(BASE_DIR, "latex", "m2l.tex"),
os.path.join(BASE_DIR, "latex", "m2l.md"))
process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
print("[MD TO LATEX]", output)
print("[RETURN CODE]", process.returncode)
# register_log_with_filename("m2l", "m2l", "m2l.log", process.returncode)
# Read converted latex from file
tex_file = open(os.path.join(BASE_DIR, "latex", "m2l.tex"), "r", encoding="utf8")
......
# Generated by Django 2.2.1 on 2019-05-22 13:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('timetable', '0009_hint_classes_formatted'),
]
operations = [
migrations.CreateModel(
name='DebugLogGroup',
fields=[
('id', models.CharField(max_length=100, primary_key=True, serialize=False)),
('name', models.CharField(max_length=200)),
],
),
]
# Generated by Django 2.2.1 on 2019-05-22 14:07
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('timetable', '0011_debuglog'),
]
operations = [
migrations.AddField(
model_name='debuglog',
name='updated_at',
field=models.DateTimeField(default=datetime.datetime(2019, 5, 22, 16, 7, 24, 453531)),
),
migrations.AlterField(
model_name='debuglog',
name='filename',
field=models.FilePathField(match='.*.log', path='/home/wethjo/dev/school-apps/schoolapps/latex',
verbose_name='Dateiname zur Logdatei'),
),
]
# Generated by Django 2.2.1 on 2019-05-22 14:08
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('timetable', '0012_auto_20190522_1607'),
]
operations = [
migrations.AlterField(
model_name='debuglog',
name='updated_at',
field=models.DateTimeField(default=datetime.datetime(2019, 5, 22, 16, 8, 10, 52079)),
),
]
# Generated by Django 2.2.1 on 2019-05-22 14:08
import datetime
from django.db import migrations, models
from django.utils.timezone import utc
class Migration(migrations.Migration):
dependencies = [
('timetable', '0013_auto_20190522_1608'),
]
operations = [
migrations.AlterField(
model_name='debuglog',
name='updated_at',
field=models.DateTimeField(default=datetime.datetime(2019, 5, 22, 14, 8, 34, 95310, tzinfo=utc)),
),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment