Skip to content

Commit

Permalink
chore: upgrade dependencies (#348)
Browse files Browse the repository at this point in the history
* upgrade dependencies

* update phac-helpers and use new excel API, also add n+1 tests

---------

Co-authored-by: fluxbot <[email protected]>
  • Loading branch information
AlexCLeduc and fluxbot authored Jun 27, 2024
1 parent 983a6cb commit e829ae4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 51 deletions.
68 changes: 29 additions & 39 deletions server/cpho/views/infobase_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@
]


class IndicatorSheetWriter(AbstractSheetWriter):
class IndicatorSheetWriter(ModelToSheetWriter):
sheet_name = "indicator"

def get_column_configs(self):
return indicator_columns
columns = indicator_columns
queryset = Indicator.objects.all().order_by("name")


indicator_data_columns = [
Expand Down Expand Up @@ -124,9 +123,14 @@ def get_column_configs(self):

class IndicatorDatumSheetWriter(ModelToSheetWriter):
sheet_name = "indicator_data"

def get_column_configs(self):
return indicator_data_columns
queryset = (
IndicatorDatum.objects.all()
.select_related(
"indicator", "period", "dimension_type", "dimension_value"
)
.order_by("indicator_id", "period_id", "dimension_type_id")
)
column = indicator_data_columns


benchmarking_columns = [
Expand All @@ -151,8 +155,13 @@ def get_column_configs(self):


class BenchmarkingSheetWriter(ModelToSheetWriter):
def get_column_configs(self):
return benchmarking_columns
columns = benchmarking_columns
sheet_name = "benchmarking"
queryset = (
Benchmarking.objects.all()
.select_related("indicator", "oecd_country")
.order_by("indicator_id", "labels", "value")
)


trend_columns = [
Expand All @@ -178,8 +187,13 @@ def get_column_configs(self):


class TrendSheetWriter(ModelToSheetWriter):
def get_column_configs(self):
return trend_columns
columns = trend_columns
sheet_name = "trend analysis"
queryset = (
TrendAnalysis.objects.all()
.select_related("indicator")
.order_by("indicator_id", "year")
)


class InfobaseExportView(View):
Expand All @@ -189,43 +203,19 @@ def workbook(self):

def write_indicators(self):
# todo: use submitted indicators instead
writer = IndicatorSheetWriter(
workbook=self.workbook,
iterator=Indicator.objects.all().order_by("name"),
)
writer = IndicatorSheetWriter(workbook=self.workbook)
writer.write()

def write_indicator_data(self):
qs = (
IndicatorDatum.objects.all()
.select_related(
"indicator", "period", "dimension_type", "dimension_value"
)
.order_by("indicator_id", "period_id", "dimension_type_id")
)
writer = IndicatorDatumSheetWriter(
workbook=self.workbook, iterator=qs.all()
)
writer = IndicatorDatumSheetWriter(workbook=self.workbook)
writer.write()

def write_trends(self):
qs = (
TrendAnalysis.objects.all()
.select_related("indicator")
.order_by("indicator_id", "year")
)
writer = TrendSheetWriter(workbook=self.workbook, iterator=qs.all())
writer = TrendSheetWriter(workbook=self.workbook)
writer.write()

def write_benchmarking(self):
qs = (
Benchmarking.objects.all()
.select_related("indicator", "oecd_country")
.order_by("indicator_id", "labels", "value")
)
writer = BenchmarkingSheetWriter(
workbook=self.workbook, iterator=qs.all()
)
writer = BenchmarkingSheetWriter(workbook=self.workbook)
writer.write()

def get(self, request, *args, **kwargs):
Expand Down
10 changes: 5 additions & 5 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
beautifulsoup4==4.12.0
django-debug-toolbar==3.8.1
django-debug-toolbar==4.4.2
django-graphiql-debug-toolbar==0.2.0
django-extensions==3.2.1
django-extensions==3.2.3
django-htmx-autocomplete==0.8.2
django-phac_aspc-helpers==2.1.0
django-phac_aspc-helpers==3.1.1
django-versionator==1.0.0
Django==4.1.13
Django==5.0.6
Faker==15.1.1
freezegun==1.2.2
gunicorn==20.1.0
Expand All @@ -20,7 +20,7 @@ pytz==2022.2.1
requests==2.31.0
whitenoise==6.4.0
rules==3.3
django-ckeditor==6.5.1
django-ckeditor==6.7.1

PyYAML==6.0.1 # necessary to apply fixtures in prod

Expand Down
4 changes: 2 additions & 2 deletions server/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-r requirements_formatting.txt
coverage==7.1.0
pytest==7.1.2
pytest-django==4.5.2
pytest===7.2.1
pytest-django===4.8.0
pytest-watch==4.2.0
pytest-cov
factory-boy===3.2.1
4 changes: 1 addition & 3 deletions server/server/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
migration_ignored_attrs = [
"help_text",
"is_searchable",
"description",
"verbose_name",
"verbose_name_plural",
"ordering",
Expand All @@ -37,9 +36,8 @@ def __init__(self, *args, is_searchable=False, **kwargs):


class DescriptionMixin:
def __init__(self, *args, extra_options=None, description="", **kwargs):
def __init__(self, *args, extra_options=None, **kwargs):
self.extra_options = extra_options or {}
self.description = description
super().__init__(*args, **kwargs)

def deconstruct(self):
Expand Down
4 changes: 3 additions & 1 deletion server/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"ENABLE_DEBUG_TOOLBAR", default=False, cast=bool
)
INTERNAL_IPS = (
config("INTERNAL_IPS", default="") if ENABLE_DEBUG_TOOLBAR else ""
config("INTERNAL_IPS", default="", cast=Csv())
if ENABLE_DEBUG_TOOLBAR
else ""
)

# Disable session timeout
Expand Down
23 changes: 22 additions & 1 deletion server/tests/test_infobase_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

from phac_aspc.rules import patch_rules

from cpho.model_factories import IndicatorDatumFactory, IndicatorFactory
from cpho.model_factories import (
BenchmarkingFactory,
IndicatorDatumFactory,
IndicatorFactory,
TrendAnalysisFactory,
)
from cpho.models import Benchmarking, Country, TrendAnalysis


Expand Down Expand Up @@ -38,3 +43,19 @@ def test_infobase_export(vanilla_user_client):
assert response.status_code == 200
assert response["Content-Type"] == "application/vnd.ms-excel"
assert response.content


def test_infobase_export_queries(
vanilla_user_client, django_assert_max_num_queries
):
url = reverse("infobase_export")

IndicatorFactory.create_batch(15)
IndicatorDatumFactory.create_batch(15)
TrendAnalysisFactory.create_batch(15)
BenchmarkingFactory.create_batch(15)

with patch_rules(is_admin_or_hso=True), django_assert_max_num_queries(10):
response = vanilla_user_client.get(url)
assert response.status_code == 200
assert response["Content-Type"] == "application/vnd.ms-excel"

0 comments on commit e829ae4

Please sign in to comment.