forked from DGNum/gestioCOF
Better labels for revente
objects
The label for the ReventeModelMultipleChoiceField now depends on a `own` parameter, which determines if we display the seller or the buyer's name.
This commit is contained in:
parent
dfa8c1a1a1
commit
f1bbade002
1 changed files with 26 additions and 2 deletions
28
bda/forms.py
28
bda/forms.py
|
@ -47,8 +47,29 @@ class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
|||
|
||||
|
||||
class ReventeModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
||||
def __init__(self, *args, own=True, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.own = own
|
||||
|
||||
def label_from_instance(self, obj):
|
||||
return str(obj.attribution.spectacle)
|
||||
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):
|
||||
|
@ -106,6 +127,7 @@ class InscriptionReventeForm(forms.Form):
|
|||
|
||||
class ReventeTirageAnnulForm(forms.Form):
|
||||
reventes = ReventeModelMultipleChoiceField(
|
||||
own=False,
|
||||
label='',
|
||||
queryset=SpectacleRevente.objects.none(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
|
@ -116,12 +138,14 @@ class ReventeTirageAnnulForm(forms.Form):
|
|||
super().__init__(*args, **kwargs)
|
||||
self.fields['reventes'].queryset = (
|
||||
participant.entered.filter(soldTo__isnull=True)
|
||||
.select_related('attribution__spectacle')
|
||||
.select_related('attribution__spectacle',
|
||||
'seller__user')
|
||||
)
|
||||
|
||||
|
||||
class ReventeTirageForm(forms.Form):
|
||||
reventes = ReventeModelMultipleChoiceField(
|
||||
own=False,
|
||||
label='',
|
||||
queryset=SpectacleRevente.objects.none(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
|
|
Loading…
Reference in a new issue