Skip to content

Commit

Permalink
🥅 newsletter import: show error message when no email template is found
Browse files Browse the repository at this point in the history
  • Loading branch information
krmax44 authored and stefanw committed Feb 24, 2025
1 parent 3ff6738 commit d52f49d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion fragdenstaat_de/fds_newsletter/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from django import forms
from django.conf import settings
from django.forms import ModelForm
from django.forms import ModelForm, ValidationError
from django.utils.translation import gettext_lazy as _

from froide.helper.spam import SpamProtectionMixin
from froide.helper.widgets import BootstrapCheckboxSelectMultiple, BootstrapRadioSelect

from fragdenstaat_de.fds_mailing.models import EmailTemplate

from .models import Newsletter, Subscriber, UnsubscribeFeedback
from .utils import import_csv, subscribe, subscribed_newsletters

Expand Down Expand Up @@ -154,6 +156,24 @@ class SubscriberImportForm(forms.Form):
label=_("Email addresses are confirmed"), required=False
)

def clean_email_confirmed(self):
email_confirmed = self.cleaned_data["email_confirmed"]

if not email_confirmed:
try:
EmailTemplate.objects.get(
mail_intent="fds_newsletter/email/subscriber_batch_confirm",
active=True,
)
except (EmailTemplate.DoesNotExist, EmailTemplate.MultipleObjectsReturned):
raise ValidationError(
_(
"Make sure there exists one active mailing template for the batch confirm intent (fds_newsletter/email/subscriber_batch_confirm)."
)
) from None

return email_confirmed

def save(self, newsletter):
csv_file = self.cleaned_data["csv_file"]
csv_file = StringIO(csv_file.read().decode("utf-8"))
Expand Down

0 comments on commit d52f49d

Please sign in to comment.