From d6d9a08e63f2e8bfcd997eab396c65dc3b7a2918 Mon Sep 17 00:00:00 2001 From: Angel Velasquez Date: Fri, 17 Sep 2010 17:35:24 -0300 Subject: Adding changing of user profile details The idea of this patch is allow to the developers who have an account, to change their data without asking some admin to do it for them. Dan: put private email address field back as it is used for a different purpose; add some help text and field names as appropriate. Signed-off-by: Angel Velasquez Signed-off-by: Dan McGee --- devel/views.py | 16 +++++++++++++--- main/models.py | 5 +++-- templates/devel/profile.html | 9 ++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/devel/views.py b/devel/views.py index 577a00c..381b4a4 100644 --- a/devel/views.py +++ b/devel/views.py @@ -52,7 +52,8 @@ def change_notify(request): return HttpResponseRedirect('/devel/') class ProfileForm(forms.Form): - email = forms.EmailField(label='E-mail Address') + email = forms.EmailField(label='Private email (not shown publicly):', + help_text="Used for out of date notifications, etc.") passwd1 = forms.CharField(label='New Password', required=False, widget=forms.PasswordInput) passwd2 = forms.CharField(label='Confirm Password', required=False, @@ -63,20 +64,29 @@ 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(): + profile_form = UserProfileForm(data=request.POST, instance=request.user.get_profile()) + if form.is_valid() and profile_form.is_valid(): request.user.email = form.cleaned_data['email'] 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}) + profile_form = UserProfileForm(instance=request.user.get_profile()) + return direct_to_template(request, 'devel/profile.html', + {'form': form, 'profile_form': profile_form}) class NewUserForm(forms.ModelForm): class Meta: diff --git a/main/models.py b/main/models.py index 10a7737..dc700fb 100644 --- a/main/models.py +++ b/main/models.py @@ -19,14 +19,15 @@ class UserProfile(models.Model): help_text="Required field") other_contact = models.CharField(max_length=100, null=True, blank=True) website = models.CharField(max_length=200, null=True, blank=True) - yob = models.IntegerField(null=True, blank=True) + yob = models.IntegerField("Year of birth", null=True, blank=True) location = models.CharField(max_length=50, null=True, blank=True) languages = models.CharField(max_length=50, null=True, blank=True) interests = models.CharField(max_length=255, null=True, blank=True) occupation = models.CharField(max_length=50, null=True, blank=True) roles = models.CharField(max_length=255, null=True, blank=True) favorite_distros = models.CharField(max_length=255, null=True, blank=True) - picture = models.FileField(upload_to='devs', default='devs/silhouette.png') + picture = models.FileField(upload_to='devs', default='devs/silhouette.png', + help_text="Ideally 125px by 125px") user = models.OneToOneField(User, related_name='userprofile') allowed_repos = models.ManyToManyField('Repo', blank=True) class Meta: diff --git a/templates/devel/profile.html b/templates/devel/profile.html index 0dde934..4da6dad 100644 --- a/templates/devel/profile.html +++ b/templates/devel/profile.html @@ -7,10 +7,17 @@

Developer Profile

{% csrf_token %} +

Note: This is the public information shown on the developer + and/or TU profiles page, so please be appropriate with the information + you provide here.

- Username: {{ user.username }} +

+ {{ user.username }}

{{ form.as_p }}
+
+ {{ profile_form.as_p }} +

-- cgit v1.2.3-24-g4f1b