diff --git a/src/sdg/accounts/forms.py b/src/sdg/accounts/forms.py index f5faf20b2..360c8a79e 100644 --- a/src/sdg/accounts/forms.py +++ b/src/sdg/accounts/forms.py @@ -49,6 +49,6 @@ class AuthenticationForm(_AuthenticationForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.error_messages[ - "invalid_login" - ] = "Voer een juist e-mailadres en wachtwoord in." + self.error_messages["invalid_login"] = ( + "Voer een juist e-mailadres en wachtwoord in." + ) diff --git a/src/sdg/conf/base.py b/src/sdg/conf/base.py index 43a91aab5..273c856ca 100644 --- a/src/sdg/conf/base.py +++ b/src/sdg/conf/base.py @@ -131,6 +131,7 @@ "django_filters", "vng_api_common", "vng_api_common.authorizations", + "simple_certmanager", "drf_spectacular", "rest_framework", "timeline_logger", @@ -159,6 +160,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", "axes.middleware.AxesMiddleware", "django_otp.middleware.OTPMiddleware", + "allauth.account.middleware.AccountMiddleware", ] ROOT_URLCONF = "sdg.urls" diff --git a/src/sdg/conf/ci.py b/src/sdg/conf/ci.py index 57c80da52..3812b101f 100644 --- a/src/sdg/conf/ci.py +++ b/src/sdg/conf/ci.py @@ -1,6 +1,7 @@ """ Continuous integration settings module. """ + import os os.environ.setdefault("IS_HTTPS", "no") diff --git a/src/sdg/conf/production.py b/src/sdg/conf/production.py index e5985e5b8..c69137b99 100644 --- a/src/sdg/conf/production.py +++ b/src/sdg/conf/production.py @@ -3,6 +3,7 @@ Tweaks the base settings so that caching mechanisms are used where possible, and HTTPS is leveraged where possible to further secure things. """ + import os os.environ.setdefault("ENVIRONMENT", "production") diff --git a/src/sdg/conf/staging.py b/src/sdg/conf/staging.py index b580b7ae8..531de39a1 100644 --- a/src/sdg/conf/staging.py +++ b/src/sdg/conf/staging.py @@ -2,6 +2,7 @@ Staging environment settings module. This *should* be nearly identical to production. """ + import os os.environ.setdefault("ENVIRONMENT", "staging") diff --git a/src/sdg/conf/test.py b/src/sdg/conf/test.py index aa1525f33..dfd51ccf7 100644 --- a/src/sdg/conf/test.py +++ b/src/sdg/conf/test.py @@ -2,6 +2,7 @@ Staging environment settings module. This *should* be nearly identical to production. """ + import os os.environ.setdefault("ENVIRONMENT", "test") diff --git a/src/sdg/conf/utils.py b/src/sdg/conf/utils.py index c7b554301..e99a2e1c6 100644 --- a/src/sdg/conf/utils.py +++ b/src/sdg/conf/utils.py @@ -7,7 +7,7 @@ from django.conf import settings -import pydantic +from functools import lru_cache from decouple import Csv, config as _config, undefined from sentry_sdk.integrations import DidNotEnable, django, redis @@ -58,7 +58,7 @@ def get_sentry_integrations() -> list: return [*default, *extra] -@pydantic.tools.lru_cache +@lru_cache def org_type_cfg(): """ Get the organization type configuration for the current environment. diff --git a/src/sdg/core/forms/fields.py b/src/sdg/core/forms/fields.py index b1d2a718d..d50bc4a20 100644 --- a/src/sdg/core/forms/fields.py +++ b/src/sdg/core/forms/fields.py @@ -26,9 +26,11 @@ def __init__(self, base_field, **kwargs): kwargs.setdefault( "widget", - DynamicArrayWidget(subwidget_form=subwidget_form) - if subwidget_form - else DynamicArrayWidget, + ( + DynamicArrayWidget(subwidget_form=subwidget_form) + if subwidget_form + else DynamicArrayWidget + ), ) super().__init__(**kwargs) diff --git a/src/sdg/core/management/utils.py b/src/sdg/core/management/utils.py index bfacee67c..99585982f 100644 --- a/src/sdg/core/management/utils.py +++ b/src/sdg/core/management/utils.py @@ -36,9 +36,11 @@ def load_government_organisations(data: List[Dict[str, Any]]) -> int: owms_identifier=resource_id, defaults={ "owms_pref_label": obj.get("prefLabel"), - "owms_end_date": string_to_date(obj.get("endDate"), "%Y-%m-%d") - if obj.get("endDate") - else None, + "owms_end_date": ( + string_to_date(obj.get("endDate"), "%Y-%m-%d") + if obj.get("endDate") + else None + ), }, ) if created: @@ -248,7 +250,10 @@ def _try_delete_generic_product(generic_product): generic_products = [] for group in groups: - (generic_product, g_created,) = GeneriekProduct.objects.get_or_create( + ( + generic_product, + g_created, + ) = GeneriekProduct.objects.get_or_create( upn=upn, doelgroep=group, ) diff --git a/src/sdg/core/tests/test_views.py b/src/sdg/core/tests/test_views.py index 0a7ab8b88..a8fcbb1df 100644 --- a/src/sdg/core/tests/test_views.py +++ b/src/sdg/core/tests/test_views.py @@ -56,7 +56,7 @@ def test_consultant_user_can_visit_home_page(self): @override_settings(SDG_ORGANIZATION_TYPE="waterauthority") def test_organization_type_link_is_displayed(self): response = self.app.get(reverse(HOME_URL)) - self.assertIn(org_type_cfg().url, response.text) + self.assertIn(str(org_type_cfg().url), response.text) @override_settings(SDG_ORGANIZATION_TYPE="waterauthority") def test_organization_type_logo_is_displayed(self): diff --git a/src/sdg/producten/forms.py b/src/sdg/producten/forms.py index b1f59e674..2c0061dc8 100644 --- a/src/sdg/producten/forms.py +++ b/src/sdg/producten/forms.py @@ -60,11 +60,11 @@ def __init__(self, *args, **kwargs): else: for form in self.forms: if not form.initial["product_titel_decentraal"]: - form.initial[ - "product_titel_decentraal" - ] = self.instance.product.generiek_product.vertalingen.get( - taal=form.instance.taal - ).product_titel + form.initial["product_titel_decentraal"] = ( + self.instance.product.generiek_product.vertalingen.get( + taal=form.instance.taal + ).product_titel + ) def clean(self): """ diff --git a/src/sdg/producten/tests/test_product.py b/src/sdg/producten/tests/test_product.py index 2bcea67f0..f5de2b2a0 100644 --- a/src/sdg/producten/tests/test_product.py +++ b/src/sdg/producten/tests/test_product.py @@ -222,9 +222,9 @@ def test_concept_save_now_with_default_explanation_placeholder(self): for idx, language in enumerate(TaalChoices.get_available_languages()): response.form[f"vertalingen-{idx}-product_aanwezig_toelichting"] = "test" - response.form[ - f"vertalingen-{idx}-product_valt_onder_toelichting" - ] = falls_under_explanation_map.get(language) + response.form[f"vertalingen-{idx}-product_valt_onder_toelichting"] = ( + falls_under_explanation_map.get(language) + ) response = self._submit_product_form(response.form, Product.status.PUBLISHED) self.assertEqual(response.status_code, 302) @@ -435,9 +435,9 @@ def test_unable_to_save_product_with_placeholder(self): for date_field in response.form.fields["date"]: date_field.value = NOW_DATE - response.form[ - "vertalingen-0-product_titel_decentraal" - ] = "Title [[placeholder]]" + response.form["vertalingen-0-product_titel_decentraal"] = ( + "Title [[placeholder]]" + ) response = response.form.submit(name="publish", value="date") self.assertEqual(response.status_code, 200) @@ -473,9 +473,9 @@ def test_able_to_save_product_concept_with_placeholder(self): for date_field in response.form.fields["date"]: date_field.value = None - response.form[ - "vertalingen-0-product_titel_decentraal" - ] = "Title [[placeholder]]" + response.form["vertalingen-0-product_titel_decentraal"] = ( + "Title [[placeholder]]" + ) response = response.form.submit(name="publish", value="concept") self.assertEqual(response.status_code, 302) @@ -1395,9 +1395,9 @@ def test_able_to_save_reference_product_with_placeholder(self): for date_field in response.form.fields["date"]: date_field.value = NOW_DATE - response.form[ - "vertalingen-0-product_titel_decentraal" - ] = "Title [[placeholder]]" + response.form["vertalingen-0-product_titel_decentraal"] = ( + "Title [[placeholder]]" + ) response = response.form.submit(name="publish", value="date") self.assertEqual(response.status_code, 302) diff --git a/src/sdg/producten/views/product.py b/src/sdg/producten/views/product.py index e87e4c831..172e93f85 100644 --- a/src/sdg/producten/views/product.py +++ b/src/sdg/producten/views/product.py @@ -374,9 +374,9 @@ def get_context_data(self, **kwargs): ], # TODO: optimize ) - context[ - "published_product_language_links" - ] = self._get_published_taal_product_links() + context["published_product_language_links"] = ( + self._get_published_taal_product_links() + ) context["history"] = ( self.product.get_all_versions() diff --git a/src/sdg/services/management/commands/import_data_from_services.py b/src/sdg/services/management/commands/import_data_from_services.py index d9afc44de..735b896c1 100644 --- a/src/sdg/services/management/commands/import_data_from_services.py +++ b/src/sdg/services/management/commands/import_data_from_services.py @@ -23,7 +23,9 @@ def handle(self, **options): retrieved_upn_uris = [p["upnUri"] for p in products] LocalizedGeneriekProduct.objects.filter( generiek_product__doelgroep=service_config.doelgroep, - ).exclude(generiek_product__upn__upn_uri__in=retrieved_upn_uris,).update( + ).exclude( + generiek_product__upn__upn_uri__in=retrieved_upn_uris, + ).update( # Don't clean everything to prevent manually entered texts from # being wiped. # diff --git a/src/sdg/setup.py b/src/sdg/setup.py index cb6d2154b..6fbb0618c 100644 --- a/src/sdg/setup.py +++ b/src/sdg/setup.py @@ -9,6 +9,7 @@ do NOT import anything Django related here, as this file needs to be loaded before Django is initialized. """ + import os from dotenv import load_dotenv