Exemple #1
0
 def test_valid_form_with_optionals(self):
     form = ProfileChangeForm(data = {
         'email': '*****@*****.**',
         'first_name': 'john',
         'last_name': 'doe'
     })
     self.assertTrue(form.is_valid())
Exemple #2
0
def update_profile(request):
    """View for updating User profile."""
    context = gen_alerts(request)
    form = ProfileChangeForm()

    # updates the User profile in the database.
    if request.method == 'POST':
        form = ProfileChangeForm(request.POST)
        if form.is_valid():
            user = request.user
            if (form.cleaned_data['email']):
                user.email = form.cleaned_data['email']
            if (form.cleaned_data['first_name']):
                user.first_name = form.cleaned_data['first_name']
            if (form.cleaned_data['last_name']):
                user.last_name = form.cleaned_data['last_name']
            user.save()
            request.session['notify'] = "Successfully Updated Profile!"
            return HttpResponseRedirect(reverse('profile'))

    context['form'] = form
    return render(request, 'profile_change.html', context)
Exemple #3
0
 def test_valid_form_one_optional(self):
     form = ProfileChangeForm(data = {
         'email': '*****@*****.**'
     })
     self.assertTrue(form.is_valid())