mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 20:09:25 +00:00
clubs: add bulk deletion on mailing lists
This commit is contained in:
@ -53,6 +53,7 @@ class MailingForm(forms.Form):
|
||||
|
||||
ACTION_NEW_MAILING = 1
|
||||
ACTION_NEW_SUBSCRIPTION = 2
|
||||
ACTION_REMOVE_SUBSCRIPTION = 3
|
||||
|
||||
subscription_users = AutoCompleteSelectMultipleField(
|
||||
"users",
|
||||
@ -61,13 +62,14 @@ class MailingForm(forms.Form):
|
||||
required=False,
|
||||
)
|
||||
|
||||
def __init__(self, club_id, user_id, *args, **kwargs):
|
||||
def __init__(self, club_id, user_id, mailings, *args, **kwargs):
|
||||
super(MailingForm, self).__init__(*args, **kwargs)
|
||||
|
||||
self.fields["action"] = forms.TypedChoiceField(
|
||||
(
|
||||
(self.ACTION_NEW_MAILING, _("New Mailing")),
|
||||
(self.ACTION_NEW_SUBSCRIPTION, _("Subscribe")),
|
||||
(self.ACTION_REMOVE_SUBSCRIPTION, _("Remove")),
|
||||
),
|
||||
coerce=int,
|
||||
label=_("Action"),
|
||||
@ -76,6 +78,15 @@ class MailingForm(forms.Form):
|
||||
widget=forms.HiddenInput(),
|
||||
)
|
||||
|
||||
# Generate bulk removal forms, they are never required
|
||||
for mailing in mailings:
|
||||
self.fields["removal_" + str(mailing.id)] = forms.ModelMultipleChoiceField(
|
||||
mailing.subscriptions.all(),
|
||||
label=_("Remove"),
|
||||
required=False,
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
)
|
||||
|
||||
# Include fields for handling mailing creation
|
||||
mailing_fields = ("email", "club", "moderator")
|
||||
self.fields.update(forms.fields_for_model(Mailing, fields=mailing_fields))
|
||||
@ -133,8 +144,6 @@ class MailingForm(forms.Form):
|
||||
def clean(self):
|
||||
cleaned_data = super(MailingForm, self).clean()
|
||||
|
||||
print(cleaned_data)
|
||||
|
||||
if not "action" in cleaned_data:
|
||||
# If there is no action provided, we can stop here
|
||||
raise forms.ValidationError(_("An action is required"), code="invalid")
|
||||
|
Reference in New Issue
Block a user