mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-15 05:54:11 +02:00
fix linting issue
This commit is contained in:
parent
00aee2a4fe
commit
f32d8c7a31
1 changed files with 8 additions and 13 deletions
|
@ -516,6 +516,10 @@ class PrototypeDomainDNSRecordView(DomainFormBaseView):
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse("prototype-domain-dns", kwargs={"pk": self.object.pk})
|
return reverse("prototype-domain-dns", kwargs={"pk": self.object.pk})
|
||||||
|
|
||||||
|
def find_by_name(self, items, name):
|
||||||
|
"""Find an item by name in a list of dictionaries."""
|
||||||
|
return next((item.get("id") for item in items if item.get("name") == name), None)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
"""Handle form submission."""
|
"""Handle form submission."""
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
@ -562,13 +566,8 @@ class PrototypeDomainDNSRecordView(DomainFormBaseView):
|
||||||
|
|
||||||
# See if we already made an account.
|
# See if we already made an account.
|
||||||
# This maybe doesn't need to be a for loop (1 record or 0) but alas, here we are
|
# This maybe doesn't need to be a for loop (1 record or 0) but alas, here we are
|
||||||
account_id = None
|
|
||||||
accounts = account_response_json.get("result", [])
|
accounts = account_response_json.get("result", [])
|
||||||
for account in accounts:
|
account_id = self.find_by_name(accounts, account_name)
|
||||||
if account.get("name") == account_name:
|
|
||||||
account_id = account.get("id")
|
|
||||||
logger.debug(f"Found it! Account: {account_name} (ID: {account_id})")
|
|
||||||
break
|
|
||||||
|
|
||||||
# If we didn't, create one
|
# If we didn't, create one
|
||||||
if not account_id:
|
if not account_id:
|
||||||
|
@ -596,13 +595,8 @@ class PrototypeDomainDNSRecordView(DomainFormBaseView):
|
||||||
zone_response.raise_for_status()
|
zone_response.raise_for_status()
|
||||||
|
|
||||||
# Get the zone id
|
# Get the zone id
|
||||||
zone_id = None
|
|
||||||
zones = zone_response_json.get("result", [])
|
zones = zone_response_json.get("result", [])
|
||||||
for zone in zones:
|
zone_id = self.find_by_name(zones, zone_name)
|
||||||
if zone.get("name") == zone_name:
|
|
||||||
zone_id = zone.get("id")
|
|
||||||
logger.debug(f"Found it! Zone: {zone_name} (ID: {zone_id})")
|
|
||||||
break
|
|
||||||
|
|
||||||
# Create one if it doesn't presently exist
|
# Create one if it doesn't presently exist
|
||||||
if not zone_id:
|
if not zone_id:
|
||||||
|
@ -662,7 +656,8 @@ class PrototypeDomainDNSRecordView(DomainFormBaseView):
|
||||||
logger.info(f"Created DNS record: {dns_response_json}")
|
logger.info(f"Created DNS record: {dns_response_json}")
|
||||||
errors = dns_response_json.get("errors", [])
|
errors = dns_response_json.get("errors", [])
|
||||||
dns_response.raise_for_status()
|
dns_response.raise_for_status()
|
||||||
messages.success(request, f"DNS A record '{form.cleaned_data['name']}' created successfully.")
|
dns_name = dns_response_json["result"]["name"]
|
||||||
|
messages.success(request, f"DNS A record '{dns_name}' created successfully.")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"Error creating DNS A record for {self.object.name}: {err}")
|
logger.error(f"Error creating DNS A record for {self.object.name}: {err}")
|
||||||
messages.error(request, f"An error occurred: {err}")
|
messages.error(request, f"An error occurred: {err}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue