added toast messages
rodzic
f66ef3ce45
commit
aabab2d67d
|
@ -172,6 +172,19 @@ WAGTAILSEARCH_BACKENDS = {
|
|||
# e.g. in notification emails. Don't include '/admin' or a trailing slash
|
||||
WAGTAILADMIN_BASE_URL = "https://artel.tepewu.pl"
|
||||
|
||||
# Messages
|
||||
from django.contrib import messages
|
||||
|
||||
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"
|
||||
MESSAGE_TAGS = {
|
||||
messages.DEBUG: "debug",
|
||||
messages.INFO: "info",
|
||||
messages.SUCCESS: "success",
|
||||
messages.WARNING: "warning",
|
||||
messages.ERROR: "danger",
|
||||
}
|
||||
|
||||
|
||||
# STORE SETTINGS
|
||||
PRODUCTS_PER_PAGE = 6
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
// close all alerts after 2 seconds
|
||||
$('.alert').fadeTo(2000, 500).slideUp(500, function(){
|
||||
$("#success-alert").slideUp(500);
|
||||
});
|
|
@ -41,16 +41,21 @@
|
|||
{% main_menu max_levels=3 template="menu/custom_main_menu.html" %}
|
||||
</div>
|
||||
<div class="col-md-9 mt-5 ml-2">
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-{{message.tags}}" role="alert">
|
||||
{{message}}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Global javascript #}
|
||||
<script type="text/javascript" src="{% static 'js/artel.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'js/jquery-3.6.4.min.js' %}"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.bundle.min.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'js/artel.js' %}"></script>
|
||||
<script src="{% static 'js/cart.js' %}"></script>
|
||||
{% block extra_js %}
|
||||
{# Override this in templates to add extra javascript #}
|
||||
|
|
|
@ -7,6 +7,7 @@ from django.views.generic import (
|
|||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.contrib import messages
|
||||
from rest_framework.viewsets import ViewSet
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
@ -96,15 +97,16 @@ class OrderView(View):
|
|||
def get(self, request, *args, **kwargs):
|
||||
cart = SessionCart(self.request)
|
||||
if cart.is_empty():
|
||||
# TODO - messages
|
||||
messages.error(request, "Twój koszyk jest pusty")
|
||||
return HttpResponseRedirect(reverse("cart"))
|
||||
return render(request, self.template_name, self.get_context_data())
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
# TODO - messages
|
||||
cart = SessionCart(self.request)
|
||||
if cart.is_empty():
|
||||
messages.error(request, "Twój koszyk jest pusty")
|
||||
return HttpResponseRedirect(reverse("cart"))
|
||||
|
||||
form = CustomerDataForm(request.POST)
|
||||
if not form.is_valid():
|
||||
context = self.get_context_data()
|
||||
|
@ -142,5 +144,5 @@ class OrderConfirmView(View):
|
|||
)
|
||||
request.session.pop("customer_data")
|
||||
cart.clear()
|
||||
# TODO - messages
|
||||
messages.success(request, "Zamówienie zostało złożone, sprawdź swój email.")
|
||||
return HttpResponseRedirect(reverse("cart"))
|
||||
|
|
Ładowanie…
Reference in New Issue