Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #1853] Move where we define the lookup mapping to avoid constant import issues #1854

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 0 additions & 88 deletions api/src/constants/lookup_constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from enum import StrEnum

from src.db.models.lookup import LookupConfig, LookupStr


class OpportunityStatus(StrEnum):
FORECASTED = "forecasted"
Expand All @@ -10,16 +8,6 @@ class OpportunityStatus(StrEnum):
ARCHIVED = "archived"


OPPORTUNITY_STATUS_CONFIG = LookupConfig(
[
LookupStr(OpportunityStatus.FORECASTED, 1),
LookupStr(OpportunityStatus.POSTED, 2),
LookupStr(OpportunityStatus.CLOSED, 3),
LookupStr(OpportunityStatus.ARCHIVED, 4),
]
)


class OpportunityCategoryLegacy(StrEnum):
# These are only used where the legacy system
# needs to specify the values and can be removed
Expand All @@ -39,17 +27,6 @@ class OpportunityCategory(StrEnum):
OTHER = "other"


OPPORTUNITY_CATEGORY_CONFIG = LookupConfig(
[
LookupStr(OpportunityCategory.DISCRETIONARY, 1),
LookupStr(OpportunityCategory.MANDATORY, 2),
LookupStr(OpportunityCategory.CONTINUATION, 3),
LookupStr(OpportunityCategory.EARMARK, 4),
LookupStr(OpportunityCategory.OTHER, 5),
]
)


class ApplicantType(StrEnum):
# https://grants.gov/system-to-system/grantor-system-to-system/schemas/grants-funding-synopsis#EligibleApplicantTypes
# Comment is the legacy systems code
Expand Down Expand Up @@ -86,29 +63,6 @@ class ApplicantType(StrEnum):
UNRESTRICTED = "unrestricted" # 99


APPLICANT_TYPE_CONFIG = LookupConfig(
[
LookupStr(ApplicantType.STATE_GOVERNMENTS, 1),
LookupStr(ApplicantType.COUNTY_GOVERNMENTS, 2),
LookupStr(ApplicantType.CITY_OR_TOWNSHIP_GOVERNMENTS, 3),
LookupStr(ApplicantType.SPECIAL_DISTRICT_GOVERNMENTS, 4),
LookupStr(ApplicantType.INDEPENDENT_SCHOOL_DISTRICTS, 5),
LookupStr(ApplicantType.PUBLIC_AND_STATE_INSTITUTIONS_OF_HIGHER_EDUCATION, 6),
LookupStr(ApplicantType.PRIVATE_INSTITUTIONS_OF_HIGHER_EDUCATION, 7),
LookupStr(ApplicantType.FEDERALLY_RECOGNIZED_NATIVE_AMERICAN_TRIBAL_GOVERNMENTS, 8),
LookupStr(ApplicantType.OTHER_NATIVE_AMERICAN_TRIBAL_ORGANIZATIONS, 9),
LookupStr(ApplicantType.PUBLIC_AND_INDIAN_HOUSING_AUTHORITIES, 10),
LookupStr(ApplicantType.NONPROFITS_NON_HIGHER_EDUCATION_WITH_501C3, 11),
LookupStr(ApplicantType.NONPROFITS_NON_HIGHER_EDUCATION_WITHOUT_501C3, 12),
LookupStr(ApplicantType.INDIVIDUALS, 13),
LookupStr(ApplicantType.FOR_PROFIT_ORGANIZATIONS_OTHER_THAN_SMALL_BUSINESSES, 14),
LookupStr(ApplicantType.SMALL_BUSINESSES, 15),
LookupStr(ApplicantType.OTHER, 16),
LookupStr(ApplicantType.UNRESTRICTED, 17),
]
)


class FundingCategory(StrEnum):
# https://grants.gov/system-to-system/grantor-system-to-system/schemas/grants-funding-synopsis#FundingActivityCategory
# Comment is the legacy systems code
Expand Down Expand Up @@ -143,38 +97,6 @@ class FundingCategory(StrEnum):
OTHER = "other" # O


FUNDING_CATEGORY_CONFIG = LookupConfig(
[
LookupStr(FundingCategory.RECOVERY_ACT, 1),
LookupStr(FundingCategory.AGRICULTURE, 2),
LookupStr(FundingCategory.ARTS, 3),
LookupStr(FundingCategory.BUSINESS_AND_COMMERCE, 4),
LookupStr(FundingCategory.COMMUNITY_DEVELOPMENT, 5),
LookupStr(FundingCategory.CONSUMER_PROTECTION, 6),
LookupStr(FundingCategory.DISASTER_PREVENTION_AND_RELIEF, 7),
LookupStr(FundingCategory.EDUCATION, 8),
LookupStr(FundingCategory.EMPLOYMENT_LABOR_AND_TRAINING, 9),
LookupStr(FundingCategory.ENERGY, 10),
LookupStr(FundingCategory.ENVIRONMENT, 11),
LookupStr(FundingCategory.FOOD_AND_NUTRITION, 12),
LookupStr(FundingCategory.HEALTH, 13),
LookupStr(FundingCategory.HOUSING, 14),
LookupStr(FundingCategory.HUMANITIES, 15),
LookupStr(FundingCategory.INFRASTRUCTURE_INVESTMENT_AND_JOBS_ACT, 16),
LookupStr(FundingCategory.INFORMATION_AND_STATISTICS, 17),
LookupStr(FundingCategory.INCOME_SECURITY_AND_SOCIAL_SERVICES, 18),
LookupStr(FundingCategory.LAW_JUSTICE_AND_LEGAL_SERVICES, 19),
LookupStr(FundingCategory.NATURAL_RESOURCES, 20),
LookupStr(FundingCategory.OPPORTUNITY_ZONE_BENEFITS, 21),
LookupStr(FundingCategory.REGIONAL_DEVELOPMENT, 22),
LookupStr(FundingCategory.SCIENCE_TECHNOLOGY_AND_OTHER_RESEARCH_AND_DEVELOPMENT, 23),
LookupStr(FundingCategory.TRANSPORTATION, 24),
LookupStr(FundingCategory.AFFORDABLE_CARE_ACT, 25),
LookupStr(FundingCategory.OTHER, 26),
]
)


class FundingInstrument(StrEnum):
# https://grants.gov/system-to-system/grantor-system-to-system/schemas/grants-funding-synopsis#FundingInstrument
# Comment is the legacy systems code
Expand All @@ -183,13 +105,3 @@ class FundingInstrument(StrEnum):
GRANT = "grant" # G
PROCUREMENT_CONTRACT = "procurement_contract" # PC
OTHER = "other" # O


FUNDING_INSTRUMENT_CONFIG = LookupConfig(
[
LookupStr(FundingInstrument.COOPERATIVE_AGREEMENT, 1),
LookupStr(FundingInstrument.GRANT, 2),
LookupStr(FundingInstrument.PROCUREMENT_CONTRACT, 3),
LookupStr(FundingInstrument.OTHER, 4),
]
)
107 changes: 98 additions & 9 deletions api/src/db/models/lookup_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,100 @@
from sqlalchemy.orm import Mapped, mapped_column

from src.constants import lookup_constants
from src.constants.lookup_constants import (
ApplicantType,
FundingCategory,
FundingInstrument,
OpportunityCategory,
OpportunityStatus,
)
from src.db.models.base import TimestampMixin
from src.db.models.lookup import Lookup, LookupRegistry, LookupTable


@LookupRegistry.register_lookup(lookup_constants.OPPORTUNITY_CATEGORY_CONFIG)
from src.db.models.lookup import Lookup, LookupConfig, LookupRegistry, LookupStr, LookupTable

OPPORTUNITY_STATUS_CONFIG = LookupConfig(
[
LookupStr(OpportunityStatus.FORECASTED, 1),
LookupStr(OpportunityStatus.POSTED, 2),
LookupStr(OpportunityStatus.CLOSED, 3),
LookupStr(OpportunityStatus.ARCHIVED, 4),
]
)


OPPORTUNITY_CATEGORY_CONFIG = LookupConfig(
[
LookupStr(OpportunityCategory.DISCRETIONARY, 1),
LookupStr(OpportunityCategory.MANDATORY, 2),
LookupStr(OpportunityCategory.CONTINUATION, 3),
LookupStr(OpportunityCategory.EARMARK, 4),
LookupStr(OpportunityCategory.OTHER, 5),
]
)

APPLICANT_TYPE_CONFIG = LookupConfig(
[
LookupStr(ApplicantType.STATE_GOVERNMENTS, 1),
LookupStr(ApplicantType.COUNTY_GOVERNMENTS, 2),
LookupStr(ApplicantType.CITY_OR_TOWNSHIP_GOVERNMENTS, 3),
LookupStr(ApplicantType.SPECIAL_DISTRICT_GOVERNMENTS, 4),
LookupStr(ApplicantType.INDEPENDENT_SCHOOL_DISTRICTS, 5),
LookupStr(ApplicantType.PUBLIC_AND_STATE_INSTITUTIONS_OF_HIGHER_EDUCATION, 6),
LookupStr(ApplicantType.PRIVATE_INSTITUTIONS_OF_HIGHER_EDUCATION, 7),
LookupStr(ApplicantType.FEDERALLY_RECOGNIZED_NATIVE_AMERICAN_TRIBAL_GOVERNMENTS, 8),
LookupStr(ApplicantType.OTHER_NATIVE_AMERICAN_TRIBAL_ORGANIZATIONS, 9),
LookupStr(ApplicantType.PUBLIC_AND_INDIAN_HOUSING_AUTHORITIES, 10),
LookupStr(ApplicantType.NONPROFITS_NON_HIGHER_EDUCATION_WITH_501C3, 11),
LookupStr(ApplicantType.NONPROFITS_NON_HIGHER_EDUCATION_WITHOUT_501C3, 12),
LookupStr(ApplicantType.INDIVIDUALS, 13),
LookupStr(ApplicantType.FOR_PROFIT_ORGANIZATIONS_OTHER_THAN_SMALL_BUSINESSES, 14),
LookupStr(ApplicantType.SMALL_BUSINESSES, 15),
LookupStr(ApplicantType.OTHER, 16),
LookupStr(ApplicantType.UNRESTRICTED, 17),
]
)


FUNDING_CATEGORY_CONFIG = LookupConfig(
[
LookupStr(FundingCategory.RECOVERY_ACT, 1),
LookupStr(FundingCategory.AGRICULTURE, 2),
LookupStr(FundingCategory.ARTS, 3),
LookupStr(FundingCategory.BUSINESS_AND_COMMERCE, 4),
LookupStr(FundingCategory.COMMUNITY_DEVELOPMENT, 5),
LookupStr(FundingCategory.CONSUMER_PROTECTION, 6),
LookupStr(FundingCategory.DISASTER_PREVENTION_AND_RELIEF, 7),
LookupStr(FundingCategory.EDUCATION, 8),
LookupStr(FundingCategory.EMPLOYMENT_LABOR_AND_TRAINING, 9),
LookupStr(FundingCategory.ENERGY, 10),
LookupStr(FundingCategory.ENVIRONMENT, 11),
LookupStr(FundingCategory.FOOD_AND_NUTRITION, 12),
LookupStr(FundingCategory.HEALTH, 13),
LookupStr(FundingCategory.HOUSING, 14),
LookupStr(FundingCategory.HUMANITIES, 15),
LookupStr(FundingCategory.INFRASTRUCTURE_INVESTMENT_AND_JOBS_ACT, 16),
LookupStr(FundingCategory.INFORMATION_AND_STATISTICS, 17),
LookupStr(FundingCategory.INCOME_SECURITY_AND_SOCIAL_SERVICES, 18),
LookupStr(FundingCategory.LAW_JUSTICE_AND_LEGAL_SERVICES, 19),
LookupStr(FundingCategory.NATURAL_RESOURCES, 20),
LookupStr(FundingCategory.OPPORTUNITY_ZONE_BENEFITS, 21),
LookupStr(FundingCategory.REGIONAL_DEVELOPMENT, 22),
LookupStr(FundingCategory.SCIENCE_TECHNOLOGY_AND_OTHER_RESEARCH_AND_DEVELOPMENT, 23),
LookupStr(FundingCategory.TRANSPORTATION, 24),
LookupStr(FundingCategory.AFFORDABLE_CARE_ACT, 25),
LookupStr(FundingCategory.OTHER, 26),
]
)

FUNDING_INSTRUMENT_CONFIG = LookupConfig(
[
LookupStr(FundingInstrument.COOPERATIVE_AGREEMENT, 1),
LookupStr(FundingInstrument.GRANT, 2),
LookupStr(FundingInstrument.PROCUREMENT_CONTRACT, 3),
LookupStr(FundingInstrument.OTHER, 4),
]
)


@LookupRegistry.register_lookup(OPPORTUNITY_CATEGORY_CONFIG)
class LkOpportunityCategory(LookupTable, TimestampMixin):
__tablename__ = "lk_opportunity_category"

Expand All @@ -19,7 +108,7 @@ def from_lookup(cls, lookup: Lookup) -> "LkOpportunityCategory":
)


@LookupRegistry.register_lookup(lookup_constants.APPLICANT_TYPE_CONFIG)
@LookupRegistry.register_lookup(APPLICANT_TYPE_CONFIG)
class LkApplicantType(LookupTable, TimestampMixin):
__tablename__ = "lk_applicant_type"

Expand All @@ -33,7 +122,7 @@ def from_lookup(cls, lookup: Lookup) -> "LkApplicantType":
)


@LookupRegistry.register_lookup(lookup_constants.FUNDING_CATEGORY_CONFIG)
@LookupRegistry.register_lookup(FUNDING_CATEGORY_CONFIG)
class LkFundingCategory(LookupTable, TimestampMixin):
__tablename__ = "lk_funding_category"

Expand All @@ -47,7 +136,7 @@ def from_lookup(cls, lookup: Lookup) -> "LkFundingCategory":
)


@LookupRegistry.register_lookup(lookup_constants.FUNDING_INSTRUMENT_CONFIG)
@LookupRegistry.register_lookup(FUNDING_INSTRUMENT_CONFIG)
class LkFundingInstrument(LookupTable, TimestampMixin):
__tablename__ = "lk_funding_instrument"

Expand All @@ -61,7 +150,7 @@ def from_lookup(cls, lookup: Lookup) -> "LkFundingInstrument":
)


@LookupRegistry.register_lookup(lookup_constants.OPPORTUNITY_STATUS_CONFIG)
@LookupRegistry.register_lookup(OPPORTUNITY_STATUS_CONFIG)
class LkOpportunityStatus(LookupTable, TimestampMixin):
__tablename__ = "lk_opportunity_status"

Expand Down
Loading