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

Confirm upload

parent 8ff3ee00
No related branches found
No related tags found
1 merge request!86Merge school-apps
import os
from uuid import uuid4
from django.template.loader_tags import register
def path_and_rename(instance, filename):
upload_to = 'menus'
......@@ -13,3 +15,8 @@ def path_and_rename(instance, filename):
filename = '{}.{}'.format(uuid4().hex, ext)
# return the whole path to the file
return os.path.join(upload_to, filename)
@register.inclusion_tag("components/msgbox.html")
def msg_box(msg, color="red"):
return {"msg": msg, "color": color}
{% include 'partials/header.html' %}
<main>
{% if msg == "success" %}
{% msg_box "Der Speiseplan wurde erfolgreich hochgeladen." "green" %}
{% endif %}
<script type="text/javascript">
$('#alert_close').click(function () {
$("#alert_box").fadeOut("slow", function () {
});
});
</script>
<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>
</main>
......
......@@ -3,5 +3,6 @@ from . import views
urlpatterns = [
path('', views.index, name="menu_index"),
path('upload/', views.upload, name="menu_upload")
path('upload/', views.upload, name="menu_upload"),
path('<str:msg>', views.index, name="menu_index_msg")
]
......@@ -9,7 +9,7 @@ def upload(request):
if form.is_valid():
form.save()
return redirect('menu_index')
return redirect('menu_index_msg', msg="success")
else:
form = MenuUploadForm()
return render(request, 'menu/upload.html', {
......@@ -17,5 +17,5 @@ def upload(request):
})
def index(request):
return render(request, 'menu/index.html')
def index(request, msg=None):
return render(request, 'menu/index.html', {"msg": msg})
<div class="row" id="alert_box">
<div class="col s12 m12">
<div class="card {{ color }} darken-1">
<div class="row">
<div class="col s12 m10">
<div class="card-content white-text">
{{ msg }}
</div>
</div>
<div class="col s12 m2">
<a class="btn-flat right waves-effect waves-{{ color }}" id="alert_close">
<i class="material-icons center white-text">close</i>
</a>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
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