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 %}
|
{% block realcontent %}
|
||||||
<h2>{{ spectacle }}</h2>
|
<h2>{{ spectacle }}</h2>
|
||||||
{% for message in messages %}
|
{% for message in messages %}
|
||||||
<h3>{{ message }}</h3>
|
<h2 class="{{message.tags}}" align="center">{{ message }}</h2>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<table class='etat-bda' align="center">
|
<table class='etat-bda' align="center">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -18,8 +18,13 @@
|
||||||
</thead>
|
</thead>
|
||||||
{% for participant in participants %}
|
{% for participant in participants %}
|
||||||
<tr>
|
<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.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.nb_places}} place{{participant.nb_places|pluralize}}</td>
|
||||||
<td>{{participant.email}}</td>
|
<td>{{participant.email}}</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -28,11 +33,18 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
<div class={%if participant.given %}"greenratio"{%else%}"redratio"{%endif%}>
|
<div class={%if participant.given == participant.nb_places %}"greenratio"
|
||||||
{% if participant.given %}Oui{% else %}Non{%endif%}
|
{%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>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
<td id="bda-part-button"><input type="submit" value="Supprimer"></td>
|
||||||
|
</form>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<form action="{% url 'bda-add-attrib' spectacle.tirage.id spectacle.id %}" method="POST">
|
<form action="{% url 'bda-add-attrib' spectacle.tirage.id spectacle.id %}" method="POST">
|
||||||
|
@ -48,7 +60,7 @@
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td align="center"><input type="checkbox" name="given"></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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -35,4 +35,7 @@ urlpatterns = patterns('',
|
||||||
url(r'spectacles/add-attrib/(?P<tirage_id>\d+)/(?P<spectacle_id>\d+)$',
|
url(r'spectacles/add-attrib/(?P<tirage_id>\d+)/(?P<spectacle_id>\d+)$',
|
||||||
'bda.views.add_attrib',
|
'bda.views.add_attrib',
|
||||||
name='bda-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'),
|
||||||
)
|
)
|
||||||
|
|
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.http import HttpResponseRedirect
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import time
|
import time
|
||||||
|
@ -303,11 +304,12 @@ def spectacle(request, tirage_id, spectacle_id):
|
||||||
'name': participant.user.get_full_name,
|
'name': participant.user.get_full_name,
|
||||||
'username':participant.user.username,
|
'username':participant.user.username,
|
||||||
'email':participant.user.email,
|
'email':participant.user.email,
|
||||||
'given':attrib.given,
|
'given':int(attrib.given),
|
||||||
'paid':participant.paid,
|
'paid':participant.paid,
|
||||||
'nb_places':1}
|
'nb_places':1}
|
||||||
if participant.id in participants:
|
if participant.id in participants:
|
||||||
participants[participant.id]['nb_places'] = 2
|
participants[participant.id]['nb_places'] += 1
|
||||||
|
participants[participant.id]['given'] += attrib.given
|
||||||
else:
|
else:
|
||||||
participants[participant.id] = participant_info
|
participants[participant.id] = participant_info
|
||||||
|
|
||||||
|
@ -317,9 +319,10 @@ def spectacle(request, tirage_id, spectacle_id):
|
||||||
{"spectacle": spectacle, "participants": participants_info})
|
{"spectacle": spectacle, "participants": participants_info})
|
||||||
|
|
||||||
@buro_required
|
@buro_required
|
||||||
|
@require_POST
|
||||||
def add_attrib(request, tirage_id, spectacle_id):
|
def add_attrib(request, tirage_id, spectacle_id):
|
||||||
tirage = get_object_or_404(Tirage, id=tirage_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:
|
try:
|
||||||
part=tirage.participant_set.get(user__username=request.POST['username'])
|
part=tirage.participant_set.get(user__username=request.POST['username'])
|
||||||
except Participant.DoesNotExist:
|
except Participant.DoesNotExist:
|
||||||
|
@ -328,14 +331,6 @@ def add_attrib(request, tirage_id, spectacle_id):
|
||||||
return HttpResponseRedirect(reverse('bda-spectacle',
|
return HttpResponseRedirect(reverse('bda-spectacle',
|
||||||
args=(tirage_id, spectacle_id,)))
|
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,
|
attrib = Attribution(participant=part, spectacle=spectacle,
|
||||||
given=('given' in request.POST))
|
given=('given' in request.POST))
|
||||||
attrib.save()
|
attrib.save()
|
||||||
|
@ -346,6 +341,20 @@ def add_attrib(request, tirage_id, spectacle_id):
|
||||||
return HttpResponseRedirect(reverse('bda-spectacle',
|
return HttpResponseRedirect(reverse('bda-spectacle',
|
||||||
args=(tirage_id, spectacle_id,)))
|
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):
|
class SpectacleListView(ListView):
|
||||||
model = Spectacle
|
model = Spectacle
|
||||||
template_name = 'spectacle_list.html'
|
template_name = 'spectacle_list.html'
|
||||||
|
|
|
@ -601,6 +601,11 @@ pre code {
|
||||||
|
|
||||||
.etat-bda tr:nth-child(even) {background: #CCC}
|
.etat-bda tr:nth-child(even) {background: #CCC}
|
||||||
|
|
||||||
|
#bda-part-button {
|
||||||
|
border:none;
|
||||||
|
background-color:#eee
|
||||||
|
}
|
||||||
|
|
||||||
.greenratio {
|
.greenratio {
|
||||||
background-color: #3F3;
|
background-color: #3F3;
|
||||||
border: 5px solid #ccc;
|
border: 5px solid #ccc;
|
||||||
|
|
Loading…
Reference in a new issue