mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-06 01:35:22 +02:00
Add page for editing UserProfile's display name.
This commit is contained in:
parent
e0b3023520
commit
5c3460782e
5 changed files with 81 additions and 8 deletions
|
@ -8,17 +8,13 @@ from django.conf import settings
|
|||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
||||
from registrar.views import health, index
|
||||
from registrar.views import health, index, profile
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("", index.index),
|
||||
path("health/", health.health),
|
||||
path("edit_profile/", profile.edit_profile, name="edit-profile"),
|
||||
# these views respect the DEBUG setting
|
||||
path("__debug__/", include("debug_toolbar.urls")),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
import debug_toolbar
|
||||
|
||||
urlpatterns = [
|
||||
path("__debug__/", include(debug_toolbar.urls)),
|
||||
] + urlpatterns
|
||||
|
|
10
src/registrar/forms.py
Normal file
10
src/registrar/forms.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django import forms
|
||||
|
||||
from .models import UserProfile
|
||||
|
||||
class EditProfileForm(forms.ModelForm):
|
||||
display_name = forms.CharField(widget=forms.TextInput(attrs={'class': 'usa-input'}), label="Display Name")
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
fields = ['display_name']
|
26
src/registrar/templates/profile.html
Normal file
26
src/registrar/templates/profile.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}
|
||||
Edit your User Profile
|
||||
{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<form class="usa-form usa-form--large" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<fieldset class="usa-fieldset">
|
||||
<legend class="usa-legend usa-legend--large">Your profile</legend>
|
||||
<p>
|
||||
Required fields are marked with an asterisk (<abbr
|
||||
title="required"
|
||||
class="usa-hint usa-hint--required"
|
||||
>*</abbr
|
||||
>).
|
||||
</p>
|
||||
{% for field in profile_form %}
|
||||
<label class="usa-label" for="id_{{ field.name }}">{{ field.label }}</label>
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
<button type="submit" class="usa-button usa-button--big">Save Changes</button>
|
||||
</form>
|
||||
{% endblock content %}
|
|
@ -1,4 +1,7 @@
|
|||
from django.test import Client, TestCase
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from registrar.models import UserProfile
|
||||
|
||||
|
||||
class HealthTest(TestCase):
|
||||
|
@ -9,3 +12,21 @@ class HealthTest(TestCase):
|
|||
response = self.client.get("/health/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "OK")
|
||||
|
||||
|
||||
class LoggedInTests(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
username = "test_user"
|
||||
first_name = "First"
|
||||
last_name = "Last"
|
||||
email = "info@example.com"
|
||||
self.user = get_user_model().objects.create(
|
||||
username=username, first_name=first_name, last_name=last_name, email=email
|
||||
)
|
||||
profile = UserProfile.objects.create(user=self.user)
|
||||
self.client.force_login(self.user)
|
||||
|
||||
def test_edit_profile(self):
|
||||
response = self.client.get("/edit_profile/")
|
||||
self.assertContains(response, "Display Name")
|
||||
|
|
20
src/registrar/views/profile.py
Normal file
20
src/registrar/views/profile.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
from django.shortcuts import redirect, render
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
|
||||
from ..forms import EditProfileForm
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_profile(request):
|
||||
if request.method == "POST":
|
||||
# post to this view when changes are made
|
||||
profile_form = EditProfileForm(request.POST, instance=request.user.userprofile)
|
||||
if profile_form.is_valid():
|
||||
profile_form.save()
|
||||
messages.success(request, 'Your profile is updated successfully')
|
||||
return redirect(to='edit-profile')
|
||||
else:
|
||||
profile_form = EditProfileForm(instance=request.user.userprofile)
|
||||
return render(request, 'profile.html', {'profile_form': profile_form})
|
Loading…
Add table
Add a link
Reference in a new issue