refactor org literal mapping to dict, tweak error handing, lint

This commit is contained in:
Rachid Mrad 2023-10-13 17:05:33 -04:00
parent 5e787eeed3
commit 372ead1121
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
2 changed files with 16 additions and 13 deletions

View file

@ -1,8 +1,10 @@
import logging
from django import template
import re
from registrar.models.domain_application import DomainApplication
register = template.Library()
logger = logging.getLogger(__name__)
@register.filter(name="extract_value")
@ -53,13 +55,14 @@ def contains_checkbox(html_list):
@register.filter
def get_organization_long_name(organization_type):
organization_choices_dict = {}
for name, value in DomainApplication.OrganizationChoicesVerbose.choices:
organization_choices_dict[name] = value
# https://gist.github.com/OmenApps/3eef60ba4204f3d1842d9d7477efcce1#file-django_choices-txt-L28
organization_choices_dict = dict(
DomainApplication.OrganizationChoicesVerbose.choices
)
long_form_type = organization_choices_dict[organization_type]
if long_form_type is not None:
return long_form_type
if long_form_type is None:
logger.error("Organization type error, triggered by a template's custom filter")
return "Error"
return long_form_type