This commit is contained in:
Hugo LEVY-FALK 2018-12-14 20:25:20 +01:00
parent 14883ab6e9
commit 9598fe2299
3 changed files with 123 additions and 55 deletions

View file

@ -4,6 +4,7 @@
<h2>{{ account.firstname}} {{ account.lastname }}</h2> <h2>{{ account.firstname}} {{ account.lastname }}</h2>
<a class="button" href="{% url 'reset' account.pk %}">Remettre le solde à 0</a> <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 'refill' account.pk %}">Recharger le compte</a>
<a class="button" href="{% url 'pay' account.pk %}">Imprimer</a>
<br/> <br/>
<br/> <br/>
<h3>Ventes</h3> <h3>Ventes</h3>

View file

@ -12,82 +12,113 @@
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <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="{% 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"> <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 { td, th {
border: 1px solid #ddd; border: 1px solid #ddd;
padding: 8px; padding: 8px;
} }
-
tr:nth-child(even){background-color: #f2f2f2;} tr:nth-child(even){background-color: #f2f2f2;}
tr:hover {background-color: #ddd;} tr:hover {background-color: #ddd;}
th { th {
padding-top: 12px; padding-top: 12px;
padding-bottom: 12px; padding-bottom: 12px;
text-align: left; text-align: left;
background-color: #b1ddab; background-color: #b1ddab;
color: white; 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> </head>
<body class="homepage is-preload"> <body class="homepage is-preload">
<div id="page-wrapper"> <div id="page-wrapper">
<!-- Header --> <!-- Header -->
<header id="header"> <header id="header">
<div class="logo container"> <div class="logo container">
<div> <div>
<h1><a href="{% url 'index' %}" id="logo">Comet</a></h1> <h1><a href="{% url 'index' %}" id="logo">Comet</a></h1>
<p>Gestion de l'imprimante</p> <p>Gestion de l'imprimante</p>
</div>
</div> </div>
</header> </div>
</header>
<!-- Nav --> <!-- Nav -->
<nav id="nav"> <nav id="nav">
<ul> <ul>
<li class="current"><a href="{% url 'index' %}">Home</a></li> <li class="current"><a href="{% url 'index' %}">Home</a></li>
<li><a href="{% url 'search' %}">Imprimer</a></li> <li><a href="{% url 'search' %}">Imprimer</a></li>
</ul> </ul>
</nav> </nav>
<!-- Main --> <!-- Main -->
<section id="main"> <section id="main">
<div class="container"> <div class="container">
<div class="row gtr-200"> <div class="col-12">
<div class="col-2"></div> {% if messages %}
<div class="col-8"> <ul class="messages">
{% block content %}{% endblock %} {% for message in messages %}
</div> <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
<div class="col-2"></div> {{ message }}
</div> </li>
{% endfor %}
</ul>
{% endif %}
</div> </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 -->
<footer id="footer"> <footer id="footer">
<div class="container"> <div class="container">
<!-- Copyright --> <!-- Copyright -->
<div id="copyright"> <div id="copyright">
<ul class="menu"> <ul class="menu">
<li>&copy; Untitled. All rights reserved</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li> <li>&copy; Untitled. All rights reserved</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
</ul> </ul>
</div>
</div> </div>
</footer>
</div>
</footer>
</div> </div>
<!-- Scripts --> <!-- Scripts -->
<script src="{% static 'js/jquery.min.js' %}"></script> <script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/jquery.dropotron.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/jquery.scrolly.min.js' %}"></script>
<script src="{% static 'js/browser.min.js' %}"></script> <script src="{% static 'js/browser.min.js' %}"></script>
<script src="{% static 'js/breakpoints.min.js' %}"></script> <script src="{% static 'js/breakpoints.min.js' %}"></script>
<script src="{% static 'js/util.js' %}"></script> <script src="{% static 'js/util.js' %}"></script>
<script src="{% static 'js/main.js' %}"></script> <script src="{% static 'js/main.js' %}"></script>
</body> </body>
</html> </html>

View file

@ -5,6 +5,7 @@ from django.shortcuts import (
) )
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib import messages
from .models import Account, Sale, Article from .models import Account, Sale, Article
from .forms import SaleForm, ChooseArticleForm, AccountForm, SearchForm, ArticleForm from .forms import SaleForm, ChooseArticleForm, AccountForm, SearchForm, ArticleForm
@ -22,6 +23,14 @@ def refill_balance(request, pk):
account.calc_balance() account.calc_balance()
bal = account.balance bal = account.balance
account.save() 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 redirect(reverse('account', args=[account.pk,]))
return render( return render(
@ -42,10 +51,17 @@ def pay(request, pk):
if form.is_valid(): if form.is_valid():
sale = form.to_sale() sale = form.to_sale()
sale.account = account if float(sale.price + account.balance) >= 0:
sale.save() sale.account = account
account.calc_balance() sale.save()
account.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 redirect(reverse('account', args=[account.pk,]))
return render( return render(
@ -72,8 +88,16 @@ def reset_balance(request, pk):
sale.save() sale.save()
account.calc_balance() account.calc_balance()
account.save() account.save()
messages.success(
request,
"Remise à zéro du solde réussie."
)
return redirect(reverse('account', args=[account.pk,])) 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 redirect(reverse('account', args=[account.pk,]))
return render( return render(
@ -92,6 +116,10 @@ def create_account(request):
if form.is_valid(): if form.is_valid():
account = form.save() account = form.save()
messages.success(
request,
"Le compte a été créé."
)
return redirect(reverse('account', args=[account.pk,])) return redirect(reverse('account', args=[account.pk,]))
return render( return render(
@ -139,6 +167,10 @@ def article(request, pk):
form = ArticleForm(request.POST or None, instance=article) form = ArticleForm(request.POST or None, instance=article)
if form.is_valid(): if form.is_valid():
form.save() form.save()
messages.success(
request,
"L'article a été modifié."
)
return redirect(reverse('list-articles')) return redirect(reverse('list-articles'))
return render( return render(
request, request,
@ -155,6 +187,10 @@ def new_article(request):
form = ArticleForm(request.POST or None) form = ArticleForm(request.POST or None)
if form.is_valid(): if form.is_valid():
form.save() form.save()
messages.success(
request,
"L'article a été créé."
)
return redirect(reverse('list-articles')) return redirect(reverse('list-articles'))
return render( return render(
request, request,