Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 153 lines (128 sloc) 5.457 kB
0068a44 This revision of django-profile will be compatible with django rev. […
david.rubert authored
1 from django import forms
34f1cf1 Initial import. A lot of work must be done.
david.rubert authored
2 from django.core.exceptions import ObjectDoesNotExist
ba3bb03 Lot of simplifications. 0.6 version is really near.
david.rubert authored
3 from django.core.exceptions import ImproperlyConfigured
4 from django.db import models
9aa8b9c Avatar changes almost done.
david.rubert authored
5 from django.utils.translation import ugettext as _
ba3bb03 Lot of simplifications. 0.6 version is really near.
david.rubert authored
6 from django.conf import settings
23fd263 Changes...
david.rubert authored
7 from django.contrib.auth.models import User
6371fa9 Lot of code removed. The account password management code is used dir…
david.rubert authored
8 from userprofile.models import EmailValidation
88b0437 Adapted to the new forms API and newforms-admin
david.rubert authored
9 from django.core.files.uploadedfile import SimpleUploadedFile
10 import mimetypes, urllib
34f1cf1 Initial import. A lot of work must be done.
david.rubert authored
11
ba3bb03 Lot of simplifications. 0.6 version is really near.
david.rubert authored
12 if not settings.AUTH_PROFILE_MODULE:
13 raise SiteProfileNotAvailable
14 try:
15 app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
16 Profile = models.get_model(app_label, model_name)
17 except (ImportError, ImproperlyConfigured):
18 raise SiteProfileNotAvailable
19
8585080 Most work done
david.rubert authored
20 class LocationForm(forms.ModelForm):
21 """
ba3bb03 Lot of simplifications. 0.6 version is really near.
david.rubert authored
22 Profile location form
8585080 Most work done
david.rubert authored
23 """
24
25 class Meta:
26 model = Profile
27 fields = ('location', 'latitude', 'longitude', 'country')
28
1988ef6 lot of changes
david.rubert authored
29 class ProfileForm(forms.ModelForm):
dfb4bc3 More changes...
david.rubert authored
30 """
31 Profile Form. Composed by all the Profile model fields.
32 """
1988ef6 lot of changes
david.rubert authored
33 class Meta:
34 model = Profile
ba3bb03 Lot of simplifications. 0.6 version is really near.
david.rubert authored
35 exclude = ('date', 'location', 'latitude', 'longitude', 'country',
341cfbf Removed "site" from the personal data form
david.rubert authored
36 'user', 'public', 'site')
ba3bb03 Lot of simplifications. 0.6 version is really near.
david.rubert authored
37
38 class PublicFieldsForm(forms.ModelForm):
39 """
40 Public Fields of the Profile Form. Composed by all the Profile model fields.
41 """
42 class Meta:
43 model = Profile
44 exclude = ('date', 'user', 'public')
34f1cf1 Initial import. A lot of work must be done.
david.rubert authored
45
46 class AvatarForm(forms.Form):
dfb4bc3 More changes...
david.rubert authored
47 """
48 The avatar form requires only one image field.
49 """
8585080 Most work done
david.rubert authored
50 photo = forms.ImageField(required=False)
a4dd2ca Lot of changes. Does not work for the moment
david.rubert authored
51 url = forms.URLField(required=False)
52
88b0437 Adapted to the new forms API and newforms-admin
david.rubert authored
53 def clean_url(self):
54 url = self.cleaned_data.get('url')
55 if not url: return ''
56 filename, headers = urllib.urlretrieve(url)
57 if not mimetypes.guess_all_extensions(headers.get('Content-Type')):
58 raise forms.ValidationError(_('The file type is invalid: %s' % type))
59 return SimpleUploadedFile(filename, open(filename).read(), content_type=headers.get('Content-Type'))
60
a4dd2ca Lot of changes. Does not work for the moment
david.rubert authored
61 def clean(self):
8585080 Most work done
david.rubert authored
62 if not (self.cleaned_data.get('photo') or self.cleaned_data.get('url')):
a4dd2ca Lot of changes. Does not work for the moment
david.rubert authored
63 raise forms.ValidationError(_('You must enter one of the options'))
88b0437 Adapted to the new forms API and newforms-admin
david.rubert authored
64 return self.cleaned_data
9aa8b9c Avatar changes almost done.
david.rubert authored
65
a751a72 New crop&resize method
david.rubert authored
66 class AvatarCropForm(forms.Form):
67 """
68 Crop dimensions form
69 """
70 top = forms.IntegerField()
71 bottom = forms.IntegerField()
72 left = forms.IntegerField()
73 right = forms.IntegerField()
74
93daa25 Some bugs solved
david.rubert authored
75 def clean(self):
76 if int(self.cleaned_data.get('right')) - int(self.cleaned_data.get('left')) < 96:
77 raise forms.ValidationError(_("You must select a portion of the image with a minimum of 96x96 pixels."))
1c1f0a5 Buf, a bug detected
david.rubert authored
78 else:
79 return self.cleaned_data
93daa25 Some bugs solved
david.rubert authored
80
8250819 Lot of HTML cleanup. Blueprint CSS is great.
david.rubert authored
81 class RegistrationForm(forms.Form):
23fd263 Changes...
david.rubert authored
82
c543bb3 Solved some issues with error reporting on forms. Thanks to Jonas.
david.rubert authored
83 username = forms.CharField(max_length=255, min_length = 3, label=_("Username"))
58d0ab0 Added an optional configuration directive: REQUIRE_EMAIL_CONFIRMATION…
david.rubert authored
84 email = forms.EmailField(required=hasattr(settings, "REQUIRE_EMAIL_CONFIRMATION") and settings.REQUIRE_EMAIL_CONFIRMATION or False, label=_("E-mail address"))
c128dcb Unified the user registration password requirements with django.contr…
david.rubert authored
85 password1 = forms.CharField(widget=forms.PasswordInput, label=_("Password"))
86 password2 = forms.CharField(widget=forms.PasswordInput, label=_("Password (again)"))
23fd263 Changes...
david.rubert authored
87
88 def clean_username(self):
89 """
90 Verify that the username isn't already registered
91 """
92 username = self.cleaned_data.get("username")
93 if not set(username).issubset("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"):
94 raise forms.ValidationError(_("That username has invalid characters. The valid values are letters, numbers and underscore."))
95
96 if User.objects.filter(username__iexact=username).count() == 0:
97 return username
98 else:
99 raise forms.ValidationError(_("The username is already registered."))
100
101 def clean(self):
102 """
103 Verify that the 2 passwords fields are equal
104 """
105 if self.cleaned_data.get("password1") == self.cleaned_data.get("password2"):
106 return self.cleaned_data
107 else:
108 raise forms.ValidationError(_("The passwords inserted are different."))
109
110 def clean_email(self):
111 """
112 Verify that the email exists
113 """
114 email = self.cleaned_data.get("email")
115
116 if not email: return email
117
118 try:
119 User.objects.get(email=email)
120 raise forms.ValidationError(_("That e-mail is already used."))
4e6a6d5 At least. Working version
david.rubert authored
121 except User.DoesNotExist:
122 try:
6371fa9 Lot of code removed. The account password management code is used dir…
david.rubert authored
123 EmailValidation.objects.get(email=email)
4e6a6d5 At least. Working version
david.rubert authored
124 raise forms.ValidationError(_("That e-mail is already being confirmed."))
6371fa9 Lot of code removed. The account password management code is used dir…
david.rubert authored
125 except EmailValidation.DoesNotExist:
4e6a6d5 At least. Working version
david.rubert authored
126 return email
23fd263 Changes...
david.rubert authored
127
c505dfa Almost working
david.rubert authored
128 class EmailValidationForm(forms.Form):
23fd263 Changes...
david.rubert authored
129 email = forms.EmailField()
130
131 def clean_email(self):
132 """
133 Verify that the email exists
134 """
135 email = self.cleaned_data.get("email")
6371fa9 Lot of code removed. The account password management code is used dir…
david.rubert authored
136 if not (User.objects.filter(email=email) or EmailValidation.objects.filter(email=email)):
23fd263 Changes...
david.rubert authored
137 return email
138
139 raise forms.ValidationError(_("That e-mail is already used."))
067de8e EMAIL_VALIDATION_REQUIRED process almost done.
david.rubert authored
140
141 class ResendEmailValidationForm(forms.Form):
142 email = forms.EmailField()
143
144 def clean_email(self):
145 """
146 Verify that the email exists
147 """
148 email = self.cleaned_data.get("email")
149 if User.objects.filter(email=email) or EmailValidation.objects.filter(email=email):
150 return email
151
152 raise forms.ValidationError(_("That e-mail isn't registered."))
Something went wrong with that request. Please try again.