[arch-general] [PATCH 3/3] Adding changing of user profile details
The idea of this patch is allow to the dev's who have an account, to change their data without asking some admin to do it for them. Signed-off-by: Angel Velasquez <angvp@archlinux.org> --- devel/views.py | 16 +++++++++++----- templates/devel/profile.html | 3 +++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/devel/views.py b/devel/views.py index c974806..a2dd0e3 100644 --- a/devel/views.py +++ b/devel/views.py @@ -53,7 +53,6 @@ def change_notify(request): return HttpResponseRedirect('/devel/') class ProfileForm(forms.Form): - email = forms.EmailField(label='E-mail Address') passwd1 = forms.CharField(label='New Password', required=False, widget=forms.PasswordInput) passwd2 = forms.CharField(label='Confirm Password', required=False, @@ -64,20 +63,27 @@ class ProfileForm(forms.Form): raise forms.ValidationError('Passwords do not match.') return self.cleaned_data +class UserProfileForm(forms.ModelForm): + class Meta: + model = UserProfile + exclude = ['allowed_repos', 'user'] + @login_required @never_cache def change_profile(request): if request.POST: form = ProfileForm(request.POST) - if form.is_valid(): - request.user.email = form.cleaned_data['email'] + profile_form = UserProfileForm(data=request.POST, instance=request.user.get_profile()) + if form.is_valid() and profile_form.is_valid(): if form.cleaned_data['passwd1']: request.user.set_password(form.cleaned_data['passwd1']) request.user.save() + profile_form.save() return HttpResponseRedirect('/devel/') else: - form = ProfileForm(initial={'email': request.user.email}) - return direct_to_template(request, 'devel/profile.html', {'form': form}) + form = ProfileForm() + profile_form = UserProfileForm(instance=request.user.get_profile()) + return direct_to_template(request, 'devel/profile.html', {'form': form, 'profile_form': profile_form}) @login_required def mirrorlist(request): diff --git a/templates/devel/profile.html b/templates/devel/profile.html index 0dde934..6e2053f 100644 --- a/templates/devel/profile.html +++ b/templates/devel/profile.html @@ -11,6 +11,9 @@ <legend>Username: <strong>{{ user.username }}</strong></legend> {{ form.as_p }} </fieldset> + <fieldset> + {{ profile_form.as_p }} + </fieldset> <p><label></label> <input title="Save changes" type="submit" value="Save" /></p> </form> -- 1.7.2.3
participants (1)
-
Angel Velasquez