Fewer requests on bda.views.revente

This commit is contained in:
Aurélien Delobelle 2017-04-08 12:10:23 +02:00
parent d31101aff3
commit 3556e3b1b0
2 changed files with 30 additions and 14 deletions

View file

@ -15,7 +15,7 @@ class TokenForm(forms.Form):
class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField): class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj): def label_from_instance(self, obj):
return "%s" % obj.spectacle return "%s" % str(obj.spectacle)
class ResellForm(forms.Form): class ResellForm(forms.Form):
@ -27,9 +27,13 @@ class ResellForm(forms.Form):
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['attributions'].queryset = participant.attribution_set\ self.fields['attributions'].queryset = (
.filter(spectacle__date__gte=timezone.now())\ participant.attribution_set
.filter(spectacle__date__gte=timezone.now())
.exclude(revente__seller=participant) .exclude(revente__seller=participant)
.select_related('spectacle', 'spectacle__location',
'participant__user')
)
class AnnulForm(forms.Form): class AnnulForm(forms.Form):
@ -41,11 +45,15 @@ 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 = participant.attribution_set\ self.fields['attributions'].queryset = (
participant.attribution_set
.filter(spectacle__date__gte=timezone.now(), .filter(spectacle__date__gte=timezone.now(),
revente__isnull=False, revente__isnull=False,
revente__notif_sent=False, revente__notif_sent=False,
revente__soldTo__isnull=True) revente__soldTo__isnull=True)
.select_related('spectacle', 'spectacle__location',
'participant__user')
)
class InscriptionReventeForm(forms.Form): class InscriptionReventeForm(forms.Form):
@ -56,8 +64,11 @@ class InscriptionReventeForm(forms.Form):
def __init__(self, tirage, *args, **kwargs): def __init__(self, tirage, *args, **kwargs):
super(InscriptionReventeForm, self).__init__(*args, **kwargs) super(InscriptionReventeForm, self).__init__(*args, **kwargs)
self.fields['spectacles'].queryset = tirage.spectacle_set.filter( self.fields['spectacles'].queryset = (
date__gte=timezone.now()) tirage.spectacle_set
.select_related('location')
.filter(date__gte=timezone.now())
)
class SoldForm(forms.Form): class SoldForm(forms.Form):
@ -70,7 +81,9 @@ class SoldForm(forms.Form):
super(SoldForm, self).__init__(*args, **kwargs) super(SoldForm, self).__init__(*args, **kwargs)
self.fields['attributions'].queryset = ( self.fields['attributions'].queryset = (
participant.attribution_set participant.attribution_set
.filter(revente__isnull=False, .filter(revente__isnull=False,
revente__soldTo__isnull=False) revente__soldTo__isnull=False)
.exclude(revente__soldTo=participant) .exclude(revente__soldTo=participant)
.select_related('spectacle', 'spectacle__location',
'participant__user')
) )

View file

@ -4,6 +4,8 @@
{% block realcontent %} {% block realcontent %}
<h2>Revente de place</h2> <h2>Revente de place</h2>
{% with resell_attributions=resellform.attributions annul_attributions=annulform.attributions sold_attributions=soldform.attributions %}
{% if resellform.attributions %} {% if resellform.attributions %}
<h3>Places non revendues</h3> <h3>Places non revendues</h3>
<form class="form-horizontal" action="" method="post"> <form class="form-horizontal" action="" method="post">
@ -15,14 +17,14 @@
</form> </form>
{% endif %} {% endif %}
<br> <br>
{% if annulform.attributions or overdue %} {% if annul_attributions or overdue %}
<h3>Places en cours de revente</h3> <h3>Places en cours de revente</h3>
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
<div class='form-group'> <div class='form-group'>
<div class='multiple-checkbox'> <div class='multiple-checkbox'>
<ul> <ul>
{% for attrib in annulform.attributions %} {% for attrib in annul_attributions %}
<li>{{attrib.tag}} {{attrib.choice_label}}</li> <li>{{attrib.tag}} {{attrib.choice_label}}</li>
{% endfor %} {% endfor %}
{% for attrib in overdue %} {% for attrib in overdue %}
@ -31,13 +33,13 @@
{{attrib.spectacle}} {{attrib.spectacle}}
</li> </li>
{% endfor %} {% endfor %}
{% if annulform.attributions %} {% if annul_attributions %}
<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>
{% endif %} {% endif %}
<br> <br>
{% if soldform.attributions %} {% if sold_attributions %}
<h3>Places revendues</h3> <h3>Places revendues</h3>
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
@ -46,8 +48,9 @@
<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 resellform.attributions and not soldform.attributions and not overdue and not annulform.attributions %} {% if not resell_attributions and not annul_attributions and not overdue and not sold_attributions %}
<p>Plus de reventes possibles !</p> <p>Plus de reventes possibles !</p>
{% endif %} {% endif %}
{% endwith %}
{% endblock %} {% endblock %}