Refactor code structure and remove redundant changes

This commit is contained in:
pacnpal
2025-08-26 13:19:04 -04:00
parent bf7e0c0f40
commit 831be6a2ee
151 changed files with 16260 additions and 9137 deletions

View File

@@ -109,7 +109,7 @@ class EditSubmission(TrackedModel):
and value is not None
):
if related_model := field.related_model:
resolved_data[field_name] = related_model.objects.get(id=value)
resolved_data[field_name] = related_model.objects.get(pk=value)
except (FieldDoesNotExist, ObjectDoesNotExist):
continue
@@ -141,7 +141,9 @@ class EditSubmission(TrackedModel):
"""Check if an object with the same name already exists"""
try:
return model_class.objects.filter(name=name).first()
except BaseException:
except BaseException as e:
print(f"Error checking for duplicate name '{name}': {e}")
raise e
return None
def approve(self, user: UserType) -> Optional[models.Model]:
@@ -172,7 +174,7 @@ class EditSubmission(TrackedModel):
self.notes = f"A {
model_class.__name__} with the name '{
prepared_data['name']}' already exists (ID: {
existing_obj.id})"
existing_obj.pk})"
self.save()
raise ValueError(self.notes)
@@ -283,18 +285,27 @@ class PhotoSubmission(TrackedModel):
def approve(self, moderator: UserType, notes: str = "") -> None:
"""Approve the photo submission"""
from apps.media.models import Photo
from apps.parks.models.media import ParkPhoto
from apps.rides.models.media import RidePhoto
self.status = "APPROVED"
self.handled_by = moderator # type: ignore
self.handled_at = timezone.now()
self.notes = notes
# Determine the correct photo model based on the content type
model_class = self.content_type.model_class()
if model_class.__name__ == "Park":
PhotoModel = ParkPhoto
elif model_class.__name__ == "Ride":
PhotoModel = RidePhoto
else:
raise ValueError(f"Unsupported content type: {model_class.__name__}")
# Create the approved photo
Photo.objects.create(
PhotoModel.objects.create(
uploaded_by=self.user,
content_type=self.content_type,
object_id=self.object_id,
content_object=self.content_object,
image=self.photo,
caption=self.caption,
is_approved=True,