forked from DGNum/gestioCOF
Réécrit des vues pour la nouvelle fonctionnalité
On en profite pour rajouter des Mixins pour les perms buro/cof
This commit is contained in:
parent
b37e7c4c41
commit
a67446048e
3 changed files with 34 additions and 13 deletions
|
@ -23,7 +23,11 @@ urlpatterns = [
|
|||
views.spectacle,
|
||||
name="bda-spectacle",
|
||||
),
|
||||
url(r"^spectacles/unpaid/(?P<tirage_id>\d+)$", views.unpaid, name="bda-unpaid"),
|
||||
url(
|
||||
r"^spectacles/unpaid/(?P<tirage_id>\d+)$",
|
||||
views.UnpaidParticipants.as_view(),
|
||||
name="bda-unpaid",
|
||||
),
|
||||
url(
|
||||
r"^spectacles/autocomplete$",
|
||||
views.spectacle_autocomplete,
|
||||
|
|
24
bda/views.py
24
bda/views.py
|
@ -41,7 +41,7 @@ from bda.models import (
|
|||
SpectacleRevente,
|
||||
Tirage,
|
||||
)
|
||||
from gestioncof.decorators import buro_required, cof_required
|
||||
from gestioncof.decorators import BuroRequiredMixin, buro_required, cof_required
|
||||
from utils.views.autocomplete import Select2QuerySetView
|
||||
|
||||
|
||||
|
@ -378,7 +378,7 @@ def revente_manage(request, tirage_id):
|
|||
- Annulation d'une revente après que le tirage a eu lieu
|
||||
"""
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
participant, created = Participant.objects.get_or_create(
|
||||
participant, created = Participant.objects_paid.get_or_create(
|
||||
user=request.user, tirage=tirage
|
||||
)
|
||||
|
||||
|
@ -695,12 +695,13 @@ def spectacle(request, tirage_id, spectacle_id):
|
|||
"username": participant.user.username,
|
||||
"email": participant.user.email,
|
||||
"given": int(attrib.given),
|
||||
"paid": participant.paid,
|
||||
"paid": True,
|
||||
"nb_places": 1,
|
||||
}
|
||||
if participant.id in participants:
|
||||
participants[participant.id]["nb_places"] += 1
|
||||
participants[participant.id]["given"] += attrib.given
|
||||
participants[participant.id]["paid"] &= attrib.paid
|
||||
else:
|
||||
participants[participant.id] = participant_info
|
||||
|
||||
|
@ -728,15 +729,14 @@ class SpectacleListView(ListView):
|
|||
return context
|
||||
|
||||
|
||||
@buro_required
|
||||
def unpaid(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
unpaid = (
|
||||
tirage.participant_set.annotate(nb_attributions=Count("attribution"))
|
||||
.filter(paid=False, nb_attributions__gt=0)
|
||||
.select_related("user")
|
||||
)
|
||||
return render(request, "bda-unpaid.html", {"unpaid": unpaid})
|
||||
class UnpaidParticipants(BuroRequiredMixin, ListView):
|
||||
context_object_name = "unpaid"
|
||||
template_name = "bda-unpaid.html"
|
||||
|
||||
def get_queryset(self):
|
||||
return Participant.objects_paid.filter(
|
||||
tirage__id=self.kwargs["tirage_id"], paid=False
|
||||
).select_related("user")
|
||||
|
||||
|
||||
@buro_required
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from functools import wraps
|
||||
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import render
|
||||
|
||||
|
@ -53,3 +54,19 @@ def buro_required(view_func):
|
|||
return render(request, "buro-denied.html", status=403)
|
||||
|
||||
return login_required(_wrapped_view)
|
||||
|
||||
|
||||
class CofRequiredMixin(PermissionRequiredMixin):
|
||||
def has_permission(self):
|
||||
try:
|
||||
return self.request.user.profile.is_cof
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
|
||||
class BuroRequiredMixin(PermissionRequiredMixin):
|
||||
def has_permission(self):
|
||||
try:
|
||||
return self.request.user.profile.is_buro
|
||||
except AttributeError:
|
||||
return False
|
||||
|
|
Loading…
Reference in a new issue