Skip to content

Commit 5a4c015

Browse files
committed
PPHA-534: Use inflection over pyhumps
1 parent 0eb18cf commit 5a4c015

9 files changed

Lines changed: 19 additions & 38 deletions

File tree

lung_cancer_screening/jinja2_env.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import inflection
2-
31
from django.conf import settings
42
from django.templatetags.static import static
53
from django.urls import reverse
4+
from inflection import singularize
65
from jinja2 import ChoiceLoader, Environment, PackageLoader
76

87

@@ -31,7 +30,7 @@ def environment(**options):
3130
)
3231

3332
env.filters.update(
34-
{"singularize": inflection.singularize}
33+
{"singularize": singularize}
3534
)
3635

3736
return env

lung_cancer_screening/questions/presenters/response_set_presenter.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import humps
2-
import inflection
3-
41
from decimal import Decimal
52
from django.urls import reverse
3+
from inflection import dasherize, singularize
64

75
from ..models.education_response import EducationValues
86
from ..models.respiratory_conditions_response import RespiratoryConditionValues
@@ -250,11 +248,10 @@ def family_history_responses_items(self):
250248

251249
return items
252250

253-
254251
def smoking_history_types_responses_items(self):
255252
items = []
256253
for type_history in self.response_set.tobacco_smoking_history.in_form_order():
257-
tobacco_type_kwargs = {"tobacco_type": humps.kebabize(type_history.type)}
254+
tobacco_type_kwargs = {"tobacco_type": dasherize(type_history.type).lower()}
258255
type_label = type_history.human_type().lower()
259256

260257
items.append(self._check_your_answer_item(
@@ -264,7 +261,7 @@ def smoking_history_types_responses_items(self):
264261
kwargs=tobacco_type_kwargs,
265262
))
266263
items.append(self._check_your_answer_item(
267-
f"Current {inflection.singularize(type_label)} smoking",
264+
f"Current {singularize(type_label)} smoking",
268265
f"{type_history.smoked_amount_response.value} {type_label} per day" if hasattr(type_history, 'smoked_amount_response') else None,
269266
"questions:smoked_amount",
270267
kwargs=tobacco_type_kwargs,

lung_cancer_screening/questions/tests/unit/presenters/test_response_set_presenter.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import humps
2-
31
from django.test import TestCase, tag
42
from django.urls import reverse
3+
from inflection import dasherize
54

65
from ...factories.response_set_factory import ResponseSetFactory
76
from ...factories.have_you_ever_smoked_response_factory import HaveYouEverSmokedResponseFactory
@@ -492,9 +491,9 @@ def test_smoking_history_types_responses_items_sets_the_correct_change_link(self
492491
reverse(
493492
"questions:smoked_total_years",
494493
kwargs={
495-
"tobacco_type": humps.kebabize(
494+
"tobacco_type": dasherize(
496495
TobaccoSmokingHistoryTypes.CIGARETTES
497-
)
496+
).lower()
498497
},
499498
query={"change": "True"},
500499
),

lung_cancer_screening/questions/tests/unit/views/test_types_tobacco_smoking.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import humps
2-
31
from django.test import TestCase, tag
42
from django.urls import reverse
3+
from inflection import dasherize
54

65
from .helpers.authentication import login_user
76
from ...factories.response_set_factory import ResponseSetFactory
@@ -127,5 +126,5 @@ def test_post_redirects_to_the_first_type_of_tobacco_smoking_history_question(se
127126
)
128127

129128
self.assertRedirects(response, reverse("questions:smoked_total_years", kwargs={
130-
"tobacco_type": humps.kebabize(TobaccoSmokingHistoryTypes.CIGARETTES.value)
129+
"tobacco_type": dasherize(TobaccoSmokingHistoryTypes.CIGARETTES.value).lower()
131130
}), fetch_redirect_response=False)

lung_cancer_screening/questions/views/mixins/ensure_smoking_history_for_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import humps
1+
from inflection import camelize
22
from django.http import Http404
33

44
class EnsureSmokingHistoryForTypeMixin:
55

66
def dispatch(self, request, *args, **kwargs):
7-
url_tobacco_type = humps.pascalize(kwargs["tobacco_type"])
7+
url_tobacco_type = camelize(kwargs["tobacco_type"])
88

99

1010
if request.response_set.tobacco_smoking_history.filter(type=url_tobacco_type).exists():

lung_cancer_screening/questions/views/smoking_history_question_base_view.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import humps
1+
from inflection import camelize
2+
23
from .question_base_view import QuestionBaseView
34

45
class SmokingHistoryQuestionBaseView(QuestionBaseView):
@@ -9,5 +10,5 @@ def get_object(self):
910

1011
def _get_history_item_for_type(self):
1112
return self.request.response_set.tobacco_smoking_history.filter(
12-
type=humps.pascalize(self.kwargs["tobacco_type"])
13+
type=camelize(self.kwargs["tobacco_type"])
1314
).first()

lung_cancer_screening/questions/views/types_tobacco_smoking.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import humps
2-
31
from django.urls import reverse
42
from django.contrib.auth.mixins import LoginRequiredMixin
53
from django.views.generic.edit import FormView
4+
from inflection import dasherize
65

76
from .mixins.ensure_response_set import EnsureResponseSet
87
from .mixins.ensure_eligible import EnsureEligibleMixin
@@ -35,8 +34,8 @@ def get_success_url(self):
3534
return reverse(
3635
"questions:smoked_total_years",
3736
kwargs={
38-
"tobacco_type": humps.kebabize(
37+
"tobacco_type": dasherize(
3938
self.request.response_set.tobacco_smoking_history.first().type
40-
)
39+
).lower()
4140
},
4241
)

poetry.lock

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ dependencies = [
1717
"mozilla-django-oidc (>=3.0.0,<4.0.0)",
1818
"pyjwt (>=2.8.0,<3.0.0)",
1919
"cryptography (>=46.0.3)",
20-
"pyhumps (>=3.8.0,<4.0.0)",
2120
"inflection (>=0.5.1,<0.6.0)",
2221
]
2322

0 commit comments

Comments
 (0)