mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:51:09 -05:00
Refactor error message handling: centralize required fields error message and improve park list template accessibility
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
<div class="flex items-center space-x-4">
|
||||
<h1 class="text-2xl font-bold text-gray-900">Parks</h1>
|
||||
|
||||
<div class="flex items-center space-x-2 bg-gray-100 rounded-lg p-1" role="group" aria-label="View mode selection">
|
||||
<fieldset class="flex items-center space-x-2 bg-gray-100 rounded-lg p-1">
|
||||
<legend class="sr-only">View mode selection</legend>
|
||||
<button hx-get="{% url 'parks:park_list' %}?view_mode=grid{% if request.GET.search %}&search={{ request.GET.search }}{% endif %}"
|
||||
hx-target="#park-results"
|
||||
hx-push-url="true"
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import requests
|
||||
from decimal import Decimal, ROUND_DOWN
|
||||
from typing import Any, Optional, cast, Literal
|
||||
|
||||
# Constants for error messages
|
||||
REQUIRED_FIELDS_ERROR = "Please correct the errors below. Required fields are marked with an asterisk (*)."
|
||||
|
||||
from django.views.generic import DetailView, ListView, CreateView, UpdateView
|
||||
from decimal import InvalidOperation
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
@@ -408,14 +412,7 @@ class ParkCreateView(LoginRequiredMixin, CreateView):
|
||||
messages.success(
|
||||
self.request,
|
||||
"Your park submission has been sent for review. "
|
||||
"You will be notified when it is approved.",
|
||||
)
|
||||
return HttpResponseRedirect(reverse("parks:park_list"))
|
||||
|
||||
def form_invalid(self, form: ParkForm) -> HttpResponse:
|
||||
messages.error(
|
||||
self.request,
|
||||
"Please correct the errors below. Required fields are marked with an asterisk (*).",
|
||||
"You will be notified when it is approved."
|
||||
)
|
||||
for field, errors in form.errors.items():
|
||||
for error in errors:
|
||||
@@ -551,7 +548,7 @@ class ParkUpdateView(LoginRequiredMixin, UpdateView):
|
||||
def form_invalid(self, form: ParkForm) -> HttpResponse:
|
||||
messages.error(
|
||||
self.request,
|
||||
"Please correct the errors below. Required fields are marked with an asterisk (*).",
|
||||
REQUIRED_FIELDS_ERROR
|
||||
)
|
||||
for field, errors in form.errors.items():
|
||||
for error in errors:
|
||||
@@ -734,7 +731,7 @@ class ParkAreaDetailView(
|
||||
def form_invalid(self, form: ParkForm) -> HttpResponse:
|
||||
messages.error(
|
||||
self.request,
|
||||
"Please correct the errors below. Required fields are marked with an asterisk (*).",
|
||||
REQUIRED_FIELDS_ERROR,
|
||||
)
|
||||
for field, errors in form.errors.items():
|
||||
for error in errors:
|
||||
@@ -872,7 +869,7 @@ class ParkUpdateView(LoginRequiredMixin, UpdateView):
|
||||
def form_invalid(self, form: ParkForm) -> HttpResponse:
|
||||
messages.error(
|
||||
self.request,
|
||||
"Please correct the errors below. Required fields are marked with an asterisk (*).",
|
||||
REQUIRED_FIELDS_ERROR,
|
||||
)
|
||||
for field, errors in form.errors.items():
|
||||
for error in errors:
|
||||
|
||||
Reference in New Issue
Block a user