From 70ed673502512f7f90f4a24dd683e8c76a9095d8 Mon Sep 17 00:00:00 2001 From: Stefan Date: Mon, 23 Dec 2024 18:03:53 +0100 Subject: [PATCH] :white_check_mark: FIX broken test. --- src/sdg/components/templatetags/fields.py | 1 - .../components/templatetags/update_form.py | 11 +++++----- src/sdg/conf/base.py | 2 +- src/sdg/organisaties/urls/notificaties.py | 2 +- src/sdg/organisaties/views/notificaties.py | 20 ++++++++--------- src/sdg/producten/forms.py | 3 ++- src/sdg/producten/models/localized.py | 2 +- src/sdg/producten/views/product.py | 4 +++- src/sdg/utils/templatetags/utils.py | 22 ++++++++++++++----- 9 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/sdg/components/templatetags/fields.py b/src/sdg/components/templatetags/fields.py index e4500e6f..83794685 100644 --- a/src/sdg/components/templatetags/fields.py +++ b/src/sdg/components/templatetags/fields.py @@ -22,7 +22,6 @@ def checkbox(context, field, **kwargs): inline = kwargs.get("inline", False) readonly = kwargs.get("readonly", False) - return { **kwargs, "context": context, diff --git a/src/sdg/components/templatetags/update_form.py b/src/sdg/components/templatetags/update_form.py index 09678ea7..5508d0f1 100644 --- a/src/sdg/components/templatetags/update_form.py +++ b/src/sdg/components/templatetags/update_form.py @@ -25,7 +25,7 @@ def update_form_generic(context) -> dict: generic_products = context.get("generic_products") formset = context.get("formset") - readonly = not context['user_can_edit'] + readonly = not context["user_can_edit"] def get_object_list(): obj_list = [] @@ -79,7 +79,7 @@ def update_form_specific(context) -> dict: languages = get_languages(formset) fields = get_fields(formset.forms[0], localized_form_fields) - readonly = not context['user_can_edit'] + readonly = not context["user_can_edit"] def get_object_list(formset: BaseFormSet, fields: list) -> list: object_list = [] @@ -99,7 +99,7 @@ def get_object_list(formset: BaseFormSet, fields: list) -> list: "form_name": form_name, "object_list": get_object_list(formset, fields), "readonly": readonly, - "org_type_name": org_type_cfg().name + "org_type_name": org_type_cfg().name, } @@ -137,8 +137,7 @@ def update_form_general(context) -> dict: # Nonlocalized fields in the general update form nonlocalized_field_names = ["interne_opmerkingen"] nonlocalized_fields = get_fields(version_form, nonlocalized_field_names) - readonly = not context['user_can_edit'] - + readonly = not context["user_can_edit"] def get_localized_object_dict(formset: BaseFormSet, fields: list) -> dict: object_list = {} @@ -173,5 +172,5 @@ def get_nonlocalized_object_dict(form: BaseForm, fields: list) -> dict: ), "product_form": product_form, "product": product, - "readonly": readonly + "readonly": readonly, } diff --git a/src/sdg/conf/base.py b/src/sdg/conf/base.py index 35ecb56d..978a4e38 100644 --- a/src/sdg/conf/base.py +++ b/src/sdg/conf/base.py @@ -663,4 +663,4 @@ assert "{organisation}" in template -SDG_PRESS_THROUGH_DAYS = config("SDG_PRESS_THROUGH_DAYS", 30) \ No newline at end of file +SDG_PRESS_THROUGH_DAYS = config("SDG_PRESS_THROUGH_DAYS", 30) diff --git a/src/sdg/organisaties/urls/notificaties.py b/src/sdg/organisaties/urls/notificaties.py index 58e14e6e..cf673be3 100644 --- a/src/sdg/organisaties/urls/notificaties.py +++ b/src/sdg/organisaties/urls/notificaties.py @@ -5,4 +5,4 @@ app_name = "notificaties" urlpatterns = [ path("", ProductVersieListView.as_view(), name="list"), -] \ No newline at end of file +] diff --git a/src/sdg/organisaties/views/notificaties.py b/src/sdg/organisaties/views/notificaties.py index 9bcdcb40..ab714c7e 100644 --- a/src/sdg/organisaties/views/notificaties.py +++ b/src/sdg/organisaties/views/notificaties.py @@ -1,4 +1,5 @@ from django.contrib.auth.mixins import LoginRequiredMixin +from django.core.exceptions import PermissionDenied from django.utils import timezone from django.utils.timezone import now from django.utils.translation import gettext as _ @@ -6,11 +7,10 @@ from dateutil.relativedelta import relativedelta +from sdg.accounts.mixins import OverheidMixin from sdg.core.views.mixins import BreadcrumbsMixin -from sdg.producten.models import NotificationViewed, ProductVersie -from django.core.exceptions import PermissionDenied from sdg.organisaties.models import LokaleOverheid -from sdg.accounts.mixins import OverheidMixin +from sdg.producten.models import NotificationViewed, ProductVersie class ProductVersieListView( @@ -40,7 +40,6 @@ def get_lokale_overheid(self): self.lokale_overheid = LokaleOverheid.objects.get(pk=self.kwargs["pk"]) return self.lokale_overheid - def get_queryset(self): """ @@ -60,17 +59,18 @@ def get(self, request, *args, **kwargs): # Call the parent class's get method to fetch the queryset response = super().get(request, *args, **kwargs) - # Raise permission denied error if the notification page + # Raise permission denied error if the notification page # of a different lokale_overheid is requested. - valid_request = any([ - kwargs['pk'] == str(role.lokale_overheid.pk) - for role in request.user.roles.all() - ]) + valid_request = any( + [ + kwargs["pk"] == str(role.lokale_overheid.pk) + for role in request.user.roles.all() + ] + ) if not valid_request: raise PermissionDenied() - # Update or create the NotificationViewed instance for the current user NotificationViewed.objects.update_or_create(gebruiker=request.user) diff --git a/src/sdg/producten/forms.py b/src/sdg/producten/forms.py index 99b1617e..cfd2722a 100644 --- a/src/sdg/producten/forms.py +++ b/src/sdg/producten/forms.py @@ -291,7 +291,8 @@ def clean(self): False if "concept" in submit_type else automatic_press_through ) automatic_press_through_date = ( - datetime.strptime(publish_date, "%Y-%m-%d").date() + timedelta(days=settings.SDG_PRESS_THROUGH_DAYS) + datetime.strptime(publish_date, "%Y-%m-%d").date() + + timedelta(days=settings.SDG_PRESS_THROUGH_DAYS) if automatic_press_through else None ) diff --git a/src/sdg/producten/models/localized.py b/src/sdg/producten/models/localized.py index 34a0c2c3..01019a31 100644 --- a/src/sdg/producten/models/localized.py +++ b/src/sdg/producten/models/localized.py @@ -164,7 +164,7 @@ class LocalizedProduct(ProductFieldMixin, TaalMixin, models.Model): models.CharField(max_length=512), ), error_messages={ - 'nested_array_mismatch': "De link moet een label en een URL bevatten." + "nested_array_mismatch": "De link moet een label en een URL bevatten." }, subwidget_form=LabeledURLWidget, validators=[validate_labeled_url], diff --git a/src/sdg/producten/views/product.py b/src/sdg/producten/views/product.py index 54ed489e..5d28eb20 100644 --- a/src/sdg/producten/views/product.py +++ b/src/sdg/producten/views/product.py @@ -422,7 +422,9 @@ def _add_placeholder_warning(self): messages.add_message( self.request, messages.WARNING, - _("De huidige gegevens bevatten placeholder tekst. Controleer en bewerk de tekst hieronder."), + _( + "De huidige gegevens bevatten placeholder tekst. Controleer en bewerk de tekst hieronder." + ), ) return diff --git a/src/sdg/utils/templatetags/utils.py b/src/sdg/utils/templatetags/utils.py index 8fafa3f4..9855e039 100644 --- a/src/sdg/utils/templatetags/utils.py +++ b/src/sdg/utils/templatetags/utils.py @@ -77,12 +77,14 @@ def addclass(field, class_attr): @register.filter(name="add_readonly") def add_readonly(field): - return field.as_widget(attrs={"readonly": True, "disabled": True }) + return field.as_widget(attrs={"readonly": True, "disabled": True}) @register.filter(name="add_class_and_readonly") def add_class_and_readonly(field, class_attrs): - return field.as_widget(attrs={"readonly": True, "disabled": True, "class": class_attrs}) + return field.as_widget( + attrs={"readonly": True, "disabled": True, "class": class_attrs} + ) @register.filter(name="add_class_for_label") @@ -92,17 +94,27 @@ def add_class_for_label(field, class_attr): @register.filter(name="add_class_and_readonly_for_label") def add_class_and_readonly_for_label(field, class_attr): - return field.as_widget(attrs={"readonly": True, "class": class_attr, "placeholder": "Label"}) + return field.as_widget( + attrs={"readonly": True, "class": class_attr, "placeholder": "Label"} + ) @register.filter(name="add_class_for_link") def add_class_for_link(field, class_attr): - return field.as_widget(attrs={"class": class_attr, "placeholder": "https://example.com/"}) + return field.as_widget( + attrs={"class": class_attr, "placeholder": "https://example.com/"} + ) @register.filter(name="add_class_and_readonly_for_link") def add_class_and_readonly_for_link(field, class_attr): - return field.as_widget(attrs={"readonly": True, "class": class_attr, "placeholder": "https://example.com/"}) + return field.as_widget( + attrs={ + "readonly": True, + "class": class_attr, + "placeholder": "https://example.com/", + } + ) @register.simple_tag