mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-22 10:51:08 -05:00
Refactor test utilities and enhance ASGI settings
- Cleaned up and standardized assertions in ApiTestMixin for API response validation. - Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE. - Removed unused imports and improved formatting in settings.py. - Refactored URL patterns in urls.py for better readability and organization. - Enhanced view functions in views.py for consistency and clarity. - Added .flake8 configuration for linting and style enforcement. - Introduced type stubs for django-environ to improve type checking with Pylance.
This commit is contained in:
@@ -1 +0,0 @@
|
||||
from .search import LocationSearchForm
|
||||
@@ -1,105 +1,168 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class LocationSearchForm(forms.Form):
|
||||
"""
|
||||
A comprehensive search form that includes text search, location-based
|
||||
search, and content type filtering for a unified search experience.
|
||||
"""
|
||||
|
||||
|
||||
# Text search query
|
||||
q = forms.CharField(
|
||||
required=False,
|
||||
label=_("Search Query"),
|
||||
widget=forms.TextInput(attrs={
|
||||
'placeholder': _("Search parks, rides, companies..."),
|
||||
'class': 'w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white'
|
||||
})
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("Search parks, rides, companies..."),
|
||||
"class": (
|
||||
"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm "
|
||||
"focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 "
|
||||
"dark:border-gray-600 dark:text-white"
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# Location-based search
|
||||
location = forms.CharField(
|
||||
required=False,
|
||||
label=_("Near Location"),
|
||||
widget=forms.TextInput(attrs={
|
||||
'placeholder': _("City, address, or coordinates..."),
|
||||
'id': 'location-input',
|
||||
'class': 'w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white'
|
||||
})
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("City, address, or coordinates..."),
|
||||
"id": "location-input",
|
||||
"class": (
|
||||
"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm "
|
||||
"focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 "
|
||||
"dark:border-gray-600 dark:text-white"
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# Hidden fields for coordinates
|
||||
lat = forms.FloatField(required=False, widget=forms.HiddenInput(attrs={'id': 'lat-input'}))
|
||||
lng = forms.FloatField(required=False, widget=forms.HiddenInput(attrs={'id': 'lng-input'}))
|
||||
|
||||
lat = forms.FloatField(
|
||||
required=False, widget=forms.HiddenInput(attrs={"id": "lat-input"})
|
||||
)
|
||||
lng = forms.FloatField(
|
||||
required=False, widget=forms.HiddenInput(attrs={"id": "lng-input"})
|
||||
)
|
||||
|
||||
# Search radius
|
||||
radius_km = forms.ChoiceField(
|
||||
required=False,
|
||||
label=_("Search Radius"),
|
||||
choices=[
|
||||
('', _("Any distance")),
|
||||
('5', _("5 km")),
|
||||
('10', _("10 km")),
|
||||
('25', _("25 km")),
|
||||
('50', _("50 km")),
|
||||
('100', _("100 km")),
|
||||
('200', _("200 km")),
|
||||
("", _("Any distance")),
|
||||
("5", _("5 km")),
|
||||
("10", _("10 km")),
|
||||
("25", _("25 km")),
|
||||
("50", _("50 km")),
|
||||
("100", _("100 km")),
|
||||
("200", _("200 km")),
|
||||
],
|
||||
widget=forms.Select(attrs={
|
||||
'class': 'w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white'
|
||||
})
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
"class": (
|
||||
"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm "
|
||||
"focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 "
|
||||
"dark:border-gray-600 dark:text-white"
|
||||
)
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# Content type filters
|
||||
search_parks = forms.BooleanField(
|
||||
required=False,
|
||||
initial=True,
|
||||
label=_("Search Parks"),
|
||||
widget=forms.CheckboxInput(attrs={'class': 'rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700'})
|
||||
widget=forms.CheckboxInput(
|
||||
attrs={
|
||||
"class": (
|
||||
"rounded border-gray-300 text-blue-600 focus:ring-blue-500 "
|
||||
"dark:border-gray-600 dark:bg-gray-700"
|
||||
)
|
||||
}
|
||||
),
|
||||
)
|
||||
search_rides = forms.BooleanField(
|
||||
required=False,
|
||||
label=_("Search Rides"),
|
||||
widget=forms.CheckboxInput(attrs={'class': 'rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700'})
|
||||
widget=forms.CheckboxInput(
|
||||
attrs={
|
||||
"class": (
|
||||
"rounded border-gray-300 text-blue-600 focus:ring-blue-500 "
|
||||
"dark:border-gray-600 dark:bg-gray-700"
|
||||
)
|
||||
}
|
||||
),
|
||||
)
|
||||
search_companies = forms.BooleanField(
|
||||
required=False,
|
||||
label=_("Search Companies"),
|
||||
widget=forms.CheckboxInput(attrs={'class': 'rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700'})
|
||||
widget=forms.CheckboxInput(
|
||||
attrs={
|
||||
"class": (
|
||||
"rounded border-gray-300 text-blue-600 focus:ring-blue-500 "
|
||||
"dark:border-gray-600 dark:bg-gray-700"
|
||||
)
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# Geographic filters
|
||||
country = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.TextInput(attrs={
|
||||
'placeholder': _("Country"),
|
||||
'class': 'w-full px-3 py-2 text-sm border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white'
|
||||
})
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("Country"),
|
||||
"class": (
|
||||
"w-full px-3 py-2 text-sm border border-gray-300 rounded-md "
|
||||
"shadow-sm focus:ring-blue-500 focus:border-blue-500 "
|
||||
"dark:bg-gray-700 dark:border-gray-600 dark:text-white"
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
state = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.TextInput(attrs={
|
||||
'placeholder': _("State/Region"),
|
||||
'class': 'w-full px-3 py-2 text-sm border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white'
|
||||
})
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("State/Region"),
|
||||
"class": (
|
||||
"w-full px-3 py-2 text-sm border border-gray-300 rounded-md "
|
||||
"shadow-sm focus:ring-blue-500 focus:border-blue-500 "
|
||||
"dark:bg-gray-700 dark:border-gray-600 dark:text-white"
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
city = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.TextInput(attrs={
|
||||
'placeholder': _("City"),
|
||||
'class': 'w-full px-3 py-2 text-sm border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white'
|
||||
})
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("City"),
|
||||
"class": (
|
||||
"w-full px-3 py-2 text-sm border border-gray-300 rounded-md "
|
||||
"shadow-sm focus:ring-blue-500 focus:border-blue-500 "
|
||||
"dark:bg-gray-700 dark:border-gray-600 dark:text-white"
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
||||
# If lat/lng are provided, ensure location field is populated for display
|
||||
lat = cleaned_data.get('lat')
|
||||
lng = cleaned_data.get('lng')
|
||||
location = cleaned_data.get('location')
|
||||
|
||||
|
||||
# If lat/lng are provided, ensure location field is populated for
|
||||
# display
|
||||
lat = cleaned_data.get("lat")
|
||||
lng = cleaned_data.get("lng")
|
||||
location = cleaned_data.get("location")
|
||||
|
||||
if lat and lng and not location:
|
||||
cleaned_data['location'] = f"{lat}, {lng}"
|
||||
|
||||
return cleaned_data
|
||||
cleaned_data["location"] = f"{lat}, {lng}"
|
||||
|
||||
return cleaned_data
|
||||
|
||||
Reference in New Issue
Block a user