Management view only deals with Revente objects

Except for Revente creation, every form is now handled with revente
objects, to use the display option in the previous commit.
This commit is contained in:
Ludovic Stephan 2017-12-19 12:41:50 +01:00
parent f1bbade002
commit 1783196a9c
4 changed files with 37 additions and 37 deletions

View file

@ -91,7 +91,8 @@ class ResellForm(forms.Form):
class AnnulForm(forms.Form): class AnnulForm(forms.Form):
attributions = AttributionModelMultipleChoiceField( reventes = ReventeModelMultipleChoiceField(
own=True,
label='', label='',
queryset=Attribution.objects.none(), queryset=Attribution.objects.none(),
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
@ -99,14 +100,13 @@ class AnnulForm(forms.Form):
def __init__(self, participant, *args, **kwargs): def __init__(self, participant, *args, **kwargs):
super(AnnulForm, self).__init__(*args, **kwargs) super(AnnulForm, self).__init__(*args, **kwargs)
self.fields['attributions'].queryset = ( self.fields['reventes'].queryset = (
participant.attribution_set participant.original_shows
.filter(spectacle__date__gte=timezone.now(), .filter(attribution__spectacle__date__gte=timezone.now(),
revente__isnull=False, notif_sent=False,
revente__notif_sent=False, soldTo__isnull=True)
revente__soldTo__isnull=True) .select_related('attribution__spectacle',
.select_related('spectacle', 'spectacle__location', 'attribution__spectacle__location')
'participant__user')
) )
@ -165,18 +165,18 @@ class ReventeTirageForm(forms.Form):
class SoldForm(forms.Form): class SoldForm(forms.Form):
attributions = AttributionModelMultipleChoiceField( reventes = ReventeModelMultipleChoiceField(
own=True,
label='', label='',
queryset=Attribution.objects.none(), queryset=Attribution.objects.none(),
widget=forms.CheckboxSelectMultiple) widget=forms.CheckboxSelectMultiple)
def __init__(self, participant, *args, **kwargs): def __init__(self, participant, *args, **kwargs):
super(SoldForm, self).__init__(*args, **kwargs) super(SoldForm, self).__init__(*args, **kwargs)
self.fields['attributions'].queryset = ( self.fields['reventes'].queryset = (
participant.attribution_set participant.original_shows
.filter(revente__isnull=False, .filter(soldTo__isnull=False)
revente__soldTo__isnull=False) .exclude(soldTo=participant)
.exclude(revente__soldTo=participant) .select_related('attribution__spectacle',
.select_related('spectacle', 'spectacle__location', 'attribution__spectacle__location')
'participant__user')
) )

View file

@ -4,7 +4,7 @@
{% block realcontent %} {% block realcontent %}
<h2>Gestion des places que je revends</h2> <h2>Gestion des places que je revends</h2>
{% with resell_attributions=resellform.attributions annul_attributions=annulform.attributions sold_attributions=soldform.attributions %} {% with resell_attributions=resellform.attributions annul_reventes=annulform.reventes sold_reventes=soldform.reventes %}
{% if resellform.attributions %} {% if resellform.attributions %}
<br /> <br />
@ -29,10 +29,10 @@
<hr /> <hr />
{% endif %} {% endif %}
{% if annul_attributions or overdue %} {% if annul_reventes or overdue %}
<h3>Places en cours de revente</h3> <h3>Places en cours de revente</h3>
<form action="" method="post"> <form action="" method="post">
{% if annul_attributions %} {% if annul_reventes %}
<div class="bg-info text-info center-block"> <div class="bg-info text-info center-block">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
Vous pouvez annuler les places mises en vente il y a moins d'une heure. Vous pouvez annuler les places mises en vente il y a moins d'une heure.
@ -42,8 +42,8 @@
<div class='form-group'> <div class='form-group'>
<div class='multiple-checkbox'> <div class='multiple-checkbox'>
<ul> <ul>
{% for attrib in annul_attributions %} {% for revente in annul_reventes %}
<li>{{ attrib.tag }} {{ attrib.choice_label }}</li> <li>{{ revente.tag }} {{ revente.choice_label }}</li>
{% endfor %} {% endfor %}
{% for attrib in overdue %} {% for attrib in overdue %}
<li> <li>
@ -54,7 +54,7 @@
</ul> </ul>
</div> </div>
</div> </div>
{% if annul_attributions %} {% if annul_reventes %}
<input type="submit" class="btn btn-primary" name="annul" value="Annuler les reventes sélectionnées"> <input type="submit" class="btn btn-primary" name="annul" value="Annuler les reventes sélectionnées">
{% endif %} {% endif %}
</form> </form>
@ -62,7 +62,7 @@
<hr /> <hr />
{% endif %} {% endif %}
{% if sold_attributions %} {% if sold_reventes %}
<h3>Places revendues</h3> <h3>Places revendues</h3>
<form action="" method="post"> <form action="" method="post">
<div class="bg-info text-info center-block"> <div class="bg-info text-info center-block">
@ -82,7 +82,7 @@
<button type="submit" class="btn btn-primary" name="reinit">Réinitialiser</button> <button type="submit" class="btn btn-primary" name="reinit">Réinitialiser</button>
</form> </form>
{% endif %} {% endif %}
{% if not resell_attributions and not annul_attributions and not overdue and not sold_attributions %} {% if not resell_attributions and not annul_attributions and not overdue and not sold_reventes %}
<p>Plus de reventes possibles !</p> <p>Plus de reventes possibles !</p>
{% endif %} {% endif %}

View file

@ -11,7 +11,7 @@
<div class="bg-info text-info center-block"> <div class="bg-info text-info center-block">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
Vous pouvez vous désinscrire des reventes suivantes tant que le tirage n'a Vous pouvez vous désinscrire des reventes suivantes tant que le tirage n'a
pas eu lieu pas eu lieu.
</div> </div>
<div class="bootstrap-form-reduce"> <div class="bootstrap-form-reduce">
{% csrf_token %} {% csrf_token %}
@ -34,7 +34,7 @@
<form class="form-horizontal" action="" method="post"> <form class="form-horizontal" action="" method="post">
<div class="bg-info text-info center-block"> <div class="bg-info text-info center-block">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
Vous pouvez vous inscrire aux tirage en cours suivants Vous pouvez vous inscrire aux tirage en cours suivants.
</div> </div>
<div class="bootstrap-form-reduce"> <div class="bootstrap-form-reduce">
{% csrf_token %} {% csrf_token %}

View file

@ -401,18 +401,18 @@ def revente_manage(request, tirage_id):
elif 'annul' in request.POST: elif 'annul' in request.POST:
annulform = AnnulForm(participant, request.POST, prefix='annul') annulform = AnnulForm(participant, request.POST, prefix='annul')
if annulform.is_valid(): if annulform.is_valid():
attributions = annulform.cleaned_data["attributions"] reventes = annulform.cleaned_data["reventes"]
for attribution in attributions: for revente in reventes:
attribution.revente.delete() revente.delete()
# On confirme une vente en transférant la place à la personne qui a # On confirme une vente en transférant la place à la personne qui a
# gagné le tirage # gagné le tirage
elif 'transfer' in request.POST: elif 'transfer' in request.POST:
soldform = SoldForm(participant, request.POST, prefix='sold') soldform = SoldForm(participant, request.POST, prefix='sold')
if soldform.is_valid(): if soldform.is_valid():
attributions = soldform.cleaned_data['attributions'] reventes = soldform.cleaned_data['reventes']
for attribution in attributions: for reventes in reventes:
attribution.participant = attribution.revente.soldTo revente.attribution.participant = revente.soldTo
attribution.save() revente.attribution.save()
# On annule la revente après le tirage au sort (par exemple si # On annule la revente après le tirage au sort (par exemple si
# la personne qui a gagné le tirage ne se manifeste pas). La place est # la personne qui a gagné le tirage ne se manifeste pas). La place est
@ -420,9 +420,9 @@ def revente_manage(request, tirage_id):
elif 'reinit' in request.POST: elif 'reinit' in request.POST:
soldform = SoldForm(participant, request.POST, prefix='sold') soldform = SoldForm(participant, request.POST, prefix='sold')
if soldform.is_valid(): if soldform.is_valid():
attributions = soldform.cleaned_data['attributions'] reventes = soldform.cleaned_data['reventes']
for attribution in attributions: for revente in reventes:
if attribution.spectacle.date > timezone.now(): if revente.attribution.spectacle.date > timezone.now():
# On antidate pour envoyer le mail plus vite # On antidate pour envoyer le mail plus vite
new_date = (timezone.now() new_date = (timezone.now()
- SpectacleRevente.remorse_time) - SpectacleRevente.remorse_time)