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 @@ + + + + + + 400 Bad Request + + +

400 Bad Request

+

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 @@ + + + + + + 403 Forbidden + + +

403 Forbidden

+

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 @@ + + + + + + 404 Not Found + + +

404 Not Found

+

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 @@ + + + + + + 500 Internal Server Error + + +

500 Internal Server Error

+

An unexpected error occurred. Please try again later.

+ +