equal
deleted
inserted
replaced
40 |
40 |
41 class CreateForm(helper.forms.BaseForm): |
41 class CreateForm(helper.forms.BaseForm): |
42 """Django form displayed when creating a User. |
42 """Django form displayed when creating a User. |
43 """ |
43 """ |
44 |
44 |
45 id = forms.EmailField( |
45 email = forms.EmailField( |
46 label=soc.models.user.User.id.verbose_name, |
46 label=soc.models.user.User.id.verbose_name, |
47 help_text=soc.models.user.User.id.help_text) |
47 help_text=soc.models.user.User.id.help_text) |
48 |
48 |
49 link_name = forms.CharField( |
49 link_name = forms.CharField( |
50 label=soc.models.user.User.link_name.verbose_name, |
50 label=soc.models.user.User.link_name.verbose_name, |
71 if user and user.link_name == link_name: |
71 if user and user.link_name == link_name: |
72 raise forms.ValidationError("This link name is already in use.") |
72 raise forms.ValidationError("This link name is already in use.") |
73 |
73 |
74 return link_name |
74 return link_name |
75 |
75 |
76 def clean_id(self): |
76 def clean_email(self): |
77 form_id = users.User(email=self.cleaned_data.get('id')) |
77 form_id = users.User(email=self.cleaned_data.get('email')) |
78 key_name = self.data.get('key_name') |
78 key_name = self.data.get('key_name') |
79 if key_name: |
79 if key_name: |
80 user = user_logic.logic.getFromKeyName(key_name) |
80 user = user_logic.logic.getFromKeyName(key_name) |
81 old_email = user.id.email() |
81 old_email = user.id.email() |
82 else: |
82 else: |
86 |
86 |
87 if new_email != old_email \ |
87 if new_email != old_email \ |
88 and user_logic.logic.getFromFields(email=new_email): |
88 and user_logic.logic.getFromFields(email=new_email): |
89 raise forms.ValidationError("This account is already in use.") |
89 raise forms.ValidationError("This account is already in use.") |
90 |
90 |
91 return form_id |
91 return self.cleaned_data.get('email') |
92 |
92 |
93 |
93 |
94 class EditForm(CreateForm): |
94 class EditForm(CreateForm): |
95 """Django form displayed when editing a User. |
95 """Django form displayed when editing a User. |
96 """ |
96 """ |
171 keys = self._logic.getKeyFieldNames() |
171 keys = self._logic.getKeyFieldNames() |
172 values = self._logic.getKeyValues(entity) |
172 values = self._logic.getKeyValues(entity) |
173 key_fields = dicts.zip(keys, values) |
173 key_fields = dicts.zip(keys, values) |
174 |
174 |
175 return self.edit(request, page, params=params, **key_fields) |
175 return self.edit(request, page, params=params, **key_fields) |
|
176 |
|
177 def _editGet(self, request, entity, form): |
|
178 """See base.View._editGet(). |
|
179 """ |
|
180 # fill in the email field with the data from the entity |
|
181 form.fields['email'].initial = entity.id.email() |
|
182 |
176 |
183 |
177 def _editPost(self, request, entity, fields): |
184 def _editPost(self, request, entity, fields): |
178 """See base.View._editPost(). |
185 """See base.View._editPost(). |
179 """ |
186 """ |
180 |
187 # fill in the id field with the user created from email |
181 fields['email'] = fields['id'].email() |
188 fields['id'] = users.User(fields['email']) |
182 |
189 |
183 |
190 |
184 view = View() |
191 view = View() |
185 |
192 |
186 create = view.create |
193 create = view.create |