~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlprofile/forms.py

  • Committer: franku
  • Date: 2016-12-13 18:28:51 UTC
  • mto: This revision was merged to the branch mainline in revision 443.
  • Revision ID: somal@arcor.de-20161213182851-bo5ebf8pdvw5beua
run the script

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import settings
13
13
import re
14
14
 
 
15
 
15
16
class EditProfileForm(forms.ModelForm):
16
17
    email = forms.EmailField(required=True)
17
18
 
21
22
                  'aim', 'yahoo', 'signature', 'email', 'show_signatures',
22
23
                  'time_zone', 'time_display', ]
23
24
 
24
 
 
25
25
    def __init__(self, *args, **kwargs):
26
 
        instance = kwargs.pop("instance")
 
26
        instance = kwargs.pop('instance')
27
27
 
28
 
        super(EditProfileForm, self).__init__(instance=instance, *args,**kwargs)
 
28
        super(EditProfileForm, self).__init__(
 
29
            instance=instance, *args, **kwargs)
29
30
 
30
31
        self.fields['email'].initial = instance.user.email
31
32
 
32
33
    def clean_signature(self):
33
34
        value = self.cleaned_data['signature'].strip()
34
35
        if len(re.findall(r'\n', value)) > settings.SIGNATURE_MAX_LINES:
35
 
            raise forms.ValidationError('Number of lines is limited to %d' % settings.SIGNATURE_MAX_LINES)
 
36
            raise forms.ValidationError(
 
37
                'Number of lines is limited to %d' % settings.SIGNATURE_MAX_LINES)
36
38
        if len(value) > settings.SIGNATURE_MAX_LENGTH:
37
 
            raise forms.ValidationError('Length of signature is limited to %d' % settings.SIGNATURE_MAX_LENGTH)
 
39
            raise forms.ValidationError(
 
40
                'Length of signature is limited to %d' % settings.SIGNATURE_MAX_LENGTH)
38
41
        return value
39
42
 
40
43
    def save(self, *args, **kwargs):
44
47
        u.email = self.cleaned_data['email']
45
48
 
46
49
        u.save(*args, **kwargs)
47
 
 
48
 
 
49