forked from DGNum/gestioCOF
gestion des erreurs et des messages associés
This commit is contained in:
parent
c7c5b5b40f
commit
574aaad745
2 changed files with 27 additions and 5 deletions
|
@ -2,6 +2,9 @@
|
|||
|
||||
{% block realcontent %}
|
||||
<h2>{{ spectacle }}</h2>
|
||||
{% for message in messages %}
|
||||
<h3>{{ message }}</h3>
|
||||
{% endfor %}
|
||||
<table class='etat-bda' align="center">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -36,7 +39,7 @@
|
|||
{% csrf_token %}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><input type="text" name="clipper" size=8></td>
|
||||
<td><input type="text" name="username" size=8></td>
|
||||
<td><select name="nb_places">
|
||||
<option value=1>1 place</option>
|
||||
<option value=2>2 places</option>
|
||||
|
|
27
bda/views.py
27
bda/views.py
|
@ -14,6 +14,7 @@ from django.utils import timezone
|
|||
from django.views.generic.list import ListView
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib import messages
|
||||
|
||||
from datetime import timedelta
|
||||
import time
|
||||
|
@ -319,13 +320,31 @@ def spectacle(request, tirage_id, spectacle_id):
|
|||
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)
|
||||
# TODO : erreur
|
||||
part= tirage.participant_set.get(user__username=request.POST['clipper'])
|
||||
attrib = Attribution(participant=part, spectacle=spectacle, given=request.POST['given'])
|
||||
try:
|
||||
part=tirage.participant_set.get(user__username=request.POST['username'])
|
||||
except Participant.DoesNotExist:
|
||||
messages.add_message(request, messages.ERROR,
|
||||
u"Erreur : utilisateur %s non trouvé" % request.POST['username'])
|
||||
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()
|
||||
if request.POST['nb_places']==2:
|
||||
attrib.save()
|
||||
return HttpResponseRedirect(reverse('bda-spectacle', args=(tirage_id, spectacle_id,)))
|
||||
messages.add_message(request, messages.SUCCESS,
|
||||
"Attribution réussie !")
|
||||
return HttpResponseRedirect(reverse('bda-spectacle',
|
||||
args=(tirage_id, spectacle_id,)))
|
||||
|
||||
class SpectacleListView(ListView):
|
||||
model = Spectacle
|
||||
|
|
Loading…
Reference in a new issue