forked from DGNum/gestioCOF
use forms
This commit is contained in:
parent
90581af528
commit
d12a21d44c
4 changed files with 21 additions and 44 deletions
13
bda/forms.py
13
bda/forms.py
|
@ -6,7 +6,8 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms.models import BaseInlineFormSet
|
from django.forms.models import BaseInlineFormSet
|
||||||
from bda.models import Spectacle
|
from django.utils import timezone
|
||||||
|
from bda.models import Attribution
|
||||||
|
|
||||||
|
|
||||||
class BaseBdaFormSet(BaseInlineFormSet):
|
class BaseBdaFormSet(BaseInlineFormSet):
|
||||||
|
@ -42,10 +43,12 @@ class SpectacleModelChoiceField(forms.ModelChoiceField):
|
||||||
|
|
||||||
|
|
||||||
class ResellForm(forms.Form):
|
class ResellForm(forms.Form):
|
||||||
count = forms.ChoiceField(choices=(("1", "1"), ("2", "2"),))
|
attributions = forms.ModelMultipleChoiceField(
|
||||||
spectacle = SpectacleModelChoiceField(queryset=Spectacle.objects.none())
|
queryset=Attribution.objects.none(),
|
||||||
|
widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
def __init__(self, participant, *args, **kwargs):
|
def __init__(self, participant, *args, **kwargs):
|
||||||
super(ResellForm, self).__init__(*args, **kwargs)
|
super(ResellForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['spectacle'].queryset = participant.attributions.all() \
|
self.fields['attributions'].queryset = participant.attribution_set\
|
||||||
.distinct()
|
.filter(spectacle__date__gte=timezone.now(),
|
||||||
|
revente__isnull=True)
|
||||||
|
|
|
@ -193,7 +193,7 @@ class SpectacleRevente(models.Model):
|
||||||
default=timezone.now)
|
default=timezone.now)
|
||||||
interested = models.ManyToManyField(Participant,
|
interested = models.ManyToManyField(Participant,
|
||||||
related_name="wanted",
|
related_name="wanted",
|
||||||
blank=True, null=True)
|
blank=True)
|
||||||
soldTo = models.ForeignKey(Participant, blank=True, null=True)
|
soldTo = models.ForeignKey(Participant, blank=True, null=True)
|
||||||
|
|
||||||
def get_expiration_time(self):
|
def get_expiration_time(self):
|
||||||
|
|
|
@ -4,30 +4,10 @@
|
||||||
{% block realcontent %}
|
{% block realcontent %}
|
||||||
|
|
||||||
<h1>Revente de place</h1>
|
<h1>Revente de place</h1>
|
||||||
{% if no_resell %}
|
|
||||||
<h2>Places non revendues</h2>
|
<h2>Places non revendues</h2>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<ol>
|
{{form}}
|
||||||
{% for attribution in no_resell %}
|
|
||||||
<li>{{attribution.spectacle}} <input type="checkbox" name="resell" value="{{attribution.id}}"></li>
|
|
||||||
{% endfor %}
|
|
||||||
</ol>
|
|
||||||
<input type="submit" value="Revendre les places sélectionnées">
|
<input type="submit" value="Revendre les places sélectionnées">
|
||||||
</form>
|
</form>
|
||||||
{%endif%}
|
|
||||||
{% if resell %}
|
|
||||||
<h2>Places en cours de revente</h2>
|
|
||||||
<form action="" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<ol>
|
|
||||||
{% for attribution in resell %}
|
|
||||||
<form action="" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="annul" value="{{attribution.id}}">
|
|
||||||
<li>{{attribution.spectacle}} {% if attribution.revente.cancellable %}<input type="submit" value="Supprimer">{%endif%}</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ol>
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
24
bda/views.py
24
bda/views.py
|
@ -26,7 +26,7 @@ from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
|
||||||
Tirage, render_template, SpectacleRevente
|
Tirage, render_template, SpectacleRevente
|
||||||
from bda.algorithm import Algorithm
|
from bda.algorithm import Algorithm
|
||||||
|
|
||||||
from bda.forms import BaseBdaFormSet, TokenForm
|
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm
|
||||||
|
|
||||||
|
|
||||||
@cof_required
|
@cof_required
|
||||||
|
@ -303,23 +303,17 @@ def revente(request, tirage_id):
|
||||||
user=request.user, tirage=tirage)
|
user=request.user, tirage=tirage)
|
||||||
if not participant.paid:
|
if not participant.paid:
|
||||||
return render(request, "bda-notpaid.html", {})
|
return render(request, "bda-notpaid.html", {})
|
||||||
if request.POST:
|
if request.method == 'POST':
|
||||||
for attr_id in request.POST.getlist('resell'):
|
form = ResellForm(participant, request.POST)
|
||||||
attribution = Attribution.objects.get(id=int(attr_id))
|
if form.is_valid():
|
||||||
|
attributions = form.cleaned_data["attributions"]
|
||||||
|
for attribution in attributions:
|
||||||
revente = SpectacleRevente(attribution=attribution)
|
revente = SpectacleRevente(attribution=attribution)
|
||||||
revente.save()
|
revente.save()
|
||||||
if 'annul' in request.POST:
|
else:
|
||||||
revente = SpectacleRevente.objects\
|
form = ResellForm(participant)
|
||||||
.get(attribution__pk=request.POST['annul'])
|
|
||||||
revente.delete()
|
|
||||||
|
|
||||||
attributions = participant.attribution_set.filter(
|
|
||||||
spectacle__date__gte=timezone.now)
|
|
||||||
resell = attributions.filter(revente__isnull=False)
|
|
||||||
no_resell = attributions.filter(revente__isnull=True)
|
|
||||||
return render(request, "bda-revente.html",
|
return render(request, "bda-revente.html",
|
||||||
{"participant": participant, 'tirage': tirage,
|
{'tirage': tirage, "form": form})
|
||||||
"resell": resell, "no_resell": no_resell})
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in a new issue