mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 10:59:21 +02:00
Add update
This commit is contained in:
parent
479f47ec66
commit
e70fb3ae6b
2 changed files with 20 additions and 11 deletions
|
@ -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",
|
||||
|
|
|
@ -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,15 +111,22 @@ 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
|
||||
eligible_user.save()
|
||||
processed_user = eligible_user
|
||||
|
||||
# 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
|
||||
|
||||
return (
|
||||
eligible_user,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue