mirror of
https://github.com/nanoy42/coope
synced 2024-12-23 23:43:47 +00:00
Merge branch 'classement_produit' into dev
This commit is contained in:
commit
bb5e2258f6
3 changed files with 64 additions and 2 deletions
|
@ -45,6 +45,22 @@ class Product(models.Model):
|
|||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def user_ranking(self, pk):
|
||||
user = User.objects.get(pk=pk)
|
||||
consumptions = ConsumptionHistory.objects.filter(customer=user).filter(product=self)
|
||||
# add menu
|
||||
nb = 0
|
||||
for consumption in consumptions:
|
||||
nb += consumption.quantity
|
||||
return (user, nb)
|
||||
|
||||
@property
|
||||
def ranking(self):
|
||||
users = User.objects.all()
|
||||
ranking = [self.user_ranking(user.pk) for user in users]
|
||||
ranking.sort(key=lambda x:x[1], reverse=True)
|
||||
return ranking[0:25]
|
||||
|
||||
|
||||
def isPinte(id):
|
||||
product = Product.objects.get(id=id)
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
{% extends "base.html" %}
|
||||
{%load static %}
|
||||
{%block entete%}Classement{%endblock%}
|
||||
{% block nav %}
|
||||
{% block navbar %}
|
||||
<ul>
|
||||
<li><a href="#first">Meilleurs consommateurs (débit)</a></li>
|
||||
<li><a href="#second">Meilleurs consommateurs (alcool)</a></li>
|
||||
<li><a href="#third">Classement par produit</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
@ -70,4 +71,44 @@
|
|||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="third" class="main">
|
||||
<div class="spotlight">
|
||||
<div class="content">
|
||||
<header class="major">
|
||||
<h2>Classement par produit</h2>
|
||||
</header>
|
||||
<div class="row">
|
||||
<div class="8u 12u$(medium)">
|
||||
<form action="" method="POST">
|
||||
{% csrf_token %}
|
||||
{{form}}
|
||||
<br><br>
|
||||
<button type="submit" class="button">Afficher</button>
|
||||
</form>
|
||||
{% if product_ranking %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Place</th>
|
||||
<th>Pseudo</th>
|
||||
<th>Quantités consommées</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for customer in product_ranking %}
|
||||
<tr>
|
||||
<th>{{ forloop.counter }}</th>
|
||||
<th><a href="{% url 'users:profile' customer.0.pk %}">{{ customer.0.username }}</a></th>
|
||||
<th>{{ customer.1 }}</th>
|
||||
</tr>
|
||||
{%endfor%}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{{form.media}}
|
||||
{%endblock%}
|
|
@ -939,7 +939,12 @@ def ranking(request):
|
|||
alcohol = customer.profile.alcohol
|
||||
list.append([customer, alcohol])
|
||||
bestDrinkers = sorted(list, key=lambda x: x[1], reverse=True)[:25]
|
||||
return render(request, "gestion/ranking.html", {"bestBuyers": bestBuyers, "bestDrinkers": bestDrinkers})
|
||||
form = SearchProductForm(request.POST or None)
|
||||
if(form.is_valid()):
|
||||
product_ranking = form.cleaned_data['product'].ranking
|
||||
else:
|
||||
product_ranking = None
|
||||
return render(request, "gestion/ranking.html", {"bestBuyers": bestBuyers, "bestDrinkers": bestDrinkers, "product_ranking": product_ranking, "form": form})
|
||||
|
||||
########## Pinte monitoring ##########
|
||||
|
||||
|
|
Loading…
Reference in a new issue