mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:31:08 -05:00
code commit
This commit is contained in:
@@ -15,7 +15,7 @@ UserType = Union[AbstractBaseUser, AnonymousUser]
|
||||
|
||||
class EditSubmission(models.Model):
|
||||
STATUS_CHOICES = [
|
||||
("NEW", "New"),
|
||||
("PENDING", "Pending"),
|
||||
("APPROVED", "Approved"),
|
||||
("REJECTED", "Rejected"),
|
||||
("ESCALATED", "Escalated"),
|
||||
@@ -49,13 +49,20 @@ class EditSubmission(models.Model):
|
||||
changes = models.JSONField(
|
||||
help_text="JSON representation of the changes or new object data"
|
||||
)
|
||||
|
||||
# Moderator's edited version of changes before approval
|
||||
moderator_changes = models.JSONField(
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Moderator's edited version of the changes before approval"
|
||||
)
|
||||
|
||||
# Metadata
|
||||
reason = models.TextField(help_text="Why this edit/addition is needed")
|
||||
source = models.TextField(
|
||||
blank=True, help_text="Source of information (if applicable)"
|
||||
)
|
||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="NEW")
|
||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="PENDING")
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
# Review details
|
||||
@@ -133,7 +140,10 @@ class EditSubmission(models.Model):
|
||||
raise ValueError("Could not resolve model class")
|
||||
|
||||
try:
|
||||
resolved_data = self._resolve_foreign_keys(self.changes)
|
||||
# Use moderator_changes if available, otherwise use original changes
|
||||
changes_to_apply = self.moderator_changes if self.moderator_changes is not None else self.changes
|
||||
|
||||
resolved_data = self._resolve_foreign_keys(changes_to_apply)
|
||||
prepared_data = self._prepare_model_data(resolved_data, model_class)
|
||||
|
||||
# For CREATE submissions, check for duplicates by name
|
||||
@@ -168,7 +178,7 @@ class EditSubmission(models.Model):
|
||||
return obj
|
||||
except Exception as e:
|
||||
if self.status != "REJECTED": # Don't override if already rejected due to duplicate
|
||||
self.status = "NEW" # Reset status if approval failed
|
||||
self.status = "PENDING" # Reset status if approval failed
|
||||
self.save()
|
||||
raise ValueError(f"Error approving submission: {str(e)}") from e
|
||||
|
||||
@@ -189,10 +199,10 @@ class EditSubmission(models.Model):
|
||||
|
||||
class PhotoSubmission(models.Model):
|
||||
STATUS_CHOICES = [
|
||||
("NEW", "New"),
|
||||
("PENDING", "Pending"),
|
||||
("APPROVED", "Approved"),
|
||||
("REJECTED", "Rejected"),
|
||||
("AUTO_APPROVED", "Auto Approved"),
|
||||
("ESCALATED", "Escalated"),
|
||||
]
|
||||
|
||||
# Who submitted the photo
|
||||
@@ -213,7 +223,7 @@ class PhotoSubmission(models.Model):
|
||||
date_taken = models.DateField(null=True, blank=True)
|
||||
|
||||
# Metadata
|
||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="NEW")
|
||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="PENDING")
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
# Review details
|
||||
@@ -268,22 +278,10 @@ class PhotoSubmission(models.Model):
|
||||
self.notes = notes
|
||||
self.save()
|
||||
|
||||
def auto_approve(self) -> None:
|
||||
"""Auto-approve the photo submission (for moderators/admins)"""
|
||||
from media.models import Photo
|
||||
|
||||
self.status = "AUTO_APPROVED"
|
||||
self.handled_by = self.user
|
||||
def escalate(self, moderator: UserType, notes: str = "") -> None:
|
||||
"""Escalate the photo submission to admin"""
|
||||
self.status = "ESCALATED"
|
||||
self.handled_by = moderator # type: ignore
|
||||
self.handled_at = timezone.now()
|
||||
|
||||
# Create the approved photo
|
||||
Photo.objects.create(
|
||||
uploaded_by=self.user,
|
||||
content_type=self.content_type,
|
||||
object_id=self.object_id,
|
||||
image=self.photo,
|
||||
caption=self.caption,
|
||||
is_approved=True,
|
||||
)
|
||||
|
||||
self.notes = notes
|
||||
self.save()
|
||||
|
||||
Reference in New Issue
Block a user