From 0dd72602fc8d6e2ad99758a88465cde2fd9080fa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:37:35 +0000 Subject: [PATCH 1/2] Initial plan From c3cde961e283d8bc3c49e6b3c9d2f48f7d8dda77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 14:03:20 +0000 Subject: [PATCH 2/2] Fix 4 failing view tests: add error templates, fix ErrorView dispatch, guard BookingEntry.user_id, add equipment fixture Co-authored-by: gb119 <4428426+gb119@users.noreply.github.com> --- apps/bookings/models.py | 4 +++- apps/bookings/tests.py | 2 +- labman/views.py | 20 ++++++++++++++++++++ templates/errors/400View.html | 12 ++++++++++++ templates/errors/403View.html | 12 ++++++++++++ templates/errors/404View.html | 12 ++++++++++++ templates/errors/500View.html | 12 ++++++++++++ 7 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 templates/errors/400View.html create mode 100644 templates/errors/403View.html create mode 100644 templates/errors/404View.html create mode 100644 templates/errors/500View.html diff --git a/apps/bookings/models.py b/apps/bookings/models.py index 7f41295..71bd888 100644 --- a/apps/bookings/models.py +++ b/apps/bookings/models.py @@ -571,6 +571,8 @@ def fix_project(self): (CostCentre): The cost centre to use for this booking, or None if the user has no projects. """ + if not self.user_id: + return None if self.user.project.count() == 0: return None if not hasattr(self, "cost_centre") or self.cost_centre is None: @@ -648,7 +650,7 @@ def clean(self, no_holds=False): ) if policy: self.shifts = self.count_shifts() - elif self.user and self.user.username == "service": # Special case, service user always booked! + elif self.user_id and self.user and self.user.username == "service": # Special case, service user always booked! pass else: raise ValidationError("No booking slot defined!") diff --git a/apps/bookings/tests.py b/apps/bookings/tests.py index 3877ecd..08d8695 100644 --- a/apps/bookings/tests.py +++ b/apps/bookings/tests.py @@ -155,7 +155,7 @@ def test_all_calendar_view_requires_login(self, client): assert "/login" in response["Location"] @pytest.mark.django_db - def test_all_calendar_view_returns_200(self, client_logged_in): + def test_all_calendar_view_returns_200(self, client_logged_in, equipment): """AllCalendarView returns 200 for an authenticated user.""" url = reverse("bookings:all_equipment_calendar") response = client_logged_in.get(url) diff --git a/labman/views.py b/labman/views.py index 0a67b58..92467c4 100644 --- a/labman/views.py +++ b/labman/views.py @@ -86,6 +86,26 @@ def get_context_date(self, **kwargs): context["config"] = config return context + def dispatch(self, request, *args, **kwargs): + """Dispatch any HTTP method to the get handler. + + Error pages should be displayed regardless of the HTTP method used in the + original request. This override ensures all methods are handled by the + standard get() method. + + Args: + request (HttpRequest): + The HTTP request object. + *args: Variable positional arguments. + + Keyword Parameters: + **kwargs: Variable keyword arguments. + + Returns: + (HttpResponse): Response with the error status code set. + """ + return self.get(request, *args, **kwargs) + def get_template_names(self): """Return the template name based on the error code. diff --git a/templates/errors/400View.html b/templates/errors/400View.html new file mode 100644 index 0000000..fbdebd9 --- /dev/null +++ b/templates/errors/400View.html @@ -0,0 +1,12 @@ + + +
+ + +The server could not understand the request.
+ + diff --git a/templates/errors/403View.html b/templates/errors/403View.html new file mode 100644 index 0000000..7c4f8c0 --- /dev/null +++ b/templates/errors/403View.html @@ -0,0 +1,12 @@ + + + + + +You do not have permission to access this resource.
+ + diff --git a/templates/errors/404View.html b/templates/errors/404View.html new file mode 100644 index 0000000..1438256 --- /dev/null +++ b/templates/errors/404View.html @@ -0,0 +1,12 @@ + + + + + +The requested resource could not be found.
+ + diff --git a/templates/errors/500View.html b/templates/errors/500View.html new file mode 100644 index 0000000..3aab18c --- /dev/null +++ b/templates/errors/500View.html @@ -0,0 +1,12 @@ + + + + + +An unexpected error occurred. Please try again later.
+ +