messages
This commit is contained in:
parent
14883ab6e9
commit
9598fe2299
3 changed files with 123 additions and 55 deletions
|
@ -4,6 +4,7 @@
|
|||
<h2>{{ account.firstname}} {{ account.lastname }}</h2>
|
||||
<a class="button" href="{% url 'reset' account.pk %}">Remettre le solde à 0</a>
|
||||
<a class="button" href="{% url 'refill' account.pk %}">Recharger le compte</a>
|
||||
<a class="button" href="{% url 'pay' account.pk %}">Imprimer</a>
|
||||
<br/>
|
||||
<br/>
|
||||
<h3>Ventes</h3>
|
||||
|
|
|
@ -12,82 +12,113 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||||
<link rel="stylesheet" href="{% static 'css/main.css' %}" />
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
|
||||
<style>
|
||||
<style>
|
||||
td, th {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
-
|
||||
tr:nth-child(even){background-color: #f2f2f2;}
|
||||
|
||||
tr:hover {background-color: #ddd;}
|
||||
|
||||
th {
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
text-align: left;
|
||||
background-color: #b1ddab;
|
||||
color: white;
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
text-align: left;
|
||||
background-color: #b1ddab;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
.messages li {
|
||||
list-style-type: none;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.messages .success {
|
||||
background-color: #b1ddab;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.messages .warning {
|
||||
background-color: #f7db7e;
|
||||
}
|
||||
|
||||
.messages .error {
|
||||
background-color: #f7947e;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="homepage is-preload">
|
||||
<div id="page-wrapper">
|
||||
|
||||
<!-- Header -->
|
||||
<header id="header">
|
||||
<div class="logo container">
|
||||
<div>
|
||||
<h1><a href="{% url 'index' %}" id="logo">Comet</a></h1>
|
||||
<p>Gestion de l'imprimante</p>
|
||||
</div>
|
||||
<header id="header">
|
||||
<div class="logo container">
|
||||
<div>
|
||||
<h1><a href="{% url 'index' %}" id="logo">Comet</a></h1>
|
||||
<p>Gestion de l'imprimante</p>
|
||||
</div>
|
||||
</header>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Nav -->
|
||||
<nav id="nav">
|
||||
<ul>
|
||||
<li class="current"><a href="{% url 'index' %}">Home</a></li>
|
||||
<li><a href="{% url 'search' %}">Imprimer</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<nav id="nav">
|
||||
<ul>
|
||||
<li class="current"><a href="{% url 'index' %}">Home</a></li>
|
||||
<li><a href="{% url 'search' %}">Imprimer</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<!-- Main -->
|
||||
<section id="main">
|
||||
<div class="container">
|
||||
<div class="row gtr-200">
|
||||
<div class="col-2"></div>
|
||||
<div class="col-8">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
<div class="col-2"></div>
|
||||
</div>
|
||||
<section id="main">
|
||||
<div class="container">
|
||||
<div class="col-12">
|
||||
{% if messages %}
|
||||
<ul class="messages">
|
||||
{% for message in messages %}
|
||||
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
|
||||
{{ message }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
<div class="row gtr-200">
|
||||
<div class="col-2"></div>
|
||||
<div class="col-8">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
<div class="col-2"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer id="footer">
|
||||
<div class="container">
|
||||
<!-- Copyright -->
|
||||
<div id="copyright">
|
||||
<ul class="menu">
|
||||
<li>© Untitled. All rights reserved</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<footer id="footer">
|
||||
<div class="container">
|
||||
<!-- Copyright -->
|
||||
<div id="copyright">
|
||||
<ul class="menu">
|
||||
<li>© Untitled. All rights reserved</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Scripts -->
|
||||
<script src="{% static 'js/jquery.min.js' %}"></script>
|
||||
<script src="{% static 'js/jquery.dropotron.min.js' %}"></script>
|
||||
<script src="{% static 'js/jquery.scrolly.min.js' %}"></script>
|
||||
<script src="{% static 'js/browser.min.js' %}"></script>
|
||||
<script src="{% static 'js/breakpoints.min.js' %}"></script>
|
||||
<script src="{% static 'js/util.js' %}"></script>
|
||||
<script src="{% static 'js/main.js' %}"></script>
|
||||
<script src="{% static 'js/jquery.min.js' %}"></script>
|
||||
<script src="{% static 'js/jquery.dropotron.min.js' %}"></script>
|
||||
<script src="{% static 'js/jquery.scrolly.min.js' %}"></script>
|
||||
<script src="{% static 'js/browser.min.js' %}"></script>
|
||||
<script src="{% static 'js/breakpoints.min.js' %}"></script>
|
||||
<script src="{% static 'js/util.js' %}"></script>
|
||||
<script src="{% static 'js/main.js' %}"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.shortcuts import (
|
|||
)
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
|
||||
from .models import Account, Sale, Article
|
||||
from .forms import SaleForm, ChooseArticleForm, AccountForm, SearchForm, ArticleForm
|
||||
|
@ -22,6 +23,14 @@ def refill_balance(request, pk):
|
|||
account.calc_balance()
|
||||
bal = account.balance
|
||||
account.save()
|
||||
messages.success(
|
||||
request,
|
||||
"Le solde de {} {} a été rechargé de {}€".format(
|
||||
account.firstname,
|
||||
account.lastname,
|
||||
sale.price
|
||||
)
|
||||
)
|
||||
return redirect(reverse('account', args=[account.pk,]))
|
||||
|
||||
return render(
|
||||
|
@ -42,10 +51,17 @@ def pay(request, pk):
|
|||
|
||||
if form.is_valid():
|
||||
sale = form.to_sale()
|
||||
sale.account = account
|
||||
sale.save()
|
||||
account.calc_balance()
|
||||
account.save()
|
||||
if float(sale.price + account.balance) >= 0:
|
||||
sale.account = account
|
||||
sale.save()
|
||||
account.calc_balance()
|
||||
account.save()
|
||||
messages.success(
|
||||
request,
|
||||
"Paiement de {}€ réalisé avec succès.".format(sale.price)
|
||||
)
|
||||
else:
|
||||
messages.error(request, "Solde trop bas pour l'opération")
|
||||
return redirect(reverse('account', args=[account.pk,]))
|
||||
|
||||
return render(
|
||||
|
@ -72,8 +88,16 @@ def reset_balance(request, pk):
|
|||
sale.save()
|
||||
account.calc_balance()
|
||||
account.save()
|
||||
messages.success(
|
||||
request,
|
||||
"Remise à zéro du solde réussie."
|
||||
)
|
||||
return redirect(reverse('account', args=[account.pk,]))
|
||||
elif account.balance is 0:
|
||||
elif float(account.balance) == 0:
|
||||
messages.warning(
|
||||
request,
|
||||
"Le solde est déjà nul."
|
||||
)
|
||||
return redirect(reverse('account', args=[account.pk,]))
|
||||
|
||||
return render(
|
||||
|
@ -92,6 +116,10 @@ def create_account(request):
|
|||
|
||||
if form.is_valid():
|
||||
account = form.save()
|
||||
messages.success(
|
||||
request,
|
||||
"Le compte a été créé."
|
||||
)
|
||||
return redirect(reverse('account', args=[account.pk,]))
|
||||
|
||||
return render(
|
||||
|
@ -139,6 +167,10 @@ def article(request, pk):
|
|||
form = ArticleForm(request.POST or None, instance=article)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(
|
||||
request,
|
||||
"L'article a été modifié."
|
||||
)
|
||||
return redirect(reverse('list-articles'))
|
||||
return render(
|
||||
request,
|
||||
|
@ -155,6 +187,10 @@ def new_article(request):
|
|||
form = ArticleForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(
|
||||
request,
|
||||
"L'article a été créé."
|
||||
)
|
||||
return redirect(reverse('list-articles'))
|
||||
return render(
|
||||
request,
|
||||
|
|
Loading…
Reference in a new issue