This commit is contained in:
zandercymatics 2025-01-27 10:28:35 -07:00
parent 0fc136cf54
commit 41cca72bd6
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 17 additions and 26 deletions

View file

@ -914,7 +914,7 @@ Example (only requests): `./manage.py create_federal_portfolio --branch "executi
| 3 | **both** | If True, runs parse_requests and parse_domains. | | 3 | **both** | If True, runs parse_requests and parse_domains. |
| 4 | **parse_requests** | If True, then the created portfolio is added to all related DomainRequests. | | 4 | **parse_requests** | If True, then the created portfolio is added to all related DomainRequests. |
| 5 | **parse_domains** | If True, then the created portfolio is added to all related Domains. | | 5 | **parse_domains** | If True, then the created portfolio is added to all related Domains. |
| 6 | **skip_existing_portfolios** | If True, then the script will only iterate through DomainRequest / DomainInfo records with portfolio__isnull=True | | 6 | **skip_existing_portfolios** | If True, then the script will only create suborganizations, modify DomainRequest, and modify DomainInformation records only when creating a new portfolio. Use this flag when you do not want to modify existing records. |
- Parameters #1-#2: Either `--agency_name` or `--branch` must be specified. Not both. - Parameters #1-#2: Either `--agency_name` or `--branch` must be specified. Not both.
- Parameters #2-#3, you cannot use `--both` while using these. You must specify either `--parse_requests` or `--parse_domains` seperately. While all of these parameters are optional in that you do not need to specify all of them, - Parameters #2-#3, you cannot use `--both` while using these. You must specify either `--parse_requests` or `--parse_domains` seperately. While all of these parameters are optional in that you do not need to specify all of them,

View file

@ -184,14 +184,22 @@ class Command(BaseCommand):
def handle_populate_portfolio(self, federal_agency, parse_domains, parse_requests, both, skip_existing_portfolios): def handle_populate_portfolio(self, federal_agency, parse_domains, parse_requests, both, skip_existing_portfolios):
"""Attempts to create a portfolio. If successful, this function will """Attempts to create a portfolio. If successful, this function will
also create new suborganizations""" also create new suborganizations"""
portfolio, _ = self.create_portfolio(federal_agency) portfolio, created = self.create_portfolio(federal_agency)
self.create_suborganizations(portfolio, federal_agency) if skip_existing_portfolios and not created:
TerminalHelper.colorful_logger(
logger.warning,
TerminalColors.YELLOW,
"Skipping modifications to suborgs, domain requests, and "
"domains due to the --skip_existing_portfolios flag. Portfolio already exists.",
)
return portfolio
self.create_suborganizations(portfolio, federal_agency)
if parse_domains or both: if parse_domains or both:
self.handle_portfolio_domains(portfolio, federal_agency, skip_existing_portfolios) self.handle_portfolio_domains(portfolio, federal_agency)
if parse_requests or both: if parse_requests or both:
self.handle_portfolio_requests(portfolio, federal_agency, skip_existing_portfolios) self.handle_portfolio_requests(portfolio, federal_agency)
return portfolio return portfolio
@ -282,9 +290,7 @@ class Command(BaseCommand):
else: else:
TerminalHelper.colorful_logger(logger.warning, TerminalColors.YELLOW, "No suborganizations added") TerminalHelper.colorful_logger(logger.warning, TerminalColors.YELLOW, "No suborganizations added")
def handle_portfolio_requests( def handle_portfolio_requests(self, portfolio: Portfolio, federal_agency: FederalAgency):
self, portfolio: Portfolio, federal_agency: FederalAgency, skip_existing_portfolios: bool
):
""" """
Associate portfolio with domain requests for a federal agency. Associate portfolio with domain requests for a federal agency.
Updates all relevant domain request records. Updates all relevant domain request records.
@ -294,16 +300,7 @@ class Command(BaseCommand):
DomainRequest.DomainRequestStatus.INELIGIBLE, DomainRequest.DomainRequestStatus.INELIGIBLE,
DomainRequest.DomainRequestStatus.REJECTED, DomainRequest.DomainRequestStatus.REJECTED,
] ]
domain_requests = DomainRequest.objects.filter(federal_agency=federal_agency).exclude(status__in=invalid_states)
if skip_existing_portfolios:
domain_requests = DomainRequest.objects.filter(
federal_agency=federal_agency, portfolio__isnull=True
).exclude(status__in=invalid_states)
else:
domain_requests = DomainRequest.objects.filter(federal_agency=federal_agency).exclude(
status__in=invalid_states
)
if not domain_requests.exists(): if not domain_requests.exists():
message = f""" message = f"""
Portfolio '{portfolio}' not added to domain requests: no valid records found. Portfolio '{portfolio}' not added to domain requests: no valid records found.
@ -346,20 +343,14 @@ class Command(BaseCommand):
message = f"Added portfolio '{portfolio}' to {len(domain_requests)} domain requests." message = f"Added portfolio '{portfolio}' to {len(domain_requests)} domain requests."
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message) TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message)
def handle_portfolio_domains( def handle_portfolio_domains(self, portfolio: Portfolio, federal_agency: FederalAgency):
self, portfolio: Portfolio, federal_agency: FederalAgency, skip_existing_portfolios: bool
):
""" """
Associate portfolio with domains for a federal agency. Associate portfolio with domains for a federal agency.
Updates all relevant domain information records. Updates all relevant domain information records.
Returns a queryset of DomainInformation objects, or None if nothing changed. Returns a queryset of DomainInformation objects, or None if nothing changed.
""" """
if skip_existing_portfolios: domain_infos = DomainInformation.objects.filter(federal_agency=federal_agency)
domain_infos = DomainInformation.objects.filter(federal_agency=federal_agency, portfolio__isnull=True)
else:
domain_infos = DomainInformation.objects.filter(federal_agency=federal_agency)
if not domain_infos.exists(): if not domain_infos.exists():
message = f""" message = f"""
Portfolio '{portfolio}' not added to domains: no valid records found. Portfolio '{portfolio}' not added to domains: no valid records found.