forked from DGNum/gestioCOF
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:
parent
a30955fb75
commit
519ef9dc20
1 changed files with 38 additions and 45 deletions
83
bda/forms.py
83
bda/forms.py
|
@ -90,24 +90,20 @@ class ResellForm(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):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["reventes"].queryset = (
|
||||
participant.original_shows.filter(
|
||||
self.fields["reventes"] = ReventeModelMultipleChoiceField(
|
||||
own=True,
|
||||
label="",
|
||||
queryset=participant.original_shows.filter(
|
||||
attribution__spectacle__date__gte=timezone.now(), soldTo__isnull=True
|
||||
)
|
||||
.select_related(
|
||||
"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):
|
||||
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):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["spectacles"].queryset = tirage.spectacle_set.select_related(
|
||||
"location"
|
||||
).filter(date__gte=timezone.now())
|
||||
self.fields["spectacles"] = TemplateLabelField(
|
||||
queryset=tirage.spectacle_set.select_related("location").filter(
|
||||
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):
|
||||
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):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["reventes"].queryset = participant.entered.filter(
|
||||
soldTo__isnull=True
|
||||
).select_related("attribution__spectacle", "seller__user")
|
||||
self.fields["reventes"] = TemplateLabelField(
|
||||
queryset=participant.entered.filter(soldTo__isnull=True).select_related(
|
||||
"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):
|
||||
|
@ -196,19 +192,16 @@ class ReventeTirageForm(forms.Form):
|
|||
|
||||
|
||||
class SoldForm(forms.Form):
|
||||
reventes = ReventeModelMultipleChoiceField(
|
||||
own=True,
|
||||
label="",
|
||||
queryset=Attribution.objects.none(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
)
|
||||
|
||||
def __init__(self, participant, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["reventes"].queryset = (
|
||||
participant.original_shows.filter(soldTo__isnull=False)
|
||||
self.fields["reventes"].queryset = ReventeModelMultipleChoiceField(
|
||||
own=True,
|
||||
label="",
|
||||
queryset=participant.original_shows.filter(soldTo__isnull=False)
|
||||
.exclude(soldTo=participant)
|
||||
.select_related(
|
||||
"attribution__spectacle", "attribution__spectacle__location"
|
||||
)
|
||||
),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue