Verified Commit f28b8f38 authored by Jonathan Weth's avatar Jonathan Weth

Use material form to render upload form

parent 5cad4d11
from django import forms
from django.core.validators import FileExtensionValidator
from django.utils import timezone
from material import Layout, Row
from .models import Menu
......@@ -15,12 +16,15 @@ class MenuUploadForm(forms.ModelForm):
year = forms.ChoiceField(
initial=timezone.datetime.now().year, choices=options_for_year
)
pdf = forms.FileField(
label="PDF-Datei",
validators=[FileExtensionValidator(allowed_extensions=["pdf"])],
)
layout = Layout(
Row("calendar_week", "year"),
Row("pdf")
)
class Meta:
model = Menu
fields = ("calendar_week", "year", "pdf")
{% extends "core/base.html" %}
{% load msg_box %}
{% load msg_box i18n material_form %}
{% block page_title %}{% trans "Upload menu" %}{% endblock %}
{% block content %}
<h5>Speiseplan hochladen</h5>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{% msg_box form.non_field_errors "error" "error" %}
<div class="row">
<div class="input-field col s5">
{% msg_box form.calendar_week.errors "error" "error" %}
<small>Kalenderwoche</small>
{{ form.calendar_week }}
</div>
<div class="col s2 center-align">
<small>&nbsp;</small>
<h4>/</h4>
</div>
<div class="input-field col s5">
{% msg_box form.year.errors "error" "error" %}
<small>Jahr</small>
{{ form.year }}
</div>
</div>
<div class="file-field input-field">
{% msg_box form.pdf.errors "error" "error" %}
<div class="btn">
<span><i class="material-icons center">cloud_upload</i></span>
<input type="file" name="{{ form.pdf.html_name }}">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
{% form form=form %}{% endform %}
<button class="waves-effect waves-light btn green" type="submit">
<i class="material-icons left">cloud_upload</i>
Speiseplan hochladen und veröffentlichen
{% trans "Upload and publish menu" %}
</button>
</form>
<p>
<a href="{% url 'menu_index' %}" class="waves-effect waves-teal btn-flat">Zurück zur Übersicht</a>
<a href="{% url 'menu_index' %}" class="waves-effect waves-teal btn-flat">{% trans "Back to overview" %}</a>
</p>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment