mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 11:31:07 -05:00
major changes, including tailwind v4
This commit is contained in:
@@ -1,14 +1,26 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.contenttypes.admin import GenericTabularInline
|
||||
from .models import Location
|
||||
|
||||
# DEPRECATED: This admin interface is deprecated.
|
||||
# Location data has been migrated to domain-specific models:
|
||||
# - ParkLocation in parks.models.location
|
||||
# - RideLocation in rides.models.location
|
||||
# - CompanyHeadquarters in parks.models.companies
|
||||
#
|
||||
# This admin interface is kept for data migration and cleanup purposes only.
|
||||
|
||||
@admin.register(Location)
|
||||
class LocationAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'location_type', 'city', 'state', 'country')
|
||||
list_display = ('name', 'location_type', 'city', 'state', 'country', 'created_at')
|
||||
list_filter = ('location_type', 'country', 'state', 'city')
|
||||
search_fields = ('name', 'street_address', 'city', 'state', 'country')
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
readonly_fields = ('created_at', 'updated_at', 'content_type', 'object_id')
|
||||
|
||||
fieldsets = (
|
||||
('⚠️ DEPRECATED MODEL', {
|
||||
'description': 'This model is deprecated. Use domain-specific location models instead.',
|
||||
'fields': (),
|
||||
}),
|
||||
('Basic Information', {
|
||||
'fields': ('name', 'location_type')
|
||||
}),
|
||||
@@ -18,8 +30,9 @@ class LocationAdmin(admin.ModelAdmin):
|
||||
('Address', {
|
||||
'fields': ('street_address', 'city', 'state', 'country', 'postal_code')
|
||||
}),
|
||||
('Content Type', {
|
||||
'fields': ('content_type', 'object_id')
|
||||
('Content Type (Read Only)', {
|
||||
'fields': ('content_type', 'object_id'),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
('Metadata', {
|
||||
'fields': ('created_at', 'updated_at'),
|
||||
@@ -29,3 +42,7 @@ class LocationAdmin(admin.ModelAdmin):
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super().get_queryset(request).select_related('content_type')
|
||||
|
||||
def has_add_permission(self, request):
|
||||
# Prevent creating new generic Location objects
|
||||
return False
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
# DEPRECATED: These forms are deprecated and no longer used.
|
||||
#
|
||||
# Domain-specific location models now have their own forms:
|
||||
# - ParkLocationForm in parks.forms (for ParkLocation)
|
||||
# - RideLocationForm in rides.forms (for RideLocation)
|
||||
# - CompanyHeadquartersForm in parks.forms (for CompanyHeadquarters)
|
||||
#
|
||||
# This file is kept for reference during migration cleanup only.
|
||||
|
||||
from django import forms
|
||||
from .models import Location
|
||||
|
||||
# NOTE: All classes below are DEPRECATED
|
||||
# Use domain-specific location forms instead
|
||||
|
||||
class LocationForm(forms.ModelForm):
|
||||
"""Form for creating and updating Location objects"""
|
||||
"""DEPRECATED: Use domain-specific location forms instead"""
|
||||
|
||||
class Meta:
|
||||
model = Location
|
||||
fields = [
|
||||
'name',
|
||||
'location_type',
|
||||
'location_type',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'street_address',
|
||||
@@ -17,63 +29,12 @@ class LocationForm(forms.ModelForm):
|
||||
'country',
|
||||
'postal_code',
|
||||
]
|
||||
widgets = {
|
||||
'latitude': forms.NumberInput(attrs={
|
||||
'step': 'any',
|
||||
'class': 'location-lat',
|
||||
'data-map-target': 'lat'
|
||||
}),
|
||||
'longitude': forms.NumberInput(attrs={
|
||||
'step': 'any',
|
||||
'class': 'location-lng',
|
||||
'data-map-target': 'lng'
|
||||
})
|
||||
}
|
||||
|
||||
class LocationSearchForm(forms.Form):
|
||||
"""Form for searching locations using OpenStreetMap Nominatim"""
|
||||
"""DEPRECATED: Location search functionality has been moved to parks app"""
|
||||
|
||||
query = forms.CharField(
|
||||
max_length=255,
|
||||
required=True,
|
||||
widget=forms.TextInput(attrs={
|
||||
'placeholder': 'Search for a location...',
|
||||
'class': 'location-search',
|
||||
'data-action': 'search#query',
|
||||
'autocomplete': 'off'
|
||||
})
|
||||
)
|
||||
|
||||
# Hidden fields for storing selected location data
|
||||
selected_lat = forms.DecimalField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(attrs={'data-search-target': 'selectedLat'})
|
||||
)
|
||||
selected_lng = forms.DecimalField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(attrs={'data-search-target': 'selectedLng'})
|
||||
)
|
||||
selected_name = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(attrs={'data-search-target': 'selectedName'})
|
||||
)
|
||||
selected_address = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(attrs={'data-search-target': 'selectedAddress'})
|
||||
)
|
||||
selected_city = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(attrs={'data-search-target': 'selectedCity'})
|
||||
)
|
||||
selected_state = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(attrs={'data-search-target': 'selectedState'})
|
||||
)
|
||||
selected_country = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(attrs={'data-search-target': 'selectedCountry'})
|
||||
)
|
||||
selected_postal_code = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(attrs={'data-search-target': 'selectedPostalCode'})
|
||||
help_text="This form is deprecated. Use location search in the parks app."
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Generated by Django 5.1.4 on 2025-02-10 01:10
|
||||
# Generated by Django 5.1.4 on 2025-08-13 21:35
|
||||
|
||||
import django.contrib.gis.db.models.fields
|
||||
import django.core.validators
|
||||
@@ -21,7 +21,15 @@ class Migration(migrations.Migration):
|
||||
migrations.CreateModel(
|
||||
name="Location",
|
||||
fields=[
|
||||
("id", models.BigAutoField(primary_key=True, serialize=False)),
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("object_id", models.PositiveIntegerField()),
|
||||
(
|
||||
"name",
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# Generated by Django 5.1.4 on 2025-02-21 17:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("location", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="location",
|
||||
name="id",
|
||||
field=models.BigAutoField(
|
||||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -5,7 +5,7 @@ from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
from django.contrib.gis.geos import Point
|
||||
import pghistory
|
||||
from history_tracking.models import TrackedModel
|
||||
from core.history import TrackedModel
|
||||
|
||||
@pghistory.track()
|
||||
class Location(TrackedModel):
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.contrib.gis.measure import D
|
||||
from .models import Location
|
||||
from operators.models import Operator
|
||||
from parks.models.companies import Operator
|
||||
from parks.models import Park
|
||||
|
||||
class LocationModelTests(TestCase):
|
||||
|
||||
@@ -1,11 +1,32 @@
|
||||
# DEPRECATED: These URLs are deprecated and no longer used.
|
||||
#
|
||||
# Location search functionality has been moved to the parks app:
|
||||
# - /parks/search/location/ (replaces /location/search/)
|
||||
# - /parks/search/reverse-geocode/ (replaces /location/reverse-geocode/)
|
||||
#
|
||||
# Domain-specific location models are managed through their respective apps:
|
||||
# - Parks app for ParkLocation
|
||||
# - Rides app for RideLocation
|
||||
# - Parks app for CompanyHeadquarters
|
||||
#
|
||||
# This file is kept for reference during migration cleanup only.
|
||||
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = 'location'
|
||||
|
||||
# NOTE: All URLs below are DEPRECATED
|
||||
# The location app URLs should not be included in the main URLconf
|
||||
|
||||
urlpatterns = [
|
||||
# DEPRECATED: Use /parks/search/location/ instead
|
||||
path('search/', views.LocationSearchView.as_view(), name='search'),
|
||||
|
||||
# DEPRECATED: Use /parks/search/reverse-geocode/ instead
|
||||
path('reverse-geocode/', views.reverse_geocode, name='reverse_geocode'),
|
||||
|
||||
# DEPRECATED: Use domain-specific location models instead
|
||||
path('create/', views.LocationCreateView.as_view(), name='create'),
|
||||
path('<int:pk>/update/', views.LocationUpdateView.as_view(), name='update'),
|
||||
path('<int:pk>/delete/', views.LocationDeleteView.as_view(), name='delete'),
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
# DEPRECATED: These views are deprecated and no longer used.
|
||||
#
|
||||
# Location search functionality has been moved to the parks app:
|
||||
# - parks.views.location_search
|
||||
# - parks.views.reverse_geocode
|
||||
#
|
||||
# Domain-specific location models are now used instead of the generic Location model:
|
||||
# - ParkLocation in parks.models.location
|
||||
# - RideLocation in rides.models.location
|
||||
# - CompanyHeadquarters in parks.models.companies
|
||||
#
|
||||
# This file is kept for reference during migration cleanup only.
|
||||
|
||||
import json
|
||||
import requests
|
||||
from django.views.generic import View
|
||||
@@ -13,190 +26,26 @@ from django.db.models import Q
|
||||
from location.forms import LocationForm
|
||||
from .models import Location
|
||||
|
||||
# NOTE: All classes and functions below are DEPRECATED
|
||||
# Use the equivalent functionality in the parks app instead
|
||||
|
||||
class LocationSearchView(View):
|
||||
"""
|
||||
View for searching locations using OpenStreetMap Nominatim.
|
||||
Returns search results in JSON format.
|
||||
"""
|
||||
|
||||
@method_decorator(csrf_protect)
|
||||
def get(self, request, *args, **kwargs):
|
||||
query = request.GET.get('q', '').strip()
|
||||
filter_type = request.GET.get('type', '') # country, state, city
|
||||
filter_parks = request.GET.get('filter_parks', 'false') == 'true'
|
||||
|
||||
if not query:
|
||||
return JsonResponse({'results': []})
|
||||
|
||||
# Check cache first
|
||||
cache_key = f'location_search_{query}_{filter_type}_{filter_parks}'
|
||||
cached_results = cache.get(cache_key)
|
||||
if cached_results:
|
||||
return JsonResponse({'results': cached_results})
|
||||
|
||||
# Search OpenStreetMap
|
||||
try:
|
||||
params = {
|
||||
'q': query,
|
||||
'format': 'json',
|
||||
'addressdetails': 1,
|
||||
'limit': 10
|
||||
}
|
||||
|
||||
# Add type-specific filters
|
||||
if filter_type == 'country':
|
||||
params['featuretype'] = 'country'
|
||||
elif filter_type == 'state':
|
||||
params['featuretype'] = 'state'
|
||||
elif filter_type == 'city':
|
||||
params['featuretype'] = 'city'
|
||||
|
||||
response = requests.get(
|
||||
'https://nominatim.openstreetmap.org/search',
|
||||
params=params,
|
||||
headers={'User-Agent': 'ThrillWiki/1.0'},
|
||||
timeout=60)
|
||||
response.raise_for_status()
|
||||
results = response.json()
|
||||
except requests.RequestException as e:
|
||||
return JsonResponse({
|
||||
'error': 'Failed to fetch location data',
|
||||
'details': str(e)
|
||||
}, status=500)
|
||||
|
||||
# Process and format results
|
||||
formatted_results = []
|
||||
for result in results:
|
||||
address = result.get('address', {})
|
||||
formatted_result = {
|
||||
'name': result.get('display_name', ''),
|
||||
'lat': result.get('lat'),
|
||||
'lon': result.get('lon'),
|
||||
'type': result.get('type', ''),
|
||||
'address': {
|
||||
'street': address.get('road', ''),
|
||||
'house_number': address.get('house_number', ''),
|
||||
'city': address.get('city', '') or address.get('town', '') or address.get('village', ''),
|
||||
'state': address.get('state', ''),
|
||||
'country': address.get('country', ''),
|
||||
'postcode': address.get('postcode', '')
|
||||
}
|
||||
}
|
||||
|
||||
# If filtering by parks, only include results that have parks
|
||||
if filter_parks:
|
||||
location_exists = Location.objects.filter(
|
||||
Q(country__icontains=formatted_result['address']['country']) &
|
||||
(Q(state__icontains=formatted_result['address']['state']) if formatted_result['address']['state'] else Q()) &
|
||||
(Q(city__icontains=formatted_result['address']['city']) if formatted_result['address']['city'] else Q())
|
||||
).exists()
|
||||
if not location_exists:
|
||||
continue
|
||||
|
||||
formatted_results.append(formatted_result)
|
||||
|
||||
# Cache results for 1 hour
|
||||
cache.set(cache_key, formatted_results, 3600)
|
||||
|
||||
return JsonResponse({'results': formatted_results})
|
||||
"""DEPRECATED: Use parks.views.location_search instead"""
|
||||
pass
|
||||
|
||||
class LocationCreateView(LoginRequiredMixin, View):
|
||||
"""View for creating new Location objects"""
|
||||
|
||||
@method_decorator(csrf_protect)
|
||||
def post(self, request, *args, **kwargs):
|
||||
form = LocationForm(request.POST)
|
||||
if form.is_valid():
|
||||
location = form.save()
|
||||
return JsonResponse({
|
||||
'id': location.id,
|
||||
'name': location.name,
|
||||
'formatted_address': location.get_formatted_address(),
|
||||
'coordinates': location.coordinates
|
||||
})
|
||||
return JsonResponse({'errors': form.errors}, status=400)
|
||||
"""DEPRECATED: Use domain-specific location models instead"""
|
||||
pass
|
||||
|
||||
class LocationUpdateView(LoginRequiredMixin, View):
|
||||
"""View for updating existing Location objects"""
|
||||
|
||||
@method_decorator(csrf_protect)
|
||||
def post(self, request, *args, **kwargs):
|
||||
location = Location.objects.get(pk=kwargs['pk'])
|
||||
form = LocationForm(request.POST, instance=location)
|
||||
if form.is_valid():
|
||||
location = form.save()
|
||||
return JsonResponse({
|
||||
'id': location.id,
|
||||
'name': location.name,
|
||||
'formatted_address': location.get_formatted_address(),
|
||||
'coordinates': location.coordinates
|
||||
})
|
||||
return JsonResponse({'errors': form.errors}, status=400)
|
||||
"""DEPRECATED: Use domain-specific location models instead"""
|
||||
pass
|
||||
|
||||
class LocationDeleteView(LoginRequiredMixin, View):
|
||||
"""View for deleting Location objects"""
|
||||
|
||||
@method_decorator(csrf_protect)
|
||||
def post(self, request, *args, **kwargs):
|
||||
try:
|
||||
location = Location.objects.get(pk=kwargs['pk'])
|
||||
location.delete()
|
||||
return JsonResponse({'status': 'success'})
|
||||
except Location.DoesNotExist:
|
||||
return JsonResponse({'error': 'Location not found'}, status=404)
|
||||
"""DEPRECATED: Use domain-specific location models instead"""
|
||||
pass
|
||||
|
||||
@require_http_methods(["GET"])
|
||||
def reverse_geocode(request):
|
||||
"""
|
||||
View for reverse geocoding coordinates to address using OpenStreetMap.
|
||||
Returns address details in JSON format.
|
||||
"""
|
||||
lat = request.GET.get('lat')
|
||||
lon = request.GET.get('lon')
|
||||
|
||||
if not lat or not lon:
|
||||
return JsonResponse({'error': 'Latitude and longitude are required'}, status=400)
|
||||
|
||||
# Check cache first
|
||||
cache_key = f'reverse_geocode_{lat}_{lon}'
|
||||
cached_result = cache.get(cache_key)
|
||||
if cached_result:
|
||||
return JsonResponse(cached_result)
|
||||
|
||||
try:
|
||||
response = requests.get(
|
||||
'https://nominatim.openstreetmap.org/reverse',
|
||||
params={
|
||||
'lat': lat,
|
||||
'lon': lon,
|
||||
'format': 'json',
|
||||
'addressdetails': 1
|
||||
},
|
||||
headers={'User-Agent': 'ThrillWiki/1.0'},
|
||||
timeout=60)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
|
||||
address = result.get('address', {})
|
||||
formatted_result = {
|
||||
'name': result.get('display_name', ''),
|
||||
'address': {
|
||||
'street': address.get('road', ''),
|
||||
'house_number': address.get('house_number', ''),
|
||||
'city': address.get('city', '') or address.get('town', '') or address.get('village', ''),
|
||||
'state': address.get('state', ''),
|
||||
'country': address.get('country', ''),
|
||||
'postcode': address.get('postcode', '')
|
||||
}
|
||||
}
|
||||
|
||||
# Cache result for 1 day
|
||||
cache.set(cache_key, formatted_result, 86400)
|
||||
|
||||
return JsonResponse(formatted_result)
|
||||
|
||||
except requests.RequestException as e:
|
||||
return JsonResponse({
|
||||
'error': 'Failed to fetch address data',
|
||||
'details': str(e)
|
||||
}, status=500)
|
||||
"""DEPRECATED: Use parks.views.reverse_geocode instead"""
|
||||
return JsonResponse({'error': 'This endpoint is deprecated. Use /parks/search/reverse-geocode/ instead'}, status=410)
|
||||
|
||||
Reference in New Issue
Block a user