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

Hint form finished (without date checking) | Work at hint list

parent 39f55b1d
No related branches found
No related tags found
No related merge requests found
import django_filters
from django.forms import Form
from material import Fieldset, Row
from .models import Hint
class HintForm(Form):
layout = Row("from_date", "to_date", "classes", "teachers")
class HintFilter(django_filters.FilterSet):
class Meta:
model = Hint
fields = ['from_date', "to_date", "classes", "teachers"]
form = HintForm
from django.core.exceptions import ValidationError
from django.forms import ModelForm
from material import Layout, Fieldset, Row
from timetable.models import Hint
class HintForm(ModelForm):
layout = Layout(Fieldset('Zeitraum',
Row('from_date', 'to_date'),
),
Fieldset('Hinweistext',
"text",
),
Fieldset('Klassen',
'classes'),
)
class Meta:
model = Hint
fields = ("from_date", "to_date", "text", "classes", "teachers")
def clean(self):
super().clean()
print("validate")
print(self.cleaned_data["classes"], self.cleaned_data["teachers"])
if len(self.cleaned_data["classes"]) == 0 and self.cleaned_data["teachers"] is False:
raise ValidationError("Bitte gib eine Zielgruppe an (Klassen oder Lehrer).")
......@@ -35,13 +35,21 @@ class Hint(models.Model):
text = MartorField(verbose_name="Hinweistext")
# Relations
classes = models.ManyToManyField(HintClass, related_name="hints", verbose_name="Klassen")
teachers = models.BooleanField(verbose_name="Lehrer?", default=False)
classes = models.ManyToManyField(HintClass, related_name="hints", verbose_name="Klassen", blank=True)
teachers = models.BooleanField(verbose_name="Lehrer?", default=False, blank=True)
class Meta:
verbose_name = "Hinweis"
verbose_name_plural = "Hinweise"
def __str__(self):
classes_list = [str(x) for x in self.classes.all()]
if self.teachers:
classes_list.append("Lehrkräfte")
targets = ", ".join(classes_list)
return "[{}]: {}–{}".format(targets, self.from_date, self.to_date)
class Timetable(models.Model):
class Meta:
......
......@@ -7,25 +7,79 @@
<main>
<h4>Neuen Hinweis erstellen</h4>
<form method="post">
{% if msg == "success" %}
<div class="alert success">
<p>
<i class="material-icons left">check_circle</i>
Der Hinweis wurde erfolgreich erstellt und veröffentlicht. Weiteren Hinweis anlegen oder zur Übersicht
zurück?<br>
<a class="btn waves-effect waves-light" href="{% url "timetable_hints" %}"><i
class="material-icons left">arrow_back</i> Zurück zur Übersicht</a>
<a class="btn waves-effect waves-light green" href="#add-hint"><i class="material-icons left">add</i>
Weiteren Hinweis hinzufügen</a>
</p>
</div>
{% endif %}
<form method="post" action="" id="add-hint">
{% csrf_token %}
{{ form.non_field_errors }}
{% if form.non_field_errors %}
<div class="alert error">
<div>
<i class="material-icons left">warning</i>
{{ form.non_field_errors }}
</div>
</div>
{% endif %}
<h5>Über welchen Zeitraum soll der Hinweis angezeigt werden? <span class="red-text">*</span></h5>
<div class="row">
<div class="col s12 m6">
{% if form.from_date.errors %}
<div class="alert error">
<div>
<i class="material-icons left">warning</i>
{{ form.from_date.errors }}
</div>
</div>
{% endif %}
{{ form.from_date.label_tag }}
{{ form.from_date|add_class:"datepicker" }}
{{ form.from_date|add_class:"datepicker required" }}
</div>
<div class="col s12 m6">
{% if form.to_date.errors %}
<div class="alert error">
<div>
<i class="material-icons left">warning</i>
{{ form.to_date.erros }}
</div>
</div>
{% endif %}
{{ form.to_date.label_tag }}
{{ form.to_date|add_class:"datepicker" }}
{{ form.to_date|add_class:"datepicker required" }}
</div>
</div>
<h5>Für wen soll der Hinweis angezeigt werden? <span class="red-text">*</span></h5>
{% if form.classes.errors %}
<div class="alert error">
<div>
<i class="material-icons left">warning</i>
{{ form.classes.erros }}
</div>
</div>
{% endif %}
{{ form.classes.label_tag }}
{{ form.classes }}
{% if form.teachers.errors %}
<div class="alert error">
<div>
<i class="material-icons left">warning</i>
{{ form.teachers.erros }}
</div>
</div>
{% endif %}
<p>
<label>
{{ form.teachers }}
......@@ -34,6 +88,14 @@
</p>
<h5>Hinweistext <span class="red-text">*</span></h5>
{% if form.text.errors %}
<div class="alert error">
<div>
<i class="material-icons left">warning</i>
{{ form.text.erros }}
</div>
</div>
{% endif %}
{{ form.text }}
......
{% include 'partials/header.html' %}
{% load material_form %}
{% load martortags %}
<main>
<h4>Hinweise</h4>
<a href="{% url 'timetable_add_hint' %}" class="waves-effect waves-light btn green">
<i class="material-icons left">add</i>
Neuen Hinweis erstellen
</a>
{# <form method="GET">#}
{# {{ filter.form.as_p }}#}
{# <button type="submit" class="waves-effect waves-light btn">#}
{# <i class="material-icons left">refresh</i> Filter aktualisieren#}
{# </button>#}
{# </form>#}
<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>
{# {{ f.form.as_p }}#}
{% 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>
<ul class="collection">
{% for aub in filter.qs %}
<li class="collection-item">
<div class="row">
<div class="col s12 m4">
<p class="title">
<span class="item-text">
<i class="material-icons">access_time</i>
{{ aub.from_date }}, {{ aub.from_time }} Uhr &mdash; {{ aub.to_date }}, {{ aub.to_time }} Uhr
</span>
</p>
<p><a href="{% url 'aub_details' aub.id %}">{{ aub.description }}</a></p>
</div>
<div class="col s12 m6">
<p>
<span class="item-text">
<i class="material-icons">person</i>
{{ aub.created_by }}
</span>
</p>
</div>
<div class="col s12 m4">
<p>
{% csrf_token %}
<button type="submit" name="allow"
class="waves-effect waves-light btn-flat btn-flat-large" title="Annehmen">
<i class="material-icons center green-text">check_circle</i>
</button>
<button type="submit" name="deny"
class="waves-effect waves-light btn-flat btn-flat-large" title="Ablehnen">
<i class="material-icons center red-text">not_interested</i>
</button>
</p>
</div
<div class="col s12 m2">
<p>
<span class="badge new {{ aub.status.style_classes }}">{{ aub.status.name }}</span>
</p>
{% for hint in f.qs %}
<li class="collection-item row">
<div class="col s12 m4">
<span class="title">
{# <i class="material-icons left">access_time</i>#}
{{ hint.from_date }} &mdash; {{ hint.to_date }}
</span>
</div>
<div class="col s12 m4">
<i class="material-icons left">people</i>
{% for class in hint.classes.all %}
{{ class }},
{% endfor %}
{% 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 s12 m4">
<div class="right">
<a class="btn-flat waves-effect waves-teal"><i class="material-icons left">edit</i>
Bearbeiten</a>
<a class="btn-flat waves-effect waves-teal"><i class="material-icons left">delete</i>
Löschen</a>
</div>
</div>
<div class="col s12">
<p>
{# <i class="material-icons left">note</i>#}
{{ hint.text|safe_markdown }}</p>
</div>
</li>
{% endfor %}
</ul>
<p>
<span class="badge new green no-float no-margin">Lehrkräfte</span> Lehrkräfte sehen den Hinweis &nbsp;&nbsp;
<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' %}
......@@ -6,8 +6,10 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.http import Http404, FileResponse
from django.shortcuts import render, redirect
from django.utils import timezone
from material import Fieldset, Row
from schoolapps.settings import WEEK_DAYS
from timetable.filters import HintFilter
from timetable.forms import HintForm
from timetable.pdf import generate_class_tex, generate_pdf
......@@ -258,18 +260,24 @@ def substitutions(request, year=None, day=None, month=None):
@login_required
@permission_required("timetable.can_view_hint")
def hints(request):
return render(request, "timetable/hints.html")
f = HintFilter(request.GET, queryset=Hint.objects.all())
# f.form.layout = Fieldset("Hi", Row("from_date", "to_date", "classes", "teachers"))
return render(request, "timetable/hints.html", {"f": f})
@login_required
@permission_required('timetable.can_add_hint')
def add_hint(request):
msg = None
if request.method == 'POST':
form = HintForm(request.POST)
if form.is_valid():
return redirect('aub_applied_for')
form.save()
# return redirect('timetable_add_hint')
form = HintForm()
msg = "success"
else:
form = HintForm()
return render(request, 'timetable/addhint.html', {'form': form, "martor": True})
return render(request, 'timetable/addhint.html', {'form': form, "martor": True, "msg": msg})
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