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

Validate uploaded files

parent a40bf379
No related branches found
No related tags found
1 merge request!86Merge school-apps
from django import forms
from django.core.validators import FileExtensionValidator
from django.utils import timezone
from mealplan.models import MealPlan
current_year = timezone.datetime.now().year
options_for_year = [(current_year, current_year),
(current_year + 1, current_year + 1)]
class MenuUploadForm(forms.ModelForm):
calendar_week = forms.ChoiceField(label="KW", choices=[(cw, cw) for cw in range(1, 53)])
year = forms.ChoiceField(label="Jahr", initial=timezone.datetime.now().year,
choices=[(timezone.datetime.now().year, timezone.datetime.now().year),
(timezone.datetime.now().year + 1, timezone.datetime.now().year + 1)])
choices=options_for_year)
# pdf = forms.FileField(label="PDF-Datei")
pdf = forms.FileField(label="PDF-Datei", validators=[FileExtensionValidator(allowed_extensions=["pdf"])])
class Meta:
model = MealPlan
......
......@@ -14,6 +14,18 @@
<a class="waves-effect waves-light btn green" href="{% url "menu_upload" %}"><i class="material-icons left">add</i>
Neuen Speiseplan hochladen</a>
<h5>Übersicht der hochgeladenen Speisepläne</h5>
<ul class="collection">
{% for menu in menus %}
<li class="collection-item ">
<span class="title">{{ menu }}</span>
<p>
<a class="btn-flat" href="/media/{{ menu.pdf }}" target="_blank">
<i class="material-icons left">picture_as_pdf</i> PDF anzeigen
</a>
</p>
<a href="#!" class="secondary-content"><i class="material-icons">grade</i></a>
</li>
{% endfor %}
</ul>
</main>
{% include 'partials/footer.html' %}
......@@ -14,7 +14,7 @@
{{ form.calendar_week }}
</div>
<div class="col s2 center-align">
<p>&nbsp;</p>
<small>&nbsp;</small>
<h4>/</h4>
</div>
<div class="input-field col s5">
......
from django.shortcuts import render, redirect
from mealplan.models import MealPlan
from .forms import MenuUploadForm
......@@ -18,4 +20,5 @@ def upload(request):
def index(request, msg=None):
return render(request, 'menu/index.html', {"msg": msg})
menus = MealPlan.objects.all().order_by("calendar_week", "year")
return render(request, 'menu/index.html', {"msg": msg, "menus": menus})
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