mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 09:21:54 +02:00
Cleanup
This commit is contained in:
parent
0fc136cf54
commit
41cca72bd6
2 changed files with 17 additions and 26 deletions
|
@ -914,7 +914,7 @@ Example (only requests): `./manage.py create_federal_portfolio --branch "executi
|
|||
| 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. |
|
||||
| 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 #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,
|
||||
|
|
|
@ -184,14 +184,22 @@ class Command(BaseCommand):
|
|||
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
|
||||
also create new suborganizations"""
|
||||
portfolio, _ = self.create_portfolio(federal_agency)
|
||||
self.create_suborganizations(portfolio, federal_agency)
|
||||
portfolio, created = self.create_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:
|
||||
self.handle_portfolio_domains(portfolio, federal_agency, skip_existing_portfolios)
|
||||
self.handle_portfolio_domains(portfolio, federal_agency)
|
||||
|
||||
if parse_requests or both:
|
||||
self.handle_portfolio_requests(portfolio, federal_agency, skip_existing_portfolios)
|
||||
self.handle_portfolio_requests(portfolio, federal_agency)
|
||||
|
||||
return portfolio
|
||||
|
||||
|
@ -282,9 +290,7 @@ class Command(BaseCommand):
|
|||
else:
|
||||
TerminalHelper.colorful_logger(logger.warning, TerminalColors.YELLOW, "No suborganizations added")
|
||||
|
||||
def handle_portfolio_requests(
|
||||
self, portfolio: Portfolio, federal_agency: FederalAgency, skip_existing_portfolios: bool
|
||||
):
|
||||
def handle_portfolio_requests(self, portfolio: Portfolio, federal_agency: FederalAgency):
|
||||
"""
|
||||
Associate portfolio with domain requests for a federal agency.
|
||||
Updates all relevant domain request records.
|
||||
|
@ -294,16 +300,7 @@ class Command(BaseCommand):
|
|||
DomainRequest.DomainRequestStatus.INELIGIBLE,
|
||||
DomainRequest.DomainRequestStatus.REJECTED,
|
||||
]
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
domain_requests = DomainRequest.objects.filter(federal_agency=federal_agency).exclude(status__in=invalid_states)
|
||||
if not domain_requests.exists():
|
||||
message = f"""
|
||||
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."
|
||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message)
|
||||
|
||||
def handle_portfolio_domains(
|
||||
self, portfolio: Portfolio, federal_agency: FederalAgency, skip_existing_portfolios: bool
|
||||
):
|
||||
def handle_portfolio_domains(self, portfolio: Portfolio, federal_agency: FederalAgency):
|
||||
"""
|
||||
Associate portfolio with domains for a federal agency.
|
||||
Updates all relevant domain information records.
|
||||
|
||||
Returns a queryset of DomainInformation objects, or None if nothing changed.
|
||||
"""
|
||||
if skip_existing_portfolios:
|
||||
domain_infos = DomainInformation.objects.filter(federal_agency=federal_agency, portfolio__isnull=True)
|
||||
else:
|
||||
domain_infos = DomainInformation.objects.filter(federal_agency=federal_agency)
|
||||
|
||||
domain_infos = DomainInformation.objects.filter(federal_agency=federal_agency)
|
||||
if not domain_infos.exists():
|
||||
message = f"""
|
||||
Portfolio '{portfolio}' not added to domains: no valid records found.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue