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

Add new Geography definitions for International and no-Geography #116

Merged
merged 7 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 21 additions & 2 deletions app/data_migrations/populate_geography.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from sqlalchemy.orm import Session

from app.db.models.law_policy import Geography
from app.db.models.law_policy.geography import CPR_DEFINED_GEOS, GeoStatistics
from app.db.models.law_policy.geography import (
CPR_DEFINED_GEOS,
GEO_OTHER,
GeoStatistics,
)

from .utils import has_rows, load_tree

Expand Down Expand Up @@ -43,15 +47,30 @@ def populate_geography(db: Session) -> None:
geo_populated = has_rows(db, Geography)
# First ensure our defined entries are present
remove_old_international_geo(db)

# Add the Other region
other = db.query(Geography).filter(Geography.value == GEO_OTHER).one_or_none()
if other is None:
other = Geography(
display_value=GEO_OTHER,
slug=GEO_OTHER.lower(),
value=GEO_OTHER,
type="ISO-3166 CPR Extension",
)
db.add(other)
db.flush()

# Add the CPR geo definitions in Other
for value, description in CPR_DEFINED_GEOS.items():
db_geo = db.query(Geography).filter(Geography.value == value).one_or_none()
if db_geo is None:
db.add(
Geography(
display_value=description,
slug=value,
slug=value.lower(),
diversemix marked this conversation as resolved.
Show resolved Hide resolved
value=value,
type="ISO-3166 CPR Extension",
parent_id=other.id,
)
)

Expand Down
1 change: 1 addition & 0 deletions app/db/models/law_policy/geography.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
GEO_NONE = "XAA"
GEO_INTERNATIONAL = "XAB"

GEO_OTHER = "Other"
CPR_DEFINED_GEOS = {GEO_NONE: "No Geography", GEO_INTERNATIONAL: "International"}


Expand Down