diff --git a/gestion/migrations/0005_auto_20190106_0018.py b/gestion/migrations/0005_auto_20190106_0018.py new file mode 100644 index 0000000..2b3fe3b --- /dev/null +++ b/gestion/migrations/0005_auto_20190106_0018.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1 on 2019-01-05 23:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gestion', '0004_auto_20181223_1830'), + ] + + operations = [ + migrations.AddField( + model_name='historicalproduct', + name='showingMultiplier', + field=models.PositiveIntegerField(default=1), + ), + migrations.AddField( + model_name='product', + name='showingMultiplier', + field=models.PositiveIntegerField(default=1), + ), + ] diff --git a/gestion/models.py b/gestion/models.py index ee03f91..a9fc147 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -39,6 +39,7 @@ class Product(models.Model): volume = models.PositiveIntegerField(default=0) deg = models.DecimalField(default=0,max_digits=5, decimal_places=2, verbose_name="Degré", validators=[MinValueValidator(0)]) adherentRequired = models.BooleanField(default=True, verbose_name="Adhérent requis") + showingMultiplier = models.PositiveIntegerField(default=1) history = HistoricalRecords() def __str__(self): diff --git a/users/templates/users/profile.html b/users/templates/users/profile.html index 03b52d3..7a3e12f 100644 --- a/users/templates/users/profile.html +++ b/users/templates/users/profile.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load static %} +{% load users_extra %} {% block entete %}{% if self %}Mon Profil{% else %}Profil de {{user}}{% endif %}{%endblock%} {% block navbar %} @@ -97,22 +98,10 @@ label: '# of Votes', data: [{% for q in quantities %}{{q}}, {% endfor %}], backgroundColor: [ - 'rgba(255, 99, 132, 0.2)', - 'rgba(54, 162, 235, 0.2)', - 'rgba(255, 206, 86, 0.2)', - 'rgba(75, 192, 192, 0.2)', - 'rgba(153, 102, 255, 0.2)', - 'rgba(255, 159, 64, 0.2)' + {% for q in products %} + 'rgb({% random_filter 0 255 %}, {% random_filter 0 255 %}, {% random_filter 0 255 %})', + {% endfor %} ], - borderColor: [ - 'rgba(255,99,132,1)', - 'rgba(54, 162, 235, 1)', - 'rgba(255, 206, 86, 1)', - 'rgba(75, 192, 192, 1)', - 'rgba(153, 102, 255, 1)', - 'rgba(255, 159, 64, 1)' - ], - borderWidth: 1 }] }, options: { diff --git a/users/templatetags/__init__;py b/users/templatetags/__init__;py new file mode 100644 index 0000000..e69de29 diff --git a/users/templatetags/users_extra.py b/users/templatetags/users_extra.py new file mode 100644 index 0000000..53730e1 --- /dev/null +++ b/users/templatetags/users_extra.py @@ -0,0 +1,9 @@ +import random + +from django import template + +register = template.Library() + +@register.simple_tag +def random_filter(a, b): + return random.randint(a, b) diff --git a/users/views.py b/users/views.py index 4f277e7..bb183c8 100644 --- a/users/views.py +++ b/users/views.py @@ -154,15 +154,25 @@ def profile(request, pk): whitelists = WhiteListHistory.objects.filter(user=user) reloads = Reload.objects.filter(customer=user).order_by('-date')[:5] consumptionsChart = Consumption.objects.filter(customer=user) + products_pre = [] + quantities_pre = [] + for ch in consumptionsChart: + if ch.product in products_pre: + i = products_pre.index(ch.product) + quantities_pre[i] += int(ch.quantity/ch.product.showingMultiplier) + else: + products_pre.append(ch.product) + quantities_pre.append(int(ch.quantity/ch.product.showingMultiplier)) + tot = len(products_pre) + totQ = sum(quantities_pre) products = [] quantities = [] - for ch in consumptionsChart: - if ch.product in products: - i = products.index(ch.product) - quantities[i] += ch.quantity - else: - products.append(ch.product) - quantities.append(ch.quantity) + for k in range(tot): + if quantities_pre[k]/totQ >= 0.01: + products.append(products_pre[k]) + quantities.append(quantities_pre[k]) + print(products) + print(quantities) lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10] lastMenus = MenuHistory.objects.filter(customer=user).order_by('-date')[:10] return render(request, "users/profile.html",