Fix concurrency issues

Creating form fields in the class and modifiying them dynamically can
cause concurrency issues because the form class is shared between tabs.
This commit is contained in:
Ludovic Stephan 2019-01-07 14:59:20 +01:00
parent a30955fb75
commit 519ef9dc20

View file

@ -90,24 +90,20 @@ class ResellForm(forms.Form):
class AnnulForm(forms.Form): class AnnulForm(forms.Form):
reventes = ReventeModelMultipleChoiceField(
own=True,
label="",
queryset=Attribution.objects.none(),
widget=forms.CheckboxSelectMultiple,
required=False,
)
def __init__(self, participant, *args, **kwargs): def __init__(self, participant, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields["reventes"].queryset = ( self.fields["reventes"] = ReventeModelMultipleChoiceField(
participant.original_shows.filter( own=True,
label="",
queryset=participant.original_shows.filter(
attribution__spectacle__date__gte=timezone.now(), soldTo__isnull=True attribution__spectacle__date__gte=timezone.now(), soldTo__isnull=True
) )
.select_related( .select_related(
"attribution__spectacle", "attribution__spectacle__location" "attribution__spectacle", "attribution__spectacle__location"
) )
.order_by("-date") .order_by("-date"),
widget=forms.CheckboxSelectMultiple,
required=False,
) )
@ -142,37 +138,37 @@ class TemplateLabelField(forms.ModelMultipleChoiceField):
class InscriptionReventeForm(forms.Form): class InscriptionReventeForm(forms.Form):
spectacles = TemplateLabelField(
queryset=Spectacle.objects.none(),
widget=forms.CheckboxSelectMultiple,
required=False,
label_template_name="bda/forms/spectacle_label_table.html",
option_template_name="bda/forms/checkbox_table.html",
context_object_name="spectacle",
)
def __init__(self, tirage, *args, **kwargs): def __init__(self, tirage, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields["spectacles"].queryset = tirage.spectacle_set.select_related( self.fields["spectacles"] = TemplateLabelField(
"location" queryset=tirage.spectacle_set.select_related("location").filter(
).filter(date__gte=timezone.now()) date__gte=timezone.now()
),
widget=forms.CheckboxSelectMultiple,
required=False,
label_template_name="bda/forms/spectacle_label_table.html",
option_template_name="bda/forms/checkbox_table.html",
context_object_name="spectacle",
)
class ReventeTirageAnnulForm(forms.Form): class ReventeTirageAnnulForm(forms.Form):
reventes = TemplateLabelField(
queryset=SpectacleRevente.objects.none(),
widget=forms.CheckboxSelectMultiple,
required=False,
label_template_name="bda/forms/revente_other_label_table.html",
option_template_name="bda/forms/checkbox_table.html",
context_object_name="revente",
)
def __init__(self, participant, *args, **kwargs): def __init__(self, participant, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields["reventes"].queryset = participant.entered.filter( self.fields["reventes"] = TemplateLabelField(
soldTo__isnull=True queryset=participant.entered.filter(soldTo__isnull=True).select_related(
).select_related("attribution__spectacle", "seller__user") "attribution__spectacle", "seller__user"
),
widget=forms.CheckboxSelectMultiple,
required=False,
label_template_name="bda/forms/revente_other_label_table.html",
option_template_name="bda/forms/checkbox_table.html",
context_object_name="revente",
)
participant.entered.filter(soldTo__isnull=True).select_related(
"attribution__spectacle", "seller__user"
)
class ReventeTirageForm(forms.Form): class ReventeTirageForm(forms.Form):
@ -196,19 +192,16 @@ class ReventeTirageForm(forms.Form):
class SoldForm(forms.Form): class SoldForm(forms.Form):
reventes = ReventeModelMultipleChoiceField(
own=True,
label="",
queryset=Attribution.objects.none(),
widget=forms.CheckboxSelectMultiple,
)
def __init__(self, participant, *args, **kwargs): def __init__(self, participant, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields["reventes"].queryset = ( self.fields["reventes"].queryset = ReventeModelMultipleChoiceField(
participant.original_shows.filter(soldTo__isnull=False) own=True,
label="",
queryset=participant.original_shows.filter(soldTo__isnull=False)
.exclude(soldTo=participant) .exclude(soldTo=participant)
.select_related( .select_related(
"attribution__spectacle", "attribution__spectacle__location" "attribution__spectacle", "attribution__spectacle__location"
) ),
widget=forms.CheckboxSelectMultiple,
) )