diff options
author | Dusty Phillips <buchuki@gmail.com> | 2008-09-16 21:12:26 -0400 |
---|---|---|
committer | Dusty Phillips <buchuki@gmail.com> | 2008-09-16 21:12:26 -0400 |
commit | 851e6d55be41b1053d5fdb7326aa0846638992fc (patch) | |
tree | cf3c2250064395ec39e659f669b2c5c34a9a01c7 | |
parent | 765c6c0cd08973f6cebb007aeff38e82c84e058d (diff) |
port profile_form to newforms
-rw-r--r-- | devel/views.py | 40 | ||||
-rw-r--r-- | templates/devel/profile.html | 19 |
2 files changed, 29 insertions, 30 deletions
diff --git a/devel/views.py b/devel/views.py index cecfe1a1..1c89ab00 100644 --- a/devel/views.py +++ b/devel/views.py @@ -1,7 +1,7 @@ +from django import forms from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.models import User -from django.core import validators -from archweb_dev.main.utils import render_response, validate +from archweb_dev.main.utils import render_response from archweb_dev.main.models import Package, Todolist, TodolistPkg from archweb_dev.main.models import Arch, Repo from archweb_dev.main.models import UserProfile, News, Donor, Mirror @@ -62,23 +62,33 @@ def change_notify(request): maint.get_profile().save() return HttpResponseRedirect('/devel/') +class ProfileForm(forms.Form): + email = forms.EmailField('E-mail Address') + passwd1 = forms.CharField('New Password', required=False, + widget=forms.PasswordInput) + passwd2 = forms.CharField('Confirm Password', required=False, + widget=forms.PasswordInput) + + def clean(self): + if ('passwd1' not in self.cleaned_data and + 'passwd2' not in self.cleaned_data): + return self.cleaned_data + + if self.cleaned_data['passwd1'] != self.cleaned_data['passwd2']: + raise forms.ValidationError('Passwords do not match') + return self.cleaned_data + def change_profile(request): - errors = {} if request.POST: - passwd1, passwd2 = request.POST['passwd'], request.POST['passwd2'] - email = request.POST['email'] - # validate - if passwd1 != passwd2: - errors['password'] = [' Passwords do not match. '] - validate(errors, 'Email', email, validators.isValidEmail, False, request) - # apply changes - if not errors: - request.user.email = email - if passwd1: - request.user.set_password(passwd1) + form = ProfileForm(request.POST) + if form.is_valid(): + request.user.email = form.cleaned_data['email'] + request.user.set_password(form.cleaned_data['passwd1']) request.user.save() return HttpResponseRedirect('/devel/') - return render_response(request, 'devel/profile.html', {'errors':errors,'email':request.user.email}) + else: + form = ProfileForm(initial={'email': request.user.email}) + return render_response(request, 'devel/profile.html', {'form': form}) def siteindex(request): # get the most recent 10 news items diff --git a/templates/devel/profile.html b/templates/devel/profile.html index 60837356..5b5a586b 100644 --- a/templates/devel/profile.html +++ b/templates/devel/profile.html @@ -1,27 +1,16 @@ -{% load validation %} {% extends "base.html" %} {% block content %} <div class="greybox"> <h2 class="title">Developer Profile</h2> - {% if errors %} - {% print_errors errors %} - {% endif %} <form method="post" action="."> <table> <tr> - <td>Username:</td> + <th>Username:</th> <td><strong>{{ user.username }}</strong></td> - </tr><tr> - <td>Email Address:</td> - <td><input type="text" name="email" value="{{ user.email }}" size="30"></td> - </tr><tr> - <td>New Password:</td> - <td><input type="password" name="passwd" size="30"></td> - </tr><tr> - <td>Confirm Password:</td> - <td><input type="password" name="passwd2" size="30"></td> - </tr><tr> + </tr> + {{form}} + <tr> <td colspan="2" align="right"> <input type="submit" value=" Save "> </td> |