Revision ae497612 snf-astakos-app/astakos/im/forms.py

b/snf-astakos-app/astakos/im/forms.py
60 60

  
61 61
from astakos.im.util import reserved_email, get_query
62 62

  
63
import astakos.im.messages as astakos_messages
64

  
63 65
import logging
64 66
import hashlib
65 67
import recaptcha.client.captcha as captcha
......
116 118
    def clean_email(self):
117 119
        email = self.cleaned_data['email']
118 120
        if not email:
119
            raise forms.ValidationError(_("This field is required"))
121
            raise forms.ValidationError(_(astakos_messages.REQUIRED_FIELD))
120 122
        if reserved_email(email):
121
            raise forms.ValidationError(_("This email is already used"))
123
            raise forms.ValidationError(_(astakos_messages.EMAIL_USED))
122 124
        return email
123 125

  
124 126
    def clean_has_signed_terms(self):
125 127
        has_signed_terms = self.cleaned_data['has_signed_terms']
126 128
        if not has_signed_terms:
127
            raise forms.ValidationError(_('You have to agree with the terms'))
129
            raise forms.ValidationError(_(astakos_messages.SIGN_TERMS))
128 130
        return has_signed_terms
129 131

  
130 132
    def clean_recaptcha_response_field(self):
......
142 144
        rrf = self.cleaned_data['recaptcha_response_field']
143 145
        check = captcha.submit(rcf, rrf, RECAPTCHA_PRIVATE_KEY, self.ip)
144 146
        if not check.is_valid:
145
            raise forms.ValidationError(
146
                _('You have not entered the correct words'))
147
            raise forms.ValidationError(_(astakos_messages.CAPTCHA_VALIDATION_ERR))
147 148

  
148 149
    def save(self, commit=True):
149 150
        """
......
222 223
    def clean_email(self):
223 224
        email = self.cleaned_data['email']
224 225
        if not email:
225
            raise forms.ValidationError(_("This field is required"))
226
            raise forms.ValidationError(_(astakos_messages.REQUIRED_FIELD))
226 227
        return email
227 228

  
228 229
    def clean_has_signed_terms(self):
229 230
        has_signed_terms = self.cleaned_data['has_signed_terms']
230 231
        if not has_signed_terms:
231
            raise forms.ValidationError(_('You have to agree with the terms'))
232
            raise forms.ValidationError(_(astakos_messages.SIGN_TERMS))
232 233
        return has_signed_terms
233 234

  
234 235
    def save(self, commit=True):
......
287 288
        email = self.cleaned_data['email']
288 289
        for user in AstakosUser.objects.filter(email=email):
289 290
            if user.provider == 'shibboleth':
290
                raise forms.ValidationError(_("This email is already associated with another shibboleth account."))
291
                raise forms.ValidationError(_(astakos_messages.SHIBBOLETH_EMAIL_USED))
291 292
            elif not user.is_active:
292
                raise forms.ValidationError(_("This email is already associated with an inactive account. \
293
                                              You need to wait to be activated before being able to switch to a shibboleth account."))
293
                raise forms.ValidationError(_(astakos_messages.SHIBBOLETH_INACTIVE_ACC))
294 294
        super(ShibbolethUserCreationForm, self).clean_email()
295 295
        return email
296 296

  
......
343 343
        rrf = self.cleaned_data['recaptcha_response_field']
344 344
        check = captcha.submit(rcf, rrf, RECAPTCHA_PRIVATE_KEY, self.ip)
345 345
        if not check.is_valid:
346
            raise forms.ValidationError(
347
                _('You have not entered the correct words'))
346
            raise forms.ValidationError(_(astakos_messages.CAPTCHA_VALIDATION_ERR))
348 347

  
349 348
    def clean(self):
350 349
        super(LoginForm, self).clean()
351 350
        if self.user_cache and self.user_cache.provider not in ('local', ''):
352
            raise forms.ValidationError(_('Local login is not the current authentication method for this account.'))
351
            raise forms.ValidationError(_(astakos_messages.SUSPENDED_LOCAL_ACC))
353 352
        return self.cleaned_data
354 353

  
355 354

  
......
419 418
        try:
420 419
            user = AstakosUser.objects.get(email=email, is_active=True)
421 420
            if not user.has_usable_password():
422
                raise forms.ValidationError(
423
                    _("This account has not a usable password."))
421
                raise forms.ValidationError(_(astakos_messages.UNUSABLE_PASSWORD))
424 422
        except AstakosUser.DoesNotExist:
425
            raise forms.ValidationError(_('That e-mail address doesn\'t have an associated user account. Are you sure you\'ve registered?'))
423
            raise forms.ValidationError(_(astakos_messages.EMAIL_UNKNOWN))
426 424
        return email
427 425

  
428 426
    def save(
......
460 458
    def clean_new_email_address(self):
461 459
        addr = self.cleaned_data['new_email_address']
462 460
        if AstakosUser.objects.filter(email__iexact=addr):
463
            raise forms.ValidationError(_(u'This email address is already in use. Please supply a different email address.'))
461
            raise forms.ValidationError(_(astakos_messages.EMAIL_USED))
464 462
        return addr
465 463

  
466 464
    def save(self, email_template_name, request, commit=True):
......
485 483
    def clean_has_signed_terms(self):
486 484
        has_signed_terms = self.cleaned_data['has_signed_terms']
487 485
        if not has_signed_terms:
488
            raise forms.ValidationError(_('You have to agree with the terms'))
486
            raise forms.ValidationError(_(astakos_messages.SIGN_TERMS))
489 487
        return has_signed_terms
490 488

  
491 489

  
......
503 501
        username = self.cleaned_data['username']
504 502
        try:
505 503
            Invitation.objects.get(username=username)
506
            raise forms.ValidationError(
507
                _('There is already invitation for this email.'))
504
            raise forms.ValidationError(_(astakos_messages.INVITATION_EMAIL_EXISTS))
508 505
        except Invitation.DoesNotExist:
509 506
            pass
510 507
        return username
......
690 687
class AddGroupMembersForm(forms.Form):
691 688
    q = forms.CharField(
692 689
        max_length=800, widget=forms.Textarea, label=_('Add users'),
693
        help_text=_('Add comma separated user emails, eg. user1@user.com, user2@user.com'),
690
        help_text=_(astakos_messages.ADD_GROUP_MEMBERS_Q_HELP),
694 691
        required=True)
695 692

  
696 693
    def clean(self):
......
700 697
        db_entries = AstakosUser.objects.filter(email__in=users)
701 698
        unknown = list(set(users) - set(u.email for u in db_entries))
702 699
        if unknown:
703
            raise forms.ValidationError(
704
                _('Unknown users: %s' % ','.join(unknown)))
700
            raise forms.ValidationError(_(astakos_messages.UNKNOWN_USERS) % ','.join(unknown))
705 701
        self.valid_users = db_entries
706 702
        return self.cleaned_data
707 703

  

Also available in: Unified diff