mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 06:51:08 -05:00
major changes, including tailwind v4
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from .querysets import get_base_park_queryset
|
||||
from search.mixins import HTMXFilterableMixin
|
||||
from reviews.models import Review
|
||||
from location.models import Location
|
||||
from core.mixins import HTMXFilterableMixin
|
||||
from .models.location import ParkLocation
|
||||
from media.models import Photo
|
||||
from moderation.models import EditSubmission
|
||||
from moderation.mixins import EditSubmissionMixin, PhotoSubmissionMixin, HistoryMixin
|
||||
@@ -375,20 +374,22 @@ class ParkCreateView(LoginRequiredMixin, CreateView):
|
||||
if form.cleaned_data.get("latitude") and form.cleaned_data.get(
|
||||
"longitude"
|
||||
):
|
||||
Location.objects.create(
|
||||
content_type=ContentType.objects.get_for_model(Park),
|
||||
object_id=self.object.id,
|
||||
name=self.object.name,
|
||||
location_type="park",
|
||||
latitude=form.cleaned_data["latitude"],
|
||||
longitude=form.cleaned_data["longitude"],
|
||||
street_address=form.cleaned_data.get(
|
||||
"street_address", ""),
|
||||
city=form.cleaned_data.get("city", ""),
|
||||
state=form.cleaned_data.get("state", ""),
|
||||
country=form.cleaned_data.get("country", ""),
|
||||
postal_code=form.cleaned_data.get("postal_code", ""),
|
||||
# Create or update ParkLocation
|
||||
park_location, created = ParkLocation.objects.get_or_create(
|
||||
park=self.object,
|
||||
defaults={
|
||||
'street_address': form.cleaned_data.get("street_address", ""),
|
||||
'city': form.cleaned_data.get("city", ""),
|
||||
'state': form.cleaned_data.get("state", ""),
|
||||
'country': form.cleaned_data.get("country", "USA"),
|
||||
'postal_code': form.cleaned_data.get("postal_code", ""),
|
||||
}
|
||||
)
|
||||
park_location.set_coordinates(
|
||||
form.cleaned_data["latitude"],
|
||||
form.cleaned_data["longitude"]
|
||||
)
|
||||
park_location.save()
|
||||
|
||||
photos = self.request.FILES.getlist("photos")
|
||||
uploaded_count = 0
|
||||
@@ -507,17 +508,50 @@ class ParkUpdateView(LoginRequiredMixin, UpdateView):
|
||||
"postal_code": form.cleaned_data.get("postal_code", ""),
|
||||
}
|
||||
|
||||
if self.object.location.exists():
|
||||
location = self.object.location.first()
|
||||
# Create or update ParkLocation
|
||||
try:
|
||||
park_location = self.object.location
|
||||
# Update existing location
|
||||
for key, value in location_data.items():
|
||||
setattr(location, key, value)
|
||||
location.save()
|
||||
else:
|
||||
Location.objects.create(
|
||||
content_type=ContentType.objects.get_for_model(Park),
|
||||
object_id=self.object.id,
|
||||
**location_data,
|
||||
if key in ['latitude', 'longitude'] and value:
|
||||
continue # Handle coordinates separately
|
||||
if hasattr(park_location, key):
|
||||
setattr(park_location, key, value)
|
||||
|
||||
# Handle coordinates if provided
|
||||
if 'latitude' in location_data and 'longitude' in location_data:
|
||||
if location_data['latitude'] and location_data['longitude']:
|
||||
park_location.set_coordinates(
|
||||
float(location_data['latitude']),
|
||||
float(location_data['longitude'])
|
||||
)
|
||||
park_location.save()
|
||||
except ParkLocation.DoesNotExist:
|
||||
# Create new ParkLocation
|
||||
coordinates_data = {}
|
||||
if 'latitude' in location_data and 'longitude' in location_data:
|
||||
if location_data['latitude'] and location_data['longitude']:
|
||||
coordinates_data = {
|
||||
'latitude': float(location_data['latitude']),
|
||||
'longitude': float(location_data['longitude'])
|
||||
}
|
||||
|
||||
# Remove coordinate fields from location_data for creation
|
||||
creation_data = {k: v for k, v in location_data.items()
|
||||
if k not in ['latitude', 'longitude']}
|
||||
creation_data.setdefault('country', 'USA')
|
||||
|
||||
park_location = ParkLocation.objects.create(
|
||||
park=self.object,
|
||||
**creation_data
|
||||
)
|
||||
|
||||
if coordinates_data:
|
||||
park_location.set_coordinates(
|
||||
coordinates_data['latitude'],
|
||||
coordinates_data['longitude']
|
||||
)
|
||||
park_location.save()
|
||||
|
||||
photos = self.request.FILES.getlist("photos")
|
||||
uploaded_count = 0
|
||||
|
||||
Reference in New Issue
Block a user