Skip to content

Commit

Permalink
✅ FIX broken test.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefrado committed Dec 23, 2024
1 parent 31fb128 commit 70ed673
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/sdg/components/templatetags/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def checkbox(context, field, **kwargs):
inline = kwargs.get("inline", False)
readonly = kwargs.get("readonly", False)


return {
**kwargs,
"context": context,
Expand Down
11 changes: 5 additions & 6 deletions src/sdg/components/templatetags/update_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 = []
Expand All @@ -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,
}


Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -173,5 +172,5 @@ def get_nonlocalized_object_dict(form: BaseForm, fields: list) -> dict:
),
"product_form": product_form,
"product": product,
"readonly": readonly
"readonly": readonly,
}
2 changes: 1 addition & 1 deletion src/sdg/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,4 @@
assert "{organisation}" in template


SDG_PRESS_THROUGH_DAYS = config("SDG_PRESS_THROUGH_DAYS", 30)
SDG_PRESS_THROUGH_DAYS = config("SDG_PRESS_THROUGH_DAYS", 30)
2 changes: 1 addition & 1 deletion src/sdg/organisaties/urls/notificaties.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
app_name = "notificaties"
urlpatterns = [
path("", ProductVersieListView.as_view(), name="list"),
]
]
20 changes: 10 additions & 10 deletions src/sdg/organisaties/views/notificaties.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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 _
from django.views.generic import ListView

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(
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion src/sdg/producten/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion src/sdg/producten/models/localized.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 3 additions & 1 deletion src/sdg/producten/views/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 17 additions & 5 deletions src/sdg/utils/templatetags/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 70ed673

Please sign in to comment.