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
|
@ -3,7 +3,7 @@
|
|||
{% block realcontent %}
|
||||
<h2>{{ spectacle }}</h2>
|
||||
{% for message in messages %}
|
||||
<h3>{{ message }}</h3>
|
||||
<h2 class="{{message.tags}}" align="center">{{ message }}</h2>
|
||||
{% endfor %}
|
||||
<table class='etat-bda' align="center">
|
||||
<thead>
|
||||
|
@ -18,8 +18,13 @@
|
|||
</thead>
|
||||
{% for participant in participants %}
|
||||
<tr>
|
||||
<form action="{% url 'bda-del-attrib' spectacle.tirage.id spectacle.id %}"
|
||||
method="POST"
|
||||
onsubmit="return confirm('Voulez-vous vraiment supprimer cette attribution ?');">
|
||||
{% csrf_token %}
|
||||
<td>{{participant.name}}</td>
|
||||
<td>{{participant.username}}</td>
|
||||
<td>{{participant.username}}
|
||||
<input type="hidden" name="username" value={{participant.username}}></td>
|
||||
<td>{{participant.nb_places}} place{{participant.nb_places|pluralize}}</td>
|
||||
<td>{{participant.email}}</td>
|
||||
<td>
|
||||
|
@ -28,11 +33,18 @@
|
|||
</div>
|
||||
</td>
|
||||
<td align="center">
|
||||
<div class={%if participant.given %}"greenratio"{%else%}"redratio"{%endif%}>
|
||||
{% if participant.given %}Oui{% else %}Non{%endif%}
|
||||
<div class={%if participant.given == participant.nb_places %}"greenratio"
|
||||
{%elif participant.given == 0%}"redratio"
|
||||
{%else%}"orangeratio"
|
||||
{%endif%}>
|
||||
{% if participant.given == participant.nb_places %}Oui
|
||||
{% elif participant.given == 0 %}Non
|
||||
{% else %}{{participant.given}}/{{participant.nb_places}}
|
||||
{%endif%}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td id="bda-part-button"><input type="submit" value="Supprimer"></td>
|
||||
</form>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<form action="{% url 'bda-add-attrib' spectacle.tirage.id spectacle.id %}" method="POST">
|
||||
|
@ -48,7 +60,7 @@
|
|||
<td></td>
|
||||
<td></td>
|
||||
<td align="center"><input type="checkbox" name="given"></td>
|
||||
<td><input type="submit" value="Ajouter"></td>
|
||||
<td align="center" id="bda-part-button"><input type="submit" value="Ajouter"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
|
|
|
@ -35,4 +35,7 @@ urlpatterns = patterns('',
|
|||
url(r'spectacles/add-attrib/(?P<tirage_id>\d+)/(?P<spectacle_id>\d+)$',
|
||||
'bda.views.add_attrib',
|
||||
name='bda-add-attrib'),
|
||||
url(r'spectacles/del-attrib/(?P<tirage_id>\d+)/(?P<spectacle_id>\d+)$',
|
||||
'bda.views.del_attrib',
|
||||
name='bda-del-attrib'),
|
||||
)
|
||||
|
|
29
bda/views.py
29
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,6 +319,7 @@ 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)
|
||||
|
@ -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()
|
||||
|
@ -346,6 +341,20 @@ def add_attrib(request, tirage_id, spectacle_id):
|
|||
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
|
||||
template_name = 'spectacle_list.html'
|
||||
|
|
|
@ -601,6 +601,11 @@ pre code {
|
|||
|
||||
.etat-bda tr:nth-child(even) {background: #CCC}
|
||||
|
||||
#bda-part-button {
|
||||
border:none;
|
||||
background-color:#eee
|
||||
}
|
||||
|
||||
.greenratio {
|
||||
background-color: #3F3;
|
||||
border: 5px solid #ccc;
|
||||
|
|
Loading…
Reference in a new issue