diff --git a/club/models.py b/club/models.py index e8018fd4..7c05faa5 100644 --- a/club/models.py +++ b/club/models.py @@ -232,7 +232,7 @@ class Mailing(models.Model): email = models.EmailField(_('Email address'), unique=True) def clean(self): - if '@' + settings.SITH_MAILING_ALLOWED_DOMAIN not in self.email: + if '@' + settings.SITH_MAILING_DOMAIN not in self.email: raise ValidationError(_('Unothorized mailing domain')) super(Mailing, self).clean() diff --git a/club/views.py b/club/views.py index 0f3bc29a..f0f967ff 100644 --- a/club/views.py +++ b/club/views.py @@ -36,6 +36,7 @@ from django.utils.translation import ugettext as _t from ajax_select.fields import AutoCompleteSelectField from django.core.exceptions import PermissionDenied from django.shortcuts import get_object_or_404 +from django.core.validators import RegexValidator, validate_email from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin from core.views.forms import SelectDate, SelectDateTime @@ -53,6 +54,16 @@ class MailingForm(forms.ModelForm): model = Mailing fields = ('email', 'club') + email = forms.CharField( + label=_('Email address'), + validators=[ + RegexValidator( + validate_email.user_regex, + _('Enter a valid address. Only the root of the address is needed.') + ) + ], + required=True) + def __init__(self, *args, **kwargs): club_id = kwargs.pop('club_id', None) super(MailingForm, self).__init__(*args, **kwargs) @@ -61,6 +72,12 @@ class MailingForm(forms.ModelForm): self.fields['club'].initial = club_id self.fields['club'].widget = forms.HiddenInput() + def clean(self): + cleaned_data = super(MailingForm, self).clean() + if self.is_valid(): + cleaned_data['email'] += '@' + settings.SITH_MAILING_DOMAIN + return cleaned_data + class MailingSubscriptionForm(forms.ModelForm): class Meta: diff --git a/sith/settings.py b/sith/settings.py index 0e3c7a1f..574b1492 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -562,7 +562,7 @@ SITH_QUICK_NOTIF = { # Mailing related settings -SITH_MAILING_ALLOWED_DOMAIN = 'utbm.fr' +SITH_MAILING_DOMAIN = 'utbm.fr' SITH_MAILING_FETCH_KEY = 'IloveMails' try: