3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-12-25 00:13:46 +00:00

Merge branch 'classement_produit' into dev

This commit is contained in:
Yoann Pétri 2019-01-18 15:39:02 +01:00
commit bb5e2258f6
3 changed files with 64 additions and 2 deletions

View file

@ -45,6 +45,22 @@ class Product(models.Model):
def __str__(self): def __str__(self):
return self.name 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): def isPinte(id):
product = Product.objects.get(id=id) product = Product.objects.get(id=id)

View file

@ -1,10 +1,11 @@
{% extends "base.html" %} {% extends "base.html" %}
{%load static %} {%load static %}
{%block entete%}Classement{%endblock%} {%block entete%}Classement{%endblock%}
{% block nav %} {% block navbar %}
<ul> <ul>
<li><a href="#first">Meilleurs consommateurs (débit)</a></li> <li><a href="#first">Meilleurs consommateurs (débit)</a></li>
<li><a href="#second">Meilleurs consommateurs (alcool)</a></li> <li><a href="#second">Meilleurs consommateurs (alcool)</a></li>
<li><a href="#third">Classement par produit</a></li>
</ul> </ul>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -70,4 +71,44 @@
</div> </div>
</div> </div>
</section> </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%} {%endblock%}

View file

@ -939,7 +939,12 @@ def ranking(request):
alcohol = customer.profile.alcohol alcohol = customer.profile.alcohol
list.append([customer, alcohol]) list.append([customer, alcohol])
bestDrinkers = sorted(list, key=lambda x: x[1], reverse=True)[:25] 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 ########## ########## Pinte monitoring ##########