Beispiel #1
0
 def test_valid_form_with_optionals(self):
     form = ProfileChangeForm(data = {
         'email': '*****@*****.**',
         'first_name': 'john',
         'last_name': 'doe'
     })
     self.assertTrue(form.is_valid())
Beispiel #2
0
    def get_profile_form(self):
        form_kwargs = {'instance': self.object.profile}
        if self.request.method == 'POST':
            form_kwargs['data'] = self.request.POST
            form_kwargs['files'] = self.request.FILES

        return ProfileChangeForm(**form_kwargs)
Beispiel #3
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)
Beispiel #4
0
 def test_valid_form_one_optional(self):
     form = ProfileChangeForm(data = {
         'email': '*****@*****.**'
     })
     self.assertTrue(form.is_valid())
Beispiel #5
0
 def test_last_name_help_text(self):
     form = ProfileChangeForm()
     self.assertEqual(form.fields['last_name'].help_text,
         "Enter your last name (optional).")
Beispiel #6
0
 def test_email_field_help_text(self):
     form = ProfileChangeForm()
     self.assertEqual(form.fields['email'].help_text,
         "Enter an email address (optional).")
Beispiel #7
0
 def test_last_name_field_label(self):
     form = ProfileChangeForm()
     self.assertTrue(form.fields['last_name'].label == 'Last Name')
Beispiel #8
0
 def test_email_field_label(self):
     form = ProfileChangeForm()
     self.assertTrue(form.fields['email'].label == 'Email')