mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 10:31:09 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user