mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-12 20:49:41 +02:00
lintomatic
This commit is contained in:
parent
2e119c2600
commit
1ccaea5028
2 changed files with 22 additions and 34 deletions
|
@ -43,7 +43,9 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def bulk_create(self):
|
def bulk_create(self):
|
||||||
try:
|
try:
|
||||||
res = ScriptDataHelper.bulk_create_fields(self.model_class, self.create, return_created=True, quiet=True)
|
res = ScriptDataHelper.bulk_create_fields(
|
||||||
|
self.model_class, self.create, return_created=True, quiet=True
|
||||||
|
)
|
||||||
self.create = res
|
self.create = res
|
||||||
return res
|
return res
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -241,9 +243,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
# == Handle managers (no bulk_create) == #
|
# == Handle managers (no bulk_create) == #
|
||||||
if parse_managers:
|
if parse_managers:
|
||||||
domain_infos = DomainInformation.objects.filter(
|
domain_infos = DomainInformation.objects.filter(portfolio__in=portfolios_to_use)
|
||||||
portfolio__in=portfolios_to_use
|
|
||||||
)
|
|
||||||
domains = Domain.objects.filter(domain_info__in=domain_infos)
|
domains = Domain.objects.filter(domain_info__in=domain_infos)
|
||||||
|
|
||||||
# Create UserPortfolioPermission
|
# Create UserPortfolioPermission
|
||||||
|
@ -320,7 +320,8 @@ class Command(BaseCommand):
|
||||||
# Org name must not be null, and must not be the portfolio name
|
# Org name must not be null, and must not be the portfolio name
|
||||||
Q(
|
Q(
|
||||||
organization_name__isnull=False,
|
organization_name__isnull=False,
|
||||||
) & ~Q(organization_name__iexact=F("portfolio__organization_name")),
|
)
|
||||||
|
& ~Q(organization_name__iexact=F("portfolio__organization_name")),
|
||||||
# Only get relevant data to the agency/portfolio we are targeting
|
# Only get relevant data to the agency/portfolio we are targeting
|
||||||
Q(federal_agency__in=agencies) | Q(portfolio__in=portfolios),
|
Q(federal_agency__in=agencies) | Q(portfolio__in=portfolios),
|
||||||
)
|
)
|
||||||
|
@ -328,7 +329,8 @@ class Command(BaseCommand):
|
||||||
# Org name must not be null, and must not be the portfolio name
|
# Org name must not be null, and must not be the portfolio name
|
||||||
Q(
|
Q(
|
||||||
organization_name__isnull=False,
|
organization_name__isnull=False,
|
||||||
) & ~Q(organization_name__iexact=F("portfolio__organization_name")),
|
)
|
||||||
|
& ~Q(organization_name__iexact=F("portfolio__organization_name")),
|
||||||
# Only get relevant data to the agency/portfolio we are targeting
|
# Only get relevant data to the agency/portfolio we are targeting
|
||||||
Q(federal_agency__in=agencies) | Q(portfolio__in=portfolios),
|
Q(federal_agency__in=agencies) | Q(portfolio__in=portfolios),
|
||||||
)
|
)
|
||||||
|
@ -356,7 +358,7 @@ class Command(BaseCommand):
|
||||||
# Don't add the record if the suborg name would equal the portfolio name
|
# Don't add the record if the suborg name would equal the portfolio name
|
||||||
if norm_org_name == portfolio_name:
|
if norm_org_name == portfolio_name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
new_suborg_name = None
|
new_suborg_name = None
|
||||||
if len(domains) == 1:
|
if len(domains) == 1:
|
||||||
new_suborg_name = domains[0].organization_name
|
new_suborg_name = domains[0].organization_name
|
||||||
|
@ -365,7 +367,8 @@ class Command(BaseCommand):
|
||||||
best_record = max(
|
best_record = max(
|
||||||
domains,
|
domains,
|
||||||
key=lambda rank: (
|
key=lambda rank: (
|
||||||
-domain.organization_name.count(" "), count_capitals(domain.organization_name, leading_only=True)
|
-domain.organization_name.count(" "),
|
||||||
|
count_capitals(domain.organization_name, leading_only=True),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
new_suborg_name = best_record.organization_name
|
new_suborg_name = best_record.organization_name
|
||||||
|
@ -397,8 +400,8 @@ class Command(BaseCommand):
|
||||||
use_location_for_domain = all(
|
use_location_for_domain = all(
|
||||||
d.city
|
d.city
|
||||||
and d.state_territory
|
and d.state_territory
|
||||||
and d.city == reference.city
|
and d.city == reference.city
|
||||||
and d.state_territory == reference.state_territory
|
and d.state_territory == reference.state_territory
|
||||||
for d in domains
|
for d in domains
|
||||||
)
|
)
|
||||||
if use_location_for_domain:
|
if use_location_for_domain:
|
||||||
|
@ -464,9 +467,7 @@ class Command(BaseCommand):
|
||||||
updated_domains.add(domain_info)
|
updated_domains.add(domain_info)
|
||||||
|
|
||||||
if not updated_domains and debug:
|
if not updated_domains and debug:
|
||||||
message = (
|
message = f"Portfolio '{portfolio}' not added to domains: nothing to add found."
|
||||||
f"Portfolio '{portfolio}' not added to domains: nothing to add found."
|
|
||||||
)
|
|
||||||
logger.warning(f"{TerminalColors.YELLOW}{message}{TerminalColors.ENDC}")
|
logger.warning(f"{TerminalColors.YELLOW}{message}{TerminalColors.ENDC}")
|
||||||
|
|
||||||
return updated_domains
|
return updated_domains
|
||||||
|
@ -512,32 +513,21 @@ class Command(BaseCommand):
|
||||||
updated_domain_requests.add(domain_request)
|
updated_domain_requests.add(domain_request)
|
||||||
|
|
||||||
if not updated_domain_requests and debug:
|
if not updated_domain_requests and debug:
|
||||||
message = (
|
message = f"Portfolio '{portfolio}' not added to domain requests: nothing to add found."
|
||||||
f"Portfolio '{portfolio}' not added to domain requests: nothing to add found."
|
|
||||||
)
|
|
||||||
logger.warning(f"{TerminalColors.YELLOW}{message}{TerminalColors.ENDC}")
|
logger.warning(f"{TerminalColors.YELLOW}{message}{TerminalColors.ENDC}")
|
||||||
|
|
||||||
return updated_domain_requests
|
return updated_domain_requests
|
||||||
|
|
||||||
def create_user_portfolio_permissions(self, domains):
|
def create_user_portfolio_permissions(self, domains):
|
||||||
user_domain_roles = UserDomainRole.objects.select_related(
|
user_domain_roles = UserDomainRole.objects.select_related(
|
||||||
"user",
|
"user", "domain", "domain__domain_info", "domain__domain_info__portfolio"
|
||||||
"domain",
|
).filter(domain__in=domains, domain__domain_info__portfolio__isnull=False, role=UserDomainRole.Roles.MANAGER)
|
||||||
"domain__domain_info",
|
|
||||||
"domain__domain_info__portfolio"
|
|
||||||
).filter(
|
|
||||||
domain__in=domains,
|
|
||||||
domain__domain_info__portfolio__isnull=False,
|
|
||||||
role=UserDomainRole.Roles.MANAGER
|
|
||||||
)
|
|
||||||
for user_domain_role in user_domain_roles:
|
for user_domain_role in user_domain_roles:
|
||||||
user = user_domain_role.user
|
user = user_domain_role.user
|
||||||
permission, created = UserPortfolioPermission.objects.get_or_create(
|
permission, created = UserPortfolioPermission.objects.get_or_create(
|
||||||
portfolio=user_domain_role.domain.domain_info.portfolio,
|
portfolio=user_domain_role.domain.domain_info.portfolio,
|
||||||
user=user,
|
user=user,
|
||||||
defaults={
|
defaults={"roles": [UserPortfolioRoleChoices.ORGANIZATION_MEMBER]},
|
||||||
"roles": [UserPortfolioRoleChoices.ORGANIZATION_MEMBER]
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
if created:
|
if created:
|
||||||
self.user_portfolio_perm_changes.create.append(permission)
|
self.user_portfolio_perm_changes.create.append(permission)
|
||||||
|
@ -546,13 +536,11 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def create_portfolio_invitations(self, domains):
|
def create_portfolio_invitations(self, domains):
|
||||||
domain_invitations = DomainInvitation.objects.select_related(
|
domain_invitations = DomainInvitation.objects.select_related(
|
||||||
"domain",
|
"domain", "domain__domain_info", "domain__domain_info__portfolio"
|
||||||
"domain__domain_info",
|
|
||||||
"domain__domain_info__portfolio"
|
|
||||||
).filter(
|
).filter(
|
||||||
domain__in=domains,
|
domain__in=domains,
|
||||||
domain__domain_info__portfolio__isnull=False,
|
domain__domain_info__portfolio__isnull=False,
|
||||||
status=DomainInvitation.DomainInvitationStatus.INVITED
|
status=DomainInvitation.DomainInvitationStatus.INVITED,
|
||||||
)
|
)
|
||||||
for domain_invitation in domain_invitations:
|
for domain_invitation in domain_invitations:
|
||||||
email = normalize_string(domain_invitation.email)
|
email = normalize_string(domain_invitation.email)
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ScriptDataHelper:
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
ScriptDataHelper.bulk_update_fields(Domain, page.object_list, ["first_ready"])
|
ScriptDataHelper.bulk_update_fields(Domain, page.object_list, ["first_ready"])
|
||||||
|
|
||||||
Returns: A queryset of the updated objets
|
Returns: A queryset of the updated objets
|
||||||
"""
|
"""
|
||||||
if not quiet:
|
if not quiet:
|
||||||
|
@ -82,7 +82,7 @@ class ScriptDataHelper:
|
||||||
or large field values, you may need to decrease this value to prevent out-of-memory errors.
|
or large field values, you may need to decrease this value to prevent out-of-memory errors.
|
||||||
Usage:
|
Usage:
|
||||||
ScriptDataHelper.bulk_add_fields(Domain, page.object_list)
|
ScriptDataHelper.bulk_add_fields(Domain, page.object_list)
|
||||||
|
|
||||||
Returns: A queryset of the added objects
|
Returns: A queryset of the added objects
|
||||||
"""
|
"""
|
||||||
if not quiet:
|
if not quiet:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue