Commit c20be33a authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils

Merge branch '51-anonymoususer-iteration-at-boutique-order-edit' into 'master'

Resolve "AnonymousUser iteration at /boutique/order/edit"

Closes #51

See merge request !57
parents 5abc936d d3326054
......@@ -504,6 +504,14 @@ class OrderEditViewTest(OrderItemTestCase):
)
self.assertTrue(context["is_contributor"])
def test_get_unauthenticated(self) -> None:
"""Tests that unauthenticated users get redirected"""
url = reverse("boutique:order_edit")
resp = self.client.get(url)
self.assertRedirects(resp, "/accounts/login?next=/boutique/order/edit", fetch_redirect_response=False)
class DeliveryViewTest(PaymentTestCase, OrderItemTestCase):
"""Tests for views.DeliveryView"""
......
......@@ -323,18 +323,21 @@ class OrderEditView(LoginRequiredMixin, UpdateView):
object: Order
def get_object(self) -> Order: # type: ignore[override] # override not supported
return self.model.objects.get_current_order(self.request.user)
"""
Get the current order
def setup(self, request, *args, **kwargs):
"""Delete illegal objects prior to display"""
super().setup(request, *args, **kwargs)
Deletes illegal objects prior to display
"""
obj = self.model.objects.get_current_order(self.request.user)
if self.get_object().clean_illegal_items():
if obj.clean_illegal_items():
messages.error(
self.request,
"Certains objets sont périmés ou ont été cachés par un administrateur. Ils ont été supprimé du panier.",
"Certains objets sont périmés ou ont été cachés par un administrateur. Ils ont été supprimés du panier.",
)
return obj
def get_form_class(self) -> Type[BaseInlineFormSet]: # type: ignore[override] # override not supported
return inlineformset_factory(
self.model,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment