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,
|
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",
|
||||||
|
|
|
@ -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,13 +111,20 @@ 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
|
|
||||||
|
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()
|
eligible_user.save()
|
||||||
processed_user = eligible_user
|
processed_user = eligible_user
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue