Skip to content

Commit

Permalink
Fix error to be raised when CountryOverview of a country is absent.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rup-Narayan-Rajbanshi committed Aug 22, 2024
1 parent 9241816 commit 5c1b7d0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
4 changes: 2 additions & 2 deletions databank/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class CountryOverviewAdmin(admin.ModelAdmin):
"calculated_world_bank_gdp_year",
"world_bank_gni",
"calculated_world_bank_gni_year",
"world_bank_gender_inequality_index",
"calculated_world_bank_gender_inequality_index_year",
"world_bank_gender_equality_index",
"calculated_world_bank_gender_equality_index_year",
"world_bank_life_expectancy",
"calculated_world_bank_life_expectancy_year",
"world_bank_literacy_rate",
Expand Down
8 changes: 4 additions & 4 deletions databank/management/commands/ingest_worldbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class CountryIndicatorData(typing.TypedDict):
CountryOverview.calculated_world_bank_gni_year,
),
"IQ.CPA.GNDR.XQ": (
CountryOverview.world_bank_gender_inequality_index,
CountryOverview.calculated_world_bank_gender_inequality_index_year,
CountryOverview.world_bank_gender_equality_index,
CountryOverview.calculated_world_bank_gender_equality_index_year,
),
"SP.DYN.LE00.IN": (
CountryOverview.world_bank_life_expectancy,
Expand Down Expand Up @@ -105,7 +105,7 @@ def get_date_range(start_year: int, end_year: int):

def paginated_response(self, iso3, indicator, daterange) -> typing.Iterator[dict]:
"""
This addes support for pagination.
This adds support for pagination.
NOTE: With current per_page 5000 -1, pagination is called rarely
"""
page = 1
Expand Down Expand Up @@ -169,7 +169,7 @@ def handle(self, **_):
for index, country in enumerate(country_qs, start=1):
iso3 = country.iso3
self.stdout.write(f"Importing country ({index:03}/{total_countries}): {iso3}")
overview = country.countryoverview
overview = CountryOverview(country=country)

# Pre-fetch to generate smaller date-range relative to local
indicator_data: dict[str, CountryIndicatorData] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.13 on 2024-08-05 10:20
# Generated by Django 4.2.15 on 2024-08-22 11:20

from django.db import migrations, models

Expand All @@ -17,9 +17,9 @@ class Migration(migrations.Migration):
),
migrations.AddField(
model_name="countryoverview",
name="calculated_world_bank_gender_inequality_index_year",
name="calculated_world_bank_gender_equality_index_year",
field=models.CharField(
blank=True, max_length=50, null=True, verbose_name="calculated world bank gender inequality index year"
blank=True, max_length=50, null=True, verbose_name="calculated world bank gender equality index year"
),
),
migrations.AddField(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2024-08-22 12:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("databank", "0026_countryoverview_calculated_world_bank_gdp_year_and_more"),
]

operations = [
migrations.RenameField(
model_name="countryoverview",
old_name="world_bank_gender_inequality_index",
new_name="world_bank_gender_equality_index",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2024-08-22 12:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("databank", "0027_remove_countryoverview_world_bank_gender_inequality_index_and_more"),
]

operations = [
migrations.AlterField(
model_name="countryoverview",
name="world_bank_gender_equality_index",
field=models.FloatField(blank=True, null=True, verbose_name="world bank gender equality index"),
),
]
8 changes: 4 additions & 4 deletions databank/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ class CountryOverview(models.Model):
calculated_world_bank_gni_year = models.CharField(
verbose_name=_("calculated world bank gni year"), null=True, blank=True, max_length=50
)
world_bank_gender_inequality_index = models.FloatField(
verbose_name=_("world bank gender inequality index"), null=True, blank=True
world_bank_gender_equality_index = models.FloatField(
verbose_name=_("world bank gender equality index"), null=True, blank=True
)
calculated_world_bank_gender_inequality_index_year = models.CharField(
verbose_name=_("calculated world bank gender inequality index year"), null=True, blank=True, max_length=50
calculated_world_bank_gender_equality_index_year = models.CharField(
verbose_name=_("calculated world bank gender equality index year"), null=True, blank=True, max_length=50
)
world_bank_life_expectancy = models.IntegerField(verbose_name=_("world bank life expectancy"), null=True, blank=True)
calculated_world_bank_life_expectancy_year = models.CharField(
Expand Down

0 comments on commit 5c1b7d0

Please sign in to comment.