diff --git a/biscuit/apps/chronos/admin.py b/biscuit/apps/chronos/admin.py index 4f20aea45bb6c46335f05d9f062cf0d57ab1a16b..8b41106e315af2de8901e9c4afcd51c597c4f804 100755 --- a/biscuit/apps/chronos/admin.py +++ b/biscuit/apps/chronos/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin # Register your models here. -from timetable.models import Hint +from timetable.models import Hint, DebugLog, DebugLogGroup def refresh_cache(modeladmin, request, queryset): @@ -17,4 +17,14 @@ 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) diff --git a/biscuit/apps/chronos/m2l.py b/biscuit/apps/chronos/m2l.py index c8ab0cb0f11296d08d1c55f72363385603885d31..051834802f399501105e0fb303fd68de8b835f6c 100644 --- a/biscuit/apps/chronos/m2l.py +++ b/biscuit/apps/chronos/m2l.py @@ -18,6 +18,7 @@ def convert_markdown_2_latex(s): process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) output = process.communicate()[0] print("[MD TO LATEX]", output) + print("[RETURN CODE]", process.returncode) # Read converted latex from file tex_file = open(os.path.join(BASE_DIR, "latex", "m2l.tex"), "r", encoding="utf8") diff --git a/biscuit/apps/chronos/migrations/0010_debugloggroup.py b/biscuit/apps/chronos/migrations/0010_debugloggroup.py new file mode 100644 index 0000000000000000000000000000000000000000..7ea21581713eb6bd219533c16b334d38d7cf0a50 --- /dev/null +++ b/biscuit/apps/chronos/migrations/0010_debugloggroup.py @@ -0,0 +1,19 @@ +# 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)), + ], + ), + ] diff --git a/biscuit/apps/chronos/migrations/0011_debuglog.py b/biscuit/apps/chronos/migrations/0011_debuglog.py new file mode 100644 index 0000000000000000000000000000000000000000..7a24b7ff45558418bf23cb06a4bdcff4523af40d --- /dev/null +++ b/biscuit/apps/chronos/migrations/0011_debuglog.py @@ -0,0 +1,30 @@ +# Generated by Django 2.2.1 on 2019-05-22 14:03 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ('timetable', '0010_debugloggroup'), + ] + + operations = [ + 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', + verbose_name='Dateiname zur Logdatei')), + ('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')), + ], + options={ + 'verbose_name': 'Debug-Log', + 'verbose_name_plural': 'Debug-Logs', + }, + ), + ] diff --git a/biscuit/apps/chronos/migrations/0012_auto_20190522_1607.py b/biscuit/apps/chronos/migrations/0012_auto_20190522_1607.py new file mode 100644 index 0000000000000000000000000000000000000000..d8f1cf747b69b3b19285718bb4f86b787266e3df --- /dev/null +++ b/biscuit/apps/chronos/migrations/0012_auto_20190522_1607.py @@ -0,0 +1,24 @@ +# 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'), + ), + ] diff --git a/biscuit/apps/chronos/migrations/0013_auto_20190522_1608.py b/biscuit/apps/chronos/migrations/0013_auto_20190522_1608.py new file mode 100644 index 0000000000000000000000000000000000000000..2339d2b9ab9cbd8a2cbb8cd331160a207da0796c --- /dev/null +++ b/biscuit/apps/chronos/migrations/0013_auto_20190522_1608.py @@ -0,0 +1,18 @@ +# 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)), + ), + ] diff --git a/biscuit/apps/chronos/migrations/0014_auto_20190522_1608.py b/biscuit/apps/chronos/migrations/0014_auto_20190522_1608.py new file mode 100644 index 0000000000000000000000000000000000000000..5bb2901746574c0d50885df1fad646e783c05c0c --- /dev/null +++ b/biscuit/apps/chronos/migrations/0014_auto_20190522_1608.py @@ -0,0 +1,19 @@ +# 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)), + ), + ] diff --git a/biscuit/apps/chronos/migrations/0015_auto_20190522_1608.py b/biscuit/apps/chronos/migrations/0015_auto_20190522_1608.py new file mode 100644 index 0000000000000000000000000000000000000000..7326242b40c55610ea15d2308dbb04e3a858d351 --- /dev/null +++ b/biscuit/apps/chronos/migrations/0015_auto_20190522_1608.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.1 on 2019-05-22 14:08 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + dependencies = [ + ('timetable', '0014_auto_20190522_1608'), + ] + + operations = [ + migrations.AlterField( + model_name='debuglog', + name='updated_at', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/biscuit/apps/chronos/migrations/0016_auto_20190522_1612.py b/biscuit/apps/chronos/migrations/0016_auto_20190522_1612.py new file mode 100644 index 0000000000000000000000000000000000000000..5f4e74e5667001b4996e4b2bea12844e3571f7f6 --- /dev/null +++ b/biscuit/apps/chronos/migrations/0016_auto_20190522_1612.py @@ -0,0 +1,32 @@ +# Generated by Django 2.2.1 on 2019-05-22 14:12 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + dependencies = [ + ('timetable', '0015_auto_20190522_1608'), + ] + + operations = [ + migrations.AlterModelOptions( + name='debugloggroup', + options={'verbose_name': 'Debug-Log-Gruppe', 'verbose_name_plural': 'Debug-Log-Gruppen'}, + ), + migrations.AlterField( + model_name='debuglog', + name='updated_at', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Aktualisierungszeitpunkt'), + ), + migrations.AlterField( + model_name='debugloggroup', + name='id', + field=models.CharField(max_length=100, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='debugloggroup', + name='name', + field=models.CharField(max_length=200, verbose_name='Name'), + ), + ] diff --git a/biscuit/apps/chronos/models.py b/biscuit/apps/chronos/models.py index f989e7a71dea3dd82c072b70afe8ac7da781b7d4..30bb9012c1da102aac891d38735f7148751cf399 100755 --- a/biscuit/apps/chronos/models.py +++ b/biscuit/apps/chronos/models.py @@ -1,10 +1,11 @@ +import os from datetime import date from django.db import models -from django.db.models.signals import post_save -from django.dispatch import receiver +from django.utils import timezone from martor.models import MartorField +from schoolapps.settings import BASE_DIR from timetable.m2l import convert_markdown_2_latex from untisconnect.api import get_all_classes, format_classes from untisconnect.models import Class @@ -76,6 +77,53 @@ class Hint(models.Model): update_fields=update_fields) +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") + + class Meta: + verbose_name = "Debug-Log-Gruppe" + verbose_name_plural = "Debug-Log-Gruppen" + + def __str__(self): + return self.name or self.id + + +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=os.path.join(BASE_DIR, "latex"), 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_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.save() + class Timetable(models.Model): class Meta: permissions = ( diff --git a/biscuit/apps/chronos/pdf.py b/biscuit/apps/chronos/pdf.py index 0bc1db4eaf740017c17e76db65f4e5b64649efdd..cf13ae30364c7bf9e4b2cf95cc58befbd981f748 100644 --- a/biscuit/apps/chronos/pdf.py +++ b/biscuit/apps/chronos/pdf.py @@ -4,6 +4,7 @@ import subprocess from django.template.loader import render_to_string from schoolapps.settings import BASE_DIR +from timetable.models import register_log_with_filename LOGO_FILENAME = os.path.join(BASE_DIR, "static", "common", "logo.png") @@ -22,6 +23,8 @@ def generate_pdf(tex, filename): filename)) process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) output = process.communicate()[0] + + register_log_with_filename("latex_{}".format(filename), "latex", "{}.log".format(filename), process.returncode) print("[LATEX]", output) diff --git a/biscuit/apps/chronos/templates/timetable/debug.html b/biscuit/apps/chronos/templates/timetable/debug.html new file mode 100755 index 0000000000000000000000000000000000000000..dda3fd813d42a4a79a27a62381cc6a39ecf4cb5f --- /dev/null +++ b/biscuit/apps/chronos/templates/timetable/debug.html @@ -0,0 +1,72 @@ +{% 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 "timetable_debugging_tool" %}"><i + class="material-icons refresh center">refresh</i></a> + <h4>Debuggingtool</h4> + + + {# <div class="row">#} + {# <div class="col s12 m4">#} + <div class="card"> + <div class="card-content"> + <i class="material-icons right green-text medium">check_circle</i> + <span class="card-title">LaTeX-Logs</span> + <pre>pdflatex</pre> + <h5>class0.log</h5> + <pre><code class="plaintext scroll-fix"> + {{ latex_1 }} + </code></pre> + <h5>class1.log</h5> + <pre><code class="plaintext scroll-fix"> + {{ latex_2 }} + </code></pre> + </div> + {# <div class="card-action">#} + {# <a href="#" class="primary-color-text">Generierung erneut anstoßen</a>#} + {# <a href="#">This is a link</a>#} + {# </div>#} + </div> + {# </div>#} + {# <div class="col s12 m4">#} + <div class="card"> + <div class="card-content"> + <i class="material-icons right red-text medium">close</i> + + <span class="card-title">MD-zu-LaTeX-Konvertierung</span> + <pre>pandoc</pre> + + <p>I am a very simple card. I am good at containing small bits of information. + I am convenient because I require little markup to use effectively.</p> + </div> + <div class="card-action"> + <a href="#">This is a link</a> + <a href="#">This is a link</a> + </div> + </div> + {# </div>#} + {# <div class="col s12 m4">#} + <div class="card"> + <div class="card-content"> + <span class="card-title">PDF-Merge</span> + <p>I am a very simple card. I am good at containing small bits of information. + I am convenient because I require little markup to use effectively.</p> + </div> + <div class="card-action"> + <a href="#">This is a link</a> + <a href="#">This is a link</a> + </div> + </div> + {# </div>#} + {# </div>#} +</main> + +{% include 'partials/footer.html' %} diff --git a/biscuit/apps/chronos/templates/timetable/hints.html b/biscuit/apps/chronos/templates/timetable/hints.html index d838b63a30662b64cd99e06bf93d78f413ab5c9d..bd289497abc631395f82ef67daf6b34937794c23 100755 --- a/biscuit/apps/chronos/templates/timetable/hints.html +++ b/biscuit/apps/chronos/templates/timetable/hints.html @@ -3,7 +3,7 @@ {% load martortags %} <main> - <h4>Hinweise</h4> + <h4>Hinweismanagement</h4> {% if msg %} <div class="alert success"> @@ -60,12 +60,12 @@ </div> <div class="collapsible-body row"> <div class="right"> - <a class="btn-flat waves-effect waves-teal green-text" + <a class="btn-flat waves-effect waves-green green-text" href="{% url "timetable_edit_hint" hint.id %}"> <i class="material-icons left">edit</i> <span class="hide-on-small-only">Bearbeiten</span> </a> - <a class="btn-flat waves-effect waves-teal red-text delete-button" + <a class="btn-flat waves-effect waves-red red-text delete-button" href="{% url "timetable_delete_hint" hint.id %}"> <i class="material-icons left">delete</i> <span class="hide-on-small-only">Löschen</span> diff --git a/biscuit/apps/chronos/urls.py b/biscuit/apps/chronos/urls.py index e5f64712947fe44b92d60f2fc0900657f4638bbe..544697e085dd955c5450963590f0be26d3878559 100755 --- a/biscuit/apps/chronos/urls.py +++ b/biscuit/apps/chronos/urls.py @@ -18,5 +18,5 @@ urlpatterns = [ path('substitutions/', views.substitutions, name='timetable_substitutions'), path('substitutions/<int:year>/<int:month>/<int:day>/', views.substitutions, name='timetable_substitutions_date'), path('class.pdf', views.sub_pdf, name="timetable_substitutions_pdf"), - + path("debug/", views.debugging_tool, name="timetable_debugging_tool") ] diff --git a/biscuit/apps/chronos/views.py b/biscuit/apps/chronos/views.py index 17fe9fbefb588103779d01cdbc90e517d7e99046..a0f3f079cdad8a34b0c6c46e64d281b28d2229a2 100755 --- a/biscuit/apps/chronos/views.py +++ b/biscuit/apps/chronos/views.py @@ -408,3 +408,17 @@ def delete_hint(request, id): hint.delete() request.session["msg"] = "success_delete" return redirect('timetable_hints') + + +@login_required +# @permission_required("timetable.") +def debugging_tool(request): + f = open(os.path.join(BASE_DIR, "latex", "class0.log"), "r") + latex_1 = f.read() + f.close() + + f = open(os.path.join(BASE_DIR, "latex", "class1.log"), "r") + latex_2 = f.read() + f.close() + + return render(request, "timetable/debug.html", {"latex_1": latex_1, "latex_2": latex_2})