Add update

This commit is contained in:
zandercymatics 2024-05-28 09:51:34 -06:00
parent 479f47ec66
commit e70fb3ae6b
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 20 additions and 11 deletions

View file

@ -594,7 +594,7 @@ class MyUserAdmin(BaseUserAdmin, ImportExportModelAdmin):
None,
{"fields": ("username", "password", "status", "verification_type")},
),
("Personal Info", {"fields": ("first_name", "middle_name", "last_name", "email", "title")}),
("Personal Info", {"fields": ("first_name", "middle_name", "last_name", "email", "phone", "title")}),
(
"Permissions",
{
@ -625,7 +625,7 @@ class MyUserAdmin(BaseUserAdmin, ImportExportModelAdmin):
)
},
),
("Personal Info", {"fields": ("first_name", "middle_name", "last_name", "email", "title")}),
("Personal Info", {"fields": ("first_name", "middle_name", "last_name", "email", "phone", "title")}),
(
"Permissions",
{
@ -654,6 +654,7 @@ class MyUserAdmin(BaseUserAdmin, ImportExportModelAdmin):
"middle_name",
"last_name",
"title",
"phone",
"email",
"Permissions",
"is_active",

View file

@ -10,6 +10,7 @@ from registrar.management.commands.utility.terminal_helper import (
)
from registrar.models.contact import Contact
from registrar.models.user import User
from registrar.models.utility.domain_helper import DomainHelper
logger = logging.getLogger(__name__)
@ -110,13 +111,20 @@ class Command(BaseCommand):
{TerminalColors.ENDC}""", # noqa
)
# ---- UPDATE THE USER IF IT DOES NOT HAVE A FIRST AND LAST NAMES
# ---- LET'S KEEP A LIGHT TOUCH
if not eligible_user.first_name and not eligible_user.last_name:
# (expression has type "str | None", variable has type "str | int | Combinable")
# so we'll ignore type
eligible_user.first_name = contact.first_name # type: ignore
eligible_user.last_name = contact.last_name # type: ignore
# Get the fields that exist on both User and Contact. Excludes id.
common_fields = DomainHelper.get_common_fields(User, Contact)
if "email" in common_fields:
# Don't change the email field.
common_fields.remove("email")
for field in common_fields:
# Grab the value that contact has stored for this field
new_value = getattr(contact, field)
# Set it on the user field
setattr(eligible_user, field, new_value)
eligible_user.save()
processed_user = eligible_user