forked from DGNum/gestioCOF
Ajout de formulaires de supression et d'ajout
This commit is contained in:
parent
574aaad745
commit
c36b0c7ef3
4 changed files with 46 additions and 17 deletions
31
bda/views.py
31
bda/views.py
|
@ -15,6 +15,7 @@ from django.views.generic.list import ListView
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib import messages
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from datetime import timedelta
|
||||
import time
|
||||
|
@ -303,11 +304,12 @@ def spectacle(request, tirage_id, spectacle_id):
|
|||
'name': participant.user.get_full_name,
|
||||
'username':participant.user.username,
|
||||
'email':participant.user.email,
|
||||
'given':attrib.given,
|
||||
'given':int(attrib.given),
|
||||
'paid':participant.paid,
|
||||
'nb_places':1}
|
||||
if participant.id in participants:
|
||||
participants[participant.id]['nb_places'] = 2
|
||||
participants[participant.id]['nb_places'] += 1
|
||||
participants[participant.id]['given'] += attrib.given
|
||||
else:
|
||||
participants[participant.id] = participant_info
|
||||
|
||||
|
@ -317,9 +319,10 @@ def spectacle(request, tirage_id, spectacle_id):
|
|||
{"spectacle": spectacle, "participants": participants_info})
|
||||
|
||||
@buro_required
|
||||
@require_POST
|
||||
def add_attrib(request, tirage_id, spectacle_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
spectacle = get_object_or_404(Spectacle, id = spectacle_id, tirage=tirage)
|
||||
spectacle = get_object_or_404(Spectacle, id=spectacle_id, tirage=tirage)
|
||||
try:
|
||||
part=tirage.participant_set.get(user__username=request.POST['username'])
|
||||
except Participant.DoesNotExist:
|
||||
|
@ -328,14 +331,6 @@ def add_attrib(request, tirage_id, spectacle_id):
|
|||
return HttpResponseRedirect(reverse('bda-spectacle',
|
||||
args=(tirage_id, spectacle_id,)))
|
||||
|
||||
places_owned = len(spectacle.attribues.filter(participant=part))
|
||||
|
||||
if int(request.POST['nb_places'])+places_owned > 2:
|
||||
messages.add_message(request, messages.ERROR,
|
||||
"Erreur: on ne peut pas avoir plus de deux places")
|
||||
return HttpResponseRedirect(reverse('bda-spectacle',
|
||||
args=(tirage_id, spectacle_id,)))
|
||||
|
||||
attrib = Attribution(participant=part, spectacle=spectacle,
|
||||
given=('given' in request.POST))
|
||||
attrib.save()
|
||||
|
@ -345,6 +340,20 @@ def add_attrib(request, tirage_id, spectacle_id):
|
|||
"Attribution réussie !")
|
||||
return HttpResponseRedirect(reverse('bda-spectacle',
|
||||
args=(tirage_id, spectacle_id,)))
|
||||
|
||||
@buro_required
|
||||
@require_POST
|
||||
def del_attrib(request, tirage_id, spectacle_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
spectacle = get_object_or_404(Spectacle, id=spectacle_id, tirage=tirage)
|
||||
part = tirage.participant_set.get(user__username=request.POST['username'])
|
||||
spectacle.attribues.filter(participant=part).delete()
|
||||
|
||||
|
||||
messages.add_message(request, messages.SUCCESS,
|
||||
"Attribution(s) supprimée(s) !")
|
||||
return HttpResponseRedirect(reverse('bda-spectacle',
|
||||
args=(tirage_id, spectacle_id,)))
|
||||
|
||||
class SpectacleListView(ListView):
|
||||
model = Spectacle
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue