mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 04:51:13 -05:00
Add ReviewEvent model and ReviewSubmissionService for review management
- Created a new ReviewEvent model to track review events with fields for content, rating, moderation status, and timestamps. - Added ForeignKey relationships to connect ReviewEvent with ContentSubmission, User, and Review. - Implemented ReviewSubmissionService to handle review submissions, including creation, updates, and moderation workflows. - Introduced atomic transactions to ensure data integrity during review submissions and updates. - Added logging for review submission and moderation actions for better traceability. - Implemented validation to prevent duplicate reviews and ensure only the review owner can update their review.
This commit is contained in:
@@ -34,39 +34,15 @@ class BaseModel(LifecycleModel, TimeStampedModel):
|
||||
|
||||
class VersionedModel(DirtyFieldsMixin, BaseModel):
|
||||
"""
|
||||
Abstract base model for entities that need version tracking.
|
||||
Abstract base model for entities that track field changes.
|
||||
|
||||
Automatically creates a version record whenever the model is created or updated.
|
||||
Uses DirtyFieldsMixin to track which fields changed.
|
||||
History tracking is now handled automatically by pghistory decorators.
|
||||
|
||||
Note: This class is kept for backwards compatibility and the DirtyFieldsMixin
|
||||
functionality, but no longer triggers custom versioning.
|
||||
"""
|
||||
|
||||
@hook(AFTER_CREATE)
|
||||
def create_version_on_create(self):
|
||||
"""Create initial version when entity is created"""
|
||||
self._create_version('created')
|
||||
|
||||
@hook(AFTER_UPDATE)
|
||||
def create_version_on_update(self):
|
||||
"""Create version when entity is updated"""
|
||||
if self.get_dirty_fields():
|
||||
self._create_version('updated')
|
||||
|
||||
def _create_version(self, change_type):
|
||||
"""
|
||||
Create a version record for this entity.
|
||||
Deferred import to avoid circular dependencies.
|
||||
"""
|
||||
try:
|
||||
from apps.versioning.services import VersionService
|
||||
VersionService.create_version(
|
||||
entity=self,
|
||||
change_type=change_type,
|
||||
changed_fields=self.get_dirty_fields() if change_type == 'updated' else {}
|
||||
)
|
||||
except ImportError:
|
||||
# Versioning app not yet available (e.g., during initial migrations)
|
||||
pass
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user