3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-12-23 07:23:47 +00:00

Ajout du wall of fame

This commit is contained in:
Yoann Pétri 2019-11-13 14:43:47 +00:00
parent ad6b78c8e7
commit edd724cee3
5 changed files with 51 additions and 5 deletions

View file

@ -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/<int:pk>', 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),

View file

@ -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,
})
})
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})

View file

@ -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])

View file

@ -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);

View file

@ -0,0 +1,33 @@
{% extends 'base.html' %}
{% block entete %}Wall of fame{% endblock %}
{% block navbar %}
<ul>
<li><a href="#first">{% if user.profile.debit >= 1000%}Félicitations{% else %}Tu n'as rien à faire ici{% endif %}</a></li>
</ul>
{% endblock %}
{% block content %}
<section id="first" class="main">
<header class="major">
<h2>{% if user.profile.debit >= 1000%}Félicitations{% else %}Tu n'as rien à faire ici{% endif %}</h2>
</header>
<section>
{% 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 :
<ul>
{% for famous_user in other_famous %}
{% if famous_user.user != user %}
<li>{{famous_user.user.username}}</li>
{% endif %}
{% endfor %}
</ul>
Il est des nôôôôôôôtreees...
{% endif %}
{% else %}
Tu n'as rien à faire ici.
{% endif %}
</section>
</section>
{% endblock %}