forked from DGNum/gestioCOF
Merge branch 'master' into Kerl/drop_py2_compat
This commit is contained in:
commit
a73736bf41
84 changed files with 10296 additions and 486 deletions
103
bda/forms.py
103
bda/forms.py
|
@ -2,7 +2,7 @@ from django import forms
|
|||
from django.forms.models import BaseInlineFormSet
|
||||
from django.utils import timezone
|
||||
|
||||
from bda.models import Attribution, Spectacle
|
||||
from bda.models import Attribution, Spectacle, SpectacleRevente
|
||||
|
||||
|
||||
class InscriptionInlineFormSet(BaseInlineFormSet):
|
||||
|
@ -41,7 +41,33 @@ class TokenForm(forms.Form):
|
|||
|
||||
class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
||||
def label_from_instance(self, obj):
|
||||
return "%s" % str(obj.spectacle)
|
||||
return str(obj.spectacle)
|
||||
|
||||
|
||||
class ReventeModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
||||
def __init__(self, *args, own=True, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.own = own
|
||||
|
||||
def label_from_instance(self, obj):
|
||||
label = "{show}{suffix}"
|
||||
suffix = ""
|
||||
if self.own:
|
||||
# C'est notre propre revente : pas besoin de spécifier le vendeur
|
||||
if obj.soldTo is not None:
|
||||
suffix = " -- Vendue à {firstname} {lastname}".format(
|
||||
firstname=obj.soldTo.user.first_name,
|
||||
lastname=obj.soldTo.user.last_name,
|
||||
)
|
||||
else:
|
||||
# Ce n'est pas à nous : on ne voit jamais l'acheteur
|
||||
suffix = " -- Vendue par {firstname} {lastname}".format(
|
||||
firstname=obj.seller.user.first_name,
|
||||
lastname=obj.seller.user.last_name,
|
||||
)
|
||||
|
||||
return label.format(show=str(obj.attribution.spectacle),
|
||||
suffix=suffix)
|
||||
|
||||
|
||||
class ResellForm(forms.Form):
|
||||
|
@ -63,7 +89,8 @@ class ResellForm(forms.Form):
|
|||
|
||||
|
||||
class AnnulForm(forms.Form):
|
||||
attributions = AttributionModelMultipleChoiceField(
|
||||
reventes = ReventeModelMultipleChoiceField(
|
||||
own=True,
|
||||
label='',
|
||||
queryset=Attribution.objects.none(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
|
@ -71,14 +98,13 @@ class AnnulForm(forms.Form):
|
|||
|
||||
def __init__(self, participant, *args, **kwargs):
|
||||
super(AnnulForm, self).__init__(*args, **kwargs)
|
||||
self.fields['attributions'].queryset = (
|
||||
participant.attribution_set
|
||||
.filter(spectacle__date__gte=timezone.now(),
|
||||
revente__isnull=False,
|
||||
revente__notif_sent=False,
|
||||
revente__soldTo__isnull=True)
|
||||
.select_related('spectacle', 'spectacle__location',
|
||||
'participant__user')
|
||||
self.fields['reventes'].queryset = (
|
||||
participant.original_shows
|
||||
.filter(attribution__spectacle__date__gte=timezone.now(),
|
||||
notif_sent=False,
|
||||
soldTo__isnull=True)
|
||||
.select_related('attribution__spectacle',
|
||||
'attribution__spectacle__location')
|
||||
)
|
||||
|
||||
|
||||
|
@ -97,19 +123,58 @@ class InscriptionReventeForm(forms.Form):
|
|||
)
|
||||
|
||||
|
||||
class ReventeTirageAnnulForm(forms.Form):
|
||||
reventes = ReventeModelMultipleChoiceField(
|
||||
own=False,
|
||||
label='',
|
||||
queryset=SpectacleRevente.objects.none(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
required=False
|
||||
)
|
||||
|
||||
def __init__(self, participant, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['reventes'].queryset = (
|
||||
participant.entered.filter(soldTo__isnull=True)
|
||||
.select_related('attribution__spectacle',
|
||||
'seller__user')
|
||||
)
|
||||
|
||||
|
||||
class ReventeTirageForm(forms.Form):
|
||||
reventes = ReventeModelMultipleChoiceField(
|
||||
own=False,
|
||||
label='',
|
||||
queryset=SpectacleRevente.objects.none(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
required=False
|
||||
)
|
||||
|
||||
def __init__(self, participant, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['reventes'].queryset = (
|
||||
SpectacleRevente.objects.filter(
|
||||
notif_sent=True,
|
||||
shotgun=False,
|
||||
tirage_done=False
|
||||
).exclude(confirmed_entry=participant)
|
||||
.select_related('attribution__spectacle')
|
||||
)
|
||||
|
||||
|
||||
class SoldForm(forms.Form):
|
||||
attributions = AttributionModelMultipleChoiceField(
|
||||
reventes = ReventeModelMultipleChoiceField(
|
||||
own=True,
|
||||
label='',
|
||||
queryset=Attribution.objects.none(),
|
||||
widget=forms.CheckboxSelectMultiple)
|
||||
|
||||
def __init__(self, participant, *args, **kwargs):
|
||||
super(SoldForm, self).__init__(*args, **kwargs)
|
||||
self.fields['attributions'].queryset = (
|
||||
participant.attribution_set
|
||||
.filter(revente__isnull=False,
|
||||
revente__soldTo__isnull=False)
|
||||
.exclude(revente__soldTo=participant)
|
||||
.select_related('spectacle', 'spectacle__location',
|
||||
'participant__user')
|
||||
self.fields['reventes'].queryset = (
|
||||
participant.original_shows
|
||||
.filter(soldTo__isnull=False)
|
||||
.exclude(soldTo=participant)
|
||||
.select_related('attribution__spectacle',
|
||||
'attribution__spectacle__location')
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue