From c9e8a57cb556100cf97d3e5560f9a9d82f3f0140 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Thu, 16 May 2019 19:35:23 +0200 Subject: [PATCH] Solve cache problem (bad solution) | Some design changes --- biscuit/apps/chronos/models.py | 5 +++ .../chronos/templates/timetable/hints.html | 43 ++++++++----------- .../timetable/latex/substitutions.tex | 1 + biscuit/apps/chronos/views.py | 6 ++- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/biscuit/apps/chronos/models.py b/biscuit/apps/chronos/models.py index 87490dd5..f989e7a7 100755 --- a/biscuit/apps/chronos/models.py +++ b/biscuit/apps/chronos/models.py @@ -1,6 +1,8 @@ from datetime import date from django.db import models +from django.db.models.signals import post_save +from django.dispatch import receiver from martor.models import MartorField from timetable.m2l import convert_markdown_2_latex @@ -64,6 +66,9 @@ class Hint(models.Model): # Convert LaTeX already when saving as cache because then is no need to do it later > performance savings self.text_as_latex = convert_markdown_2_latex(self.text) + super(Hint, self).save(force_insert=force_insert, force_update=force_update, using=using, + update_fields=update_fields) + # Format classes already > cache, too self.classes_formatted = format_classes(self.classes.all()) diff --git a/biscuit/apps/chronos/templates/timetable/hints.html b/biscuit/apps/chronos/templates/timetable/hints.html index 2a4e11ff..d838b63a 100755 --- a/biscuit/apps/chronos/templates/timetable/hints.html +++ b/biscuit/apps/chronos/templates/timetable/hints.html @@ -3,6 +3,8 @@ {% load martortags %} <main> + <h4>Hinweise</h4> + {% if msg %} <div class="alert success"> <p> @@ -12,23 +14,27 @@ </p> </div> {% endif %} - <h4>Hinweise</h4> - <div class="card"> <form method="GET" class="card-content"> - <a href="{% url 'timetable_add_hint' %}" class="waves-effect waves-light btn green"> - <i class="material-icons left">add</i> - Neuen Hinweis erstellen - </a> + <div class="row no-margin"> + <div class="col s12 m4"> + <a href="{% url 'timetable_add_hint' %}" class="waves-effect waves-light btn green"> + <i class="material-icons left">add</i> + Neuen Hinweis erstellen + </a> + </div> + <div class="col s12 m8 right-align"> + <button type="submit" class="waves-effect waves-green btn-flat"> + <i class="material-icons left">refresh</i> Filter aktualisieren + </button> + <a class="waves-effect waves-red btn-flat " href="{% url "timetable_hints" %}"> + <i class="material-icons left">clear</i> Filter entfernen + </a> + </div> + </div> {% form form=f.form %} {% endform %} - <button type="submit" class="waves-effect waves-light btn"> - <i class="material-icons left">refresh</i> Filter aktualisieren - </button> - <a class="waves-effect waves-light btn red" href="{% url "timetable_hints" %}"> - <i class="material-icons left">clear</i> Filter entfernen - </a> </form> </div> @@ -40,14 +46,10 @@ <div class="col s10"> <strong>{{ hint.from_date }} — {{ hint.to_date }}</strong> für <strong> - {% for class in hint.classes.all %} - {{ class }}, - {% endfor %} + {{ hint.classes_formatted }} </strong> {% if hint.teachers %} <span class="badge new green no-float no-margin">Lehrkräfte</span> - {% else %} - <span class="badge new red no-float no-margin">Lehrkräfte</span> {% endif %} </div> <div class="col s2"> @@ -78,13 +80,6 @@ </li> {% endfor %} </ul> - <p> - <span class="badge new green no-float no-margin">Lehrkräfte</span> - Lehrkräfte sehen den Hinweis - <span class="badge new red no-float no-margin">Lehrkräfte</span> - Lehrkräfte sehen den Hinweis - <strong>nicht</strong> - </p> </main> {% include 'partials/footer.html' %} diff --git a/biscuit/apps/chronos/templates/timetable/latex/substitutions.tex b/biscuit/apps/chronos/templates/timetable/latex/substitutions.tex index 053c2965..7a708cee 100644 --- a/biscuit/apps/chronos/templates/timetable/latex/substitutions.tex +++ b/biscuit/apps/chronos/templates/timetable/latex/substitutions.tex @@ -10,6 +10,7 @@ \usepackage{fancyhdr} \usepackage{graphicx} \usepackage{longtable} +\usepackage{booktabs} \usepackage{multirow} \usepackage{color, colortbl} \usepackage[colorlinks, linkcolor = black, citecolor = black, filecolor = black, urlcolor = black]{hyperref} diff --git a/biscuit/apps/chronos/views.py b/biscuit/apps/chronos/views.py index 3238237d..17fe9fbe 100755 --- a/biscuit/apps/chronos/views.py +++ b/biscuit/apps/chronos/views.py @@ -372,7 +372,8 @@ def add_hint(request): form = HintForm(request.POST) if form.is_valid(): - form.save() + i = form.save() + i.save() # return redirect('timetable_add_hint') form = HintForm() msg = "success" @@ -390,7 +391,8 @@ def edit_hint(request, id): form = HintForm(request.POST, instance=hint) if form.is_valid(): - form.save() + i = form.save() + i.save() request.session["msg"] = "success_edit" return redirect('timetable_hints') else: -- GitLab