mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-01 10:13:55 +02:00
refactor org literal mapping to dict, tweak error handing, lint
This commit is contained in:
parent
5e787eeed3
commit
372ead1121
2 changed files with 16 additions and 13 deletions
|
@ -107,9 +107,9 @@ class DomainApplication(TimeStampedModel):
|
||||||
class OrganizationChoices(models.TextChoices):
|
class OrganizationChoices(models.TextChoices):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Primary organization choices:
|
Primary organization choices:
|
||||||
For use in django admin
|
For use in django admin
|
||||||
Keys need to match OrganizationChoicesVerbose
|
Keys need to match OrganizationChoicesVerbose
|
||||||
"""
|
"""
|
||||||
|
|
||||||
FEDERAL = "federal", "Federal"
|
FEDERAL = "federal", "Federal"
|
||||||
|
@ -124,9 +124,9 @@ class DomainApplication(TimeStampedModel):
|
||||||
class OrganizationChoicesVerbose(models.TextChoices):
|
class OrganizationChoicesVerbose(models.TextChoices):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Secondary organization choices
|
Secondary organization choices
|
||||||
For use in the application form and on the templates
|
For use in the application form and on the templates
|
||||||
Keys need to match OrganizationChoices
|
Keys need to match OrganizationChoices
|
||||||
"""
|
"""
|
||||||
|
|
||||||
FEDERAL = (
|
FEDERAL = (
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
import logging
|
||||||
from django import template
|
from django import template
|
||||||
import re
|
import re
|
||||||
from registrar.models.domain_application import DomainApplication
|
from registrar.models.domain_application import DomainApplication
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="extract_value")
|
@register.filter(name="extract_value")
|
||||||
|
@ -53,13 +55,14 @@ def contains_checkbox(html_list):
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def get_organization_long_name(organization_type):
|
def get_organization_long_name(organization_type):
|
||||||
organization_choices_dict = {}
|
# https://gist.github.com/OmenApps/3eef60ba4204f3d1842d9d7477efcce1#file-django_choices-txt-L28
|
||||||
|
organization_choices_dict = dict(
|
||||||
for name, value in DomainApplication.OrganizationChoicesVerbose.choices:
|
DomainApplication.OrganizationChoicesVerbose.choices
|
||||||
organization_choices_dict[name] = value
|
)
|
||||||
|
|
||||||
long_form_type = organization_choices_dict[organization_type]
|
long_form_type = organization_choices_dict[organization_type]
|
||||||
if long_form_type is not None:
|
if long_form_type is None:
|
||||||
return long_form_type
|
logger.error("Organization type error, triggered by a template's custom filter")
|
||||||
|
return "Error"
|
||||||
|
|
||||||
return "Error"
|
return long_form_type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue