clubs: set club_id and user_id as mandatory arguments for MailingForm

This commit is contained in:
Antoine Bartuccio 2019-05-01 18:59:41 +02:00
parent da25480993
commit 24fb714c5e
Signed by: klmp200
GPG Key ID: E7245548C53F904B

View File

@ -61,9 +61,7 @@ class MailingForm(forms.Form):
required=False, required=False,
) )
def __init__(self, *args, **kwargs): def __init__(self, club_id, user_id, *args, **kwargs):
club_id = kwargs.pop("club_id", None)
user_id = kwargs.pop("user_id", -1) # Remember 0 is treated as None
super(MailingForm, self).__init__(*args, **kwargs) super(MailingForm, self).__init__(*args, **kwargs)
self.fields["action"] = forms.TypedChoiceField( self.fields["action"] = forms.TypedChoiceField(
@ -94,14 +92,13 @@ class MailingForm(forms.Form):
self.fields["subscription_" + field] = self.fields.pop(field) self.fields["subscription_" + field] = self.fields.pop(field)
self.fields["subscription_" + field].required = False self.fields["subscription_" + field].required = False
if club_id:
self.fields["mailing_club"].queryset = Club.objects.filter(id=club_id) self.fields["mailing_club"].queryset = Club.objects.filter(id=club_id)
self.fields["mailing_club"].initial = club_id self.fields["mailing_club"].initial = club_id
self.fields["mailing_club"].widget = forms.HiddenInput() self.fields["mailing_club"].widget = forms.HiddenInput()
self.fields["subscription_mailing"].queryset = Mailing.objects.filter( self.fields["subscription_mailing"].queryset = Mailing.objects.filter(
club__id=club_id, is_moderated=True club__id=club_id, is_moderated=True
) )
if user_id >= 0:
self.fields["mailing_moderator"].queryset = User.objects.filter(id=user_id) self.fields["mailing_moderator"].queryset = User.objects.filter(id=user_id)
self.fields["mailing_moderator"].initial = user_id self.fields["mailing_moderator"].initial = user_id
self.fields["mailing_moderator"].widget = forms.HiddenInput() self.fields["mailing_moderator"].widget = forms.HiddenInput()