From edd724cee330ae51eef201388effb5e13951ae89 Mon Sep 17 00:00:00 2001 From: nanoy Date: Wed, 13 Nov 2019 14:43:47 +0000 Subject: [PATCH] Ajout du wall of fame --- coopeV3/urls.py | 1 + coopeV3/views.py | 11 ++++++++--- gestion/views.py | 3 +++ staticfiles/manage.js | 8 ++++++-- templates/wall_of_fame.html | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 templates/wall_of_fame.html diff --git a/coopeV3/urls.py b/coopeV3/urls.py index 294fecc..b213148 100644 --- a/coopeV3/urls.py +++ b/coopeV3/urls.py @@ -25,6 +25,7 @@ urlpatterns = [ path('home', views.homepage, name="homepage"), path('about', views.about, name="about"), path('coope-runner', views.coope_runner, name="coope-runner"), + path('wall-of-fame/', views.wall_of_fame, name="wall-of-fame"), path('stats', views.stats, name="stats"), path('admin/doc/', include('django.contrib.admindocs.urls')), path('admin/', admin.site.urls), diff --git a/coopeV3/views.py b/coopeV3/views.py index e04eec0..496627a 100644 --- a/coopeV3/views.py +++ b/coopeV3/views.py @@ -1,6 +1,6 @@ import os -from django.shortcuts import redirect, render +from django.shortcuts import redirect, render, get_object_or_404 from django.urls import reverse from django.conf import settings from django.contrib.auth.decorators import login_required @@ -8,7 +8,7 @@ from django.contrib.auth.models import User, Group from preferences.models import GeneralPreferences, PaymentMethod, Cotisation from gestion.models import Keg, ConsumptionHistory, Category, Product, Menu -from users.models import School +from users.models import School, Profile from .acl import active_required, admin_required @@ -99,4 +99,9 @@ def stats(request): "payment_methods": payment_methods, "cotisations": cotisations, "nb_quotes": nb_quotes, - }) \ No newline at end of file + }) + +def wall_of_fame(request, pk): + user = get_object_or_404(User, pk=pk) + other_famous = Profile.objects.filter(debit__gte=1000) + return render(request, "wall_of_fame.html", {"user": user, "other_famous": other_famous}) \ No newline at end of file diff --git a/gestion/views.py b/gestion/views.py index f6213c2..d9a415f 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -81,6 +81,7 @@ def order(request): user = User.objects.get(pk=request.POST['user']) except: raise Exception("Impossible de récupérer l'utilisateur") + previous_debit = user.profile.debit paymentMethod = get_object_or_404(PaymentMethod, pk=request.POST['paymentMethod']) amount = Decimal(request.POST['amount']) order = json.loads(request.POST["order"]) @@ -240,6 +241,8 @@ def order(request): raise Exception("Le stock du produit " + article.name + "n'autorise pas l'opération") user.profile.alcohol += Decimal(quantity * float(product.deg) * product.volume * 0.79 /10 /1000) user.save() + if user.profile.debit >= 1000 and previous_debit < 1000: + return HttpResponse("fame") return HttpResponse("La commande a bien été effectuée") except Exception as e: return HttpResponse("Impossible d'effectuer la transaction : " + e.args[0]) diff --git a/staticfiles/manage.js b/staticfiles/manage.js index aa0a629..e4a307f 100644 --- a/staticfiles/manage.js +++ b/staticfiles/manage.js @@ -243,8 +243,12 @@ $(document).ready(function(){ } } $.post("order", {"user":id_user, "paymentMethod": $(this).attr('data-payment'), "order_length": products.length + menus.length + cotisations.length + reloads.length, "order": JSON.stringify(products), "amount": total, "menus": JSON.stringify(menus), "listPintes": JSON.stringify(listPintes), "cotisations": JSON.stringify(cotisations), "reloads": JSON.stringify(reloads)}, function(data){ - alert(data); - location.reload(); + if(data == "fame"){ + document.location.href="../wall-of-fame/"+id_user; + }else{ + alert(data); + location.reload(); + } }).fail(function(data){ alert("Impossible d'effectuer la transaction. Veuillez contacter le trésorier ou le président"); console.log(data); diff --git a/templates/wall_of_fame.html b/templates/wall_of_fame.html new file mode 100644 index 0000000..f308151 --- /dev/null +++ b/templates/wall_of_fame.html @@ -0,0 +1,33 @@ +{% extends 'base.html' %} +{% block entete %}Wall of fame{% endblock %} +{% block navbar %} + +{% endblock %} +{% block content %} +
+
+

{% if user.profile.debit >= 1000%}Félicitations{% else %}Tu n'as rien à faire ici{% endif %}

+
+
+ {% if user.profile.debit >= 1000%} + {% if other_famous.count == 1 %} + Tu es seul mais tu peux te féliciter toi même. + {% else %} + Bravo à {{user.username}} pour son entrée dans le club 1000 boules (aussi appelé club des gros sacs), actuellement composé de : +
    + {% for famous_user in other_famous %} + {% if famous_user.user != user %} +
  • {{famous_user.user.username}}
  • + {% endif %} + {% endfor %} +
+ Il est des nôôôôôôôtreees... + {% endif %} + {% else %} + Tu n'as rien à faire ici. + {% endif %} +
+
+{% endblock %}