From aabab2d67d82e433afc63ec7ff4bb2ba69038050 Mon Sep 17 00:00:00 2001 From: mtyton Date: Sun, 18 Jun 2023 20:58:04 +0200 Subject: [PATCH] added toast messages --- artel/artel/settings/base.py | 13 +++++++++++++ artel/artel/static/js/artel.js | 5 +++++ artel/artel/templates/base.html | 7 ++++++- artel/store/views.py | 8 +++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/artel/artel/settings/base.py b/artel/artel/settings/base.py index 8e68022..66d3794 100644 --- a/artel/artel/settings/base.py +++ b/artel/artel/settings/base.py @@ -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 diff --git a/artel/artel/static/js/artel.js b/artel/artel/static/js/artel.js index e69de29..ffe2a1f 100644 --- a/artel/artel/static/js/artel.js +++ b/artel/artel/static/js/artel.js @@ -0,0 +1,5 @@ + +// close all alerts after 2 seconds +$('.alert').fadeTo(2000, 500).slideUp(500, function(){ + $("#success-alert").slideUp(500); +}); diff --git a/artel/artel/templates/base.html b/artel/artel/templates/base.html index 9b18cdf..086f284 100644 --- a/artel/artel/templates/base.html +++ b/artel/artel/templates/base.html @@ -41,16 +41,21 @@ {% main_menu max_levels=3 template="menu/custom_main_menu.html" %}
+ {% for message in messages %} + + {% endfor %} {% block content %}{% endblock %}
{# Global javascript #} - + {% block extra_js %} {# Override this in templates to add extra javascript #} diff --git a/artel/store/views.py b/artel/store/views.py index 4b349ca..384e43b 100644 --- a/artel/store/views.py +++ b/artel/store/views.py @@ -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"))