Skip to content

Commit

Permalink
Adds ISO2 and region to both data csv files. #442
Browse files Browse the repository at this point in the history
  • Loading branch information
drcongo committed Aug 14, 2024
1 parent 9b04367 commit 28bf10c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/modules/notion/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"Who can access",
]

COUNTRY_HEADERS = ["", "Stage"] + BASE_HEADERS
COUNTRY_HEADERS = ["", "Stage"] + BASE_HEADERS + ["ISO2", "Region"]

ALL_HEADERS = ["Country", "Stage"] + BASE_HEADERS
ALL_HEADERS = ["Country", "Stage"] + BASE_HEADERS + ["ISO2", "Region"]


class DataExportBase(View):
Expand Down Expand Up @@ -126,17 +126,22 @@ def get(self, *args, **kwargs): # noqa: ARG002
def _generate_csv(self, response: HttpResponse):
writer = csv.writer(response)
writer.writerow(COUNTRY_HEADERS)
row = ["", "", "", "", "", "", "", "", "", ""]
row = ["", "", "", "", "", "", "", "", "", "", "", ""]
row[0] = self.country.name
row[1] = self.country.category_display
row[10] = self.country.iso2
try:
region = self.country.regions.first().name
except Exception as err:
logger.error(err)
row[11] = region
writer.writerow(row)
# NO MORE COMMITMENT ROWS!
# for commitment in self.country.commitments.all():
# writer.writerow(self._get_commitment_row(commitment))
for regime in self.country.regimes.all():
if regime.display:
row = self._get_regime_row(regime)
logger.info(row)
writer.writerow(row)
return writer

Expand Down Expand Up @@ -164,8 +169,14 @@ def _generate_csv(self, response: HttpResponse):
# writer.writerow(row)
for regime in country.regimes.all():
if regime.display:
row = [country.name] + self._get_regime_row(regime, is_single=False)
row = [country.name] + self._get_regime_row(regime, is_single=False) + ["", ""]
row[1] = country.category_display
row[10] = country.iso2
try:
region = country.regions.first().name
except Exception as err:
logger.error(err)
row[11] = region
writer.writerow(row)
return writer

Expand Down

0 comments on commit 28bf10c

Please sign in to comment.