clubs: remove moderator and club from mailing form + display not moderated mailings

This commit is contained in:
2019-05-09 17:43:47 +02:00
parent 1d07195881
commit d1fb9cc4c3
5 changed files with 70 additions and 44 deletions

View File

@ -88,7 +88,7 @@ class MailingForm(forms.Form):
)
# Include fields for handling mailing creation
mailing_fields = ("email", "club", "moderator")
mailing_fields = ("email",)
self.fields.update(forms.fields_for_model(Mailing, fields=mailing_fields))
for field in mailing_fields:
self.fields["mailing_" + field] = self.fields.pop(field)
@ -103,17 +103,10 @@ class MailingForm(forms.Form):
self.fields["subscription_" + field] = self.fields.pop(field)
self.fields["subscription_" + field].required = False
self.fields["mailing_club"].queryset = Club.objects.filter(id=club_id)
self.fields["mailing_club"].initial = club_id
self.fields["mailing_club"].widget = forms.HiddenInput()
self.fields["subscription_mailing"].queryset = Mailing.objects.filter(
club__id=club_id, is_moderated=True
)
self.fields["mailing_moderator"].queryset = User.objects.filter(id=user_id)
self.fields["mailing_moderator"].initial = user_id
self.fields["mailing_moderator"].widget = forms.HiddenInput()
def check_required(self, cleaned_data, field):
"""
If the given field doesn't exist or has no value, add a required error on it
@ -150,8 +143,8 @@ class MailingForm(forms.Form):
if cleaned_data["action"] == self.ACTION_NEW_MAILING:
self.check_required(cleaned_data, "mailing_email")
self.check_required(cleaned_data, "mailing_club")
self.check_required(cleaned_data, "mailing_moderator")
# self.check_required(cleaned_data, "mailing_club")
# self.check_required(cleaned_data, "mailing_moderator")
if cleaned_data["action"] == self.ACTION_NEW_SUBSCRIPTION:
self.check_required(cleaned_data, "subscription_mailing")