Пример #1
0
 def test_username_validity(self):
     user = User.objects.get(username='******')
     data = {'username': '******'}
     form = UserChangeForm(data, instance=user)
     self.assertFalse(form.is_valid())
     self.assertEqual(form['username'].errors,
                      [u'This value may contain only letters, numbers and @/./+/-/_ characters.'])
Пример #2
0
def edit(request):
    if request.method == 'POST':
        form = UserChangeForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            messages.success(request, _('Profile details updated.'))
            return HttpResponseRedirect(reverse('shorturl-home') )
        else:
            messages.error(request, _('There was an error when editing your data')) 
    else:
        form = UserChangeForm(instance=request.user)
    return render_to_response('account/edit.html'
                             ,locals()
                             ,context_instance=RequestContext(request))