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, None,
{"fields": ("username", "password", "status", "verification_type")}, {"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", "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", "Permissions",
{ {
@ -654,6 +654,7 @@ class MyUserAdmin(BaseUserAdmin, ImportExportModelAdmin):
"middle_name", "middle_name",
"last_name", "last_name",
"title", "title",
"phone",
"email", "email",
"Permissions", "Permissions",
"is_active", "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.contact import Contact
from registrar.models.user import User from registrar.models.user import User
from registrar.models.utility.domain_helper import DomainHelper
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -110,15 +111,22 @@ class Command(BaseCommand):
{TerminalColors.ENDC}""", # noqa {TerminalColors.ENDC}""", # noqa
) )
# ---- UPDATE THE USER IF IT DOES NOT HAVE A FIRST AND LAST NAMES
# ---- LET'S KEEP A LIGHT TOUCH # Get the fields that exist on both User and Contact. Excludes id.
if not eligible_user.first_name and not eligible_user.last_name: common_fields = DomainHelper.get_common_fields(User, Contact)
# (expression has type "str | None", variable has type "str | int | Combinable") if "email" in common_fields:
# so we'll ignore type # Don't change the email field.
eligible_user.first_name = contact.first_name # type: ignore common_fields.remove("email")
eligible_user.last_name = contact.last_name # type: ignore
eligible_user.save() for field in common_fields:
processed_user = eligible_user # 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
return ( return (
eligible_user, eligible_user,