diff options
author | Angel Velasquez <angvp@archlinux.org> | 2010-09-17 17:35:24 -0300 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-10-05 15:11:50 -0500 |
commit | d6d9a08e63f2e8bfcd997eab396c65dc3b7a2918 (patch) | |
tree | 3ac7692af8757ec52d9fd159217b801ef8e3c948 | |
parent | d66d0e4300052933a6bfaa016114dc6a68708905 (diff) |
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 <angvp@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | devel/views.py | 16 | ||||
-rw-r--r-- | main/models.py | 5 | ||||
-rw-r--r-- | templates/devel/profile.html | 9 |
3 files changed, 24 insertions, 6 deletions
diff --git a/devel/views.py b/devel/views.py index 577a00c4..381b4a4a 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 10a77379..dc700fbf 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 0dde9349..4da6dad1 100644 --- a/templates/devel/profile.html +++ b/templates/devel/profile.html @@ -7,10 +7,17 @@ <h2>Developer Profile</h2> <form id="edit-profile-form" method="post">{% csrf_token %} + <p><em>Note:</em> This is the public information shown on the developer + and/or TU profiles page, so please be appropriate with the information + you provide here.</p> <fieldset> - <legend>Username: <strong>{{ user.username }}</strong></legend> + <p><label>Username:</label> + <strong>{{ user.username }}</strong></p> {{ form.as_p }} </fieldset> + <fieldset> + {{ profile_form.as_p }} + </fieldset> <p><label></label> <input title="Save changes" type="submit" value="Save" /></p> </form> |