mirror of https://github.com/nanoy42/coope
7 changed files with 293 additions and 0 deletions
@ -0,0 +1,66 @@ |
|||
from django.contrib.auth.decorators import user_passes_test |
|||
from django.contrib.auth.models import User |
|||
from django.shortcuts import redirect, get_object_or_404 |
|||
from django.urls import reverse |
|||
|
|||
from preferences.models import GeneralPreferences |
|||
|
|||
def admin_required(view): |
|||
""" |
|||
Test if the user is staff |
|||
""" |
|||
return user_passes_test(view, lambda u:u.is_staff) |
|||
|
|||
def superuser_required(view): |
|||
""" |
|||
Test if the user is superuser |
|||
""" |
|||
return user_passes_test(view, lambda u:u.is_superuser) |
|||
|
|||
def self_or_has_perm(pkName, perm): |
|||
""" |
|||
Test if the user is the request user (pk) or has perm permission |
|||
""" |
|||
def decorator(view): |
|||
def wrapper(request, *args, **kwargs): |
|||
user = get_object_or_404(User, pk=kwargs[pkName]) |
|||
if(user == request.user or request.user.has_perm(perm)): |
|||
return view(request, *args, **kwargs) |
|||
else: |
|||
return redirect(reverse('users:login')) |
|||
return wrapper |
|||
return decorator |
|||
|
|||
def active_required(view): |
|||
def wrapper(request, *args, **kwargs): |
|||
gp,_ = GeneralPreferences.objects.get_or_create(pk=1) |
|||
if(not gp.is_active): |
|||
return redirect(reverse('preferences:inactif')) |
|||
return view(request, *args, **kwargs) |
|||
return wrapper |
|||
|
|||
def acl_or(*perms): |
|||
def decorator(view): |
|||
def wrapper(request,*args, **kwargs): |
|||
can_pass = request.user.has_perm(perms[0]) |
|||
for perm in perms: |
|||
can_pass = can_pass or request.user.has_perm(perm) |
|||
if can_pass: |
|||
return view(request, *args, **kwargs) |
|||
else: |
|||
return redirect(reverse('users:login')) |
|||
return wrapper |
|||
return decorator |
|||
|
|||
def acl_and(*perms): |
|||
def decorator(view): |
|||
def wrapper(request,*args, **kwargs): |
|||
can_pass = request.user.has_perm(perms[0]) |
|||
for perm in perms: |
|||
can_pass = can_pass and request.user.has_perm(perm) |
|||
if can_pass: |
|||
return view(request, *args, **kwargs) |
|||
else: |
|||
return redirect(reverse('users:login')) |
|||
return wrapper |
|||
return decorator |
|||
@ -0,0 +1,24 @@ |
|||
{% extends "base.html" %} |
|||
{%load static %} |
|||
{%block entete%}<h1>Classement</h1>{%endblock%} |
|||
{% block nav %} |
|||
<ul> |
|||
<li><a href="#first">Dezo pas Dezo</a></li> |
|||
</ul> |
|||
{% endblock %} |
|||
{% block content %} |
|||
<section id="intro" class="main"> |
|||
<div class="spotlight"> |
|||
<div class="content"> |
|||
<header class="major"> |
|||
<h2>Dezo pas dezo</h2> |
|||
</header> |
|||
<div class="row"> |
|||
<div class="12u$"> |
|||
Dû à des problèmes techniques, cet onglet n'est actuellement pas disponible. |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</section> |
|||
{%endblock%} |
|||
@ -0,0 +1,24 @@ |
|||
{% extends "base.html" %} |
|||
{% block entete %}<h1>Gestion des utilisateurs</h1>{% endblock %} |
|||
{% block navbar %} |
|||
<ul> |
|||
<li><a href="#first">Général</a></li> |
|||
</ul> |
|||
{% endblock %} |
|||
{% block content %} |
|||
<section id="first" class="main"> |
|||
<header class="major"> |
|||
<h2>Général</h2> |
|||
</header> |
|||
<a class="button small">(Dés)Activer</a> <a class="button small">Modifier</a> <a href="#" class="button small">Supprimer</a><br> |
|||
<strong>Nom</strong> : {{ product.name }}<br> |
|||
<strong>Prix de vente</strong> : {{ product.amount }}€<br> |
|||
<strong>Stock en soute</strong> : {{ product.stockHold }}<br> |
|||
<strong>Stock au bar</strong> : {{ product.stockBar }}<br> |
|||
<strong>Code Barre</strong> : {{ product.barcode }}<br> |
|||
<strong>Catégorie</strong> : {{ product.category }}<br> |
|||
<strong>Actif</strong> : {{ product.active }}<br> |
|||
<strong>Dégré</strong> : {{ product.deg }}<br> |
|||
<strong>Volume</strong> : {{ product.volume }}cl<br> |
|||
</section> |
|||
{% endblock %} |
|||
@ -0,0 +1,73 @@ |
|||
{% extends "base.html" %} |
|||
{%load static %} |
|||
{%block entete%}<h1>Classement</h1>{%endblock%} |
|||
{% block nav %} |
|||
<ul> |
|||
<li><a href="#first">Meilleurs consommateurs (débit)</a></li> |
|||
<li><a href="#second">Meilleurs consommateurs (alcool)</a></li> |
|||
</ul> |
|||
{% endblock %} |
|||
{% block content %} |
|||
<section id="intro" class="main"> |
|||
<div class="spotlight"> |
|||
<div class="content"> |
|||
<header class="major"> |
|||
<h2>Meilleurs consommateurs (débit)</h2> |
|||
</header> |
|||
<div class="row"> |
|||
<div class="8u 12u$(medium)"> |
|||
<table> |
|||
<thead> |
|||
<tr> |
|||
<th>Place</th> |
|||
<th>Pseudo</th> |
|||
<th>Debit</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{%for customer in bestBuyers%} |
|||
<tr> |
|||
<th>{{ forloop.counter }}</th> |
|||
<th>{{ customer.username }}</th> |
|||
<th>{{ customer.profile.debit }}€</th> |
|||
</tr> |
|||
{%endfor%} |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</section> |
|||
<section id="second" class="main"> |
|||
<div class="spotlight"> |
|||
<div class="content"> |
|||
<header class="major"> |
|||
<h2>Meilleurs consommateurs (alcool)</h2> |
|||
</header> |
|||
<div class="row"> |
|||
<div class="8u 12u$(medium)"> |
|||
<table> |
|||
<thead> |
|||
<tr> |
|||
<th>Place</th> |
|||
<th>Pseudo</th> |
|||
<th>Nombre de kilos ingérés</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{% for customer in bestDrinkers %} |
|||
<tr> |
|||
<th>{{ forloop.counter }}</th> |
|||
<th>{{ customer.0.username }}</th> |
|||
<th>{{ customer.1 }}</th> |
|||
</tr> |
|||
{%endfor%} |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</section> |
|||
{%endblock%} |
|||
@ -0,0 +1,33 @@ |
|||
# Generated by Django 2.1 on 2018-10-09 09:19 |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('preferences', '0001_initial'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='paymentmethod', |
|||
name='is_usable_in_reload', |
|||
field=models.BooleanField(default=True, verbose_name='Rechargements ?'), |
|||
), |
|||
migrations.AlterField( |
|||
model_name='paymentmethod', |
|||
name='affect_balance', |
|||
field=models.BooleanField(default=False, verbose_name='Affecte le solde'), |
|||
), |
|||
migrations.AlterField( |
|||
model_name='paymentmethod', |
|||
name='is_active', |
|||
field=models.BooleanField(default=True, verbose_name='Actif'), |
|||
), |
|||
migrations.AlterField( |
|||
model_name='paymentmethod', |
|||
name='is_usable_in_cotisation', |
|||
field=models.BooleanField(default=True, verbose_name='Cotisations ?'), |
|||
), |
|||
] |
|||
@ -0,0 +1,18 @@ |
|||
# Generated by Django 2.1 on 2018-10-09 09:19 |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('users', '0001_initial'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name='school', |
|||
name='name', |
|||
field=models.CharField(max_length=255, verbose_name='Nom'), |
|||
), |
|||
] |
|||
@ -0,0 +1,55 @@ |
|||
{% extends "base.html" %} |
|||
{% load static %} |
|||
{% block entete %}<h1>Rechargements</h1>{%endblock%} |
|||
|
|||
{% block navbar %} |
|||
<ul> |
|||
<li><a href="#first">Rechargements ({{user}})</a></li> |
|||
</ul> |
|||
{% endblock %} |
|||
{% block content %} |
|||
<section id="first" class="main special"> |
|||
<header class="major"> |
|||
<h2>Rechargements ({{user}})</h2> |
|||
</header> |
|||
<section id="rechargements"> |
|||
<div class="table-wrapper"> |
|||
<table> |
|||
<thead id="headRechargement"> |
|||
<tr> |
|||
<th>Montant</th> |
|||
<th>Type de Rechargement</th> |
|||
<th>Date</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody id="bodyRechargement"> |
|||
{% for reload in reloads %} |
|||
<tr> |
|||
<th>{{reload.amount}}€</th> |
|||
<th>{{reload.PaymentMethod}}</th> |
|||
<th>{{reload.date}}</th> |
|||
</tr> |
|||
{% endfor %} |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
<div class="pagination special"> |
|||
<span class="step-links"> |
|||
{% if reloads.has_previous %} |
|||
<a href="{% url 'users:allReloads' user.pk 1 %}">« Première </a> |
|||
<a href="{% url 'users:allReloads' user.pk reloads.previous_page_number %}"> Précédente </a> |
|||
{% endif %} |
|||
|
|||
<span class="current"> |
|||
Page {{ reloads.number }} sur {{ reloads.paginator.num_pages }}. |
|||
</span> |
|||
|
|||
{% if reloads.has_next %} |
|||
<a href="{% url 'users:allReloads' user.pk reloads.next_page_number %}"> Suivante </a> |
|||
<a href="{% url 'users:allReloads' user.pk reloads.paginator.num_pages %}"> Dernière »</a> |
|||
{% endif %} |
|||
</span> |
|||
</div> |
|||
</section> |
|||
</section> |
|||
{%endblock%} |
|||
Loading…
Reference in new issue