Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/bookings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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!")
Expand Down
2 changes: 1 addition & 1 deletion apps/bookings/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions labman/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 12 additions & 0 deletions templates/errors/400View.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>400 Bad Request</title>
</head>
<body>
<h1>400 Bad Request</h1>
<p>The server could not understand the request.</p>
</body>
</html>
12 changes: 12 additions & 0 deletions templates/errors/403View.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>403 Forbidden</title>
</head>
<body>
<h1>403 Forbidden</h1>
<p>You do not have permission to access this resource.</p>
</body>
</html>
12 changes: 12 additions & 0 deletions templates/errors/404View.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>404 Not Found</title>
</head>
<body>
<h1>404 Not Found</h1>
<p>The requested resource could not be found.</p>
</body>
</html>
12 changes: 12 additions & 0 deletions templates/errors/500View.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>500 Internal Server Error</title>
</head>
<body>
<h1>500 Internal Server Error</h1>
<p>An unexpected error occurred. Please try again later.</p>
</body>
</html>