mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-24 21:31:09 -05:00
feat: Refactor rides app with unique constraints, mixins, and enhanced documentation
- Added migration to convert unique_together constraints to UniqueConstraint for RideModel. - Introduced RideFormMixin for handling entity suggestions in ride forms. - Created comprehensive code standards documentation outlining formatting, docstring requirements, complexity guidelines, and testing requirements. - Established error handling guidelines with a structured exception hierarchy and best practices for API and view error handling. - Documented view pattern guidelines, emphasizing the use of CBVs, FBVs, and ViewSets with examples. - Implemented a benchmarking script for query performance analysis and optimization. - Developed security documentation detailing measures, configurations, and a security checklist. - Compiled a database optimization guide covering indexing strategies, query optimization patterns, and computed fields.
This commit is contained in:
49
backend/apps/rides/mixins.py
Normal file
49
backend/apps/rides/mixins.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
Mixins for ride views.
|
||||
|
||||
This module contains mixins that provide reusable functionality
|
||||
for ride-related views, reducing code duplication.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.contrib import messages
|
||||
|
||||
from apps.rides.services import RideService
|
||||
|
||||
|
||||
class RideFormMixin:
|
||||
"""
|
||||
Mixin for handling ride form submissions with entity suggestions.
|
||||
|
||||
Provides common functionality for RideCreateView and RideUpdateView
|
||||
to handle new manufacturer, designer, and ride model suggestions.
|
||||
"""
|
||||
|
||||
def handle_entity_suggestions(self, form) -> Dict[str, Any]:
|
||||
"""
|
||||
Process new entity suggestions from form.
|
||||
|
||||
Creates moderation submissions for any new manufacturers,
|
||||
designers, or ride models that were suggested but don't
|
||||
exist in the system.
|
||||
|
||||
Args:
|
||||
form: Validated form instance with cleaned_data
|
||||
|
||||
Returns:
|
||||
Dictionary with submission results from RideService
|
||||
"""
|
||||
result = RideService.handle_new_entity_suggestions(
|
||||
form_data=form.cleaned_data,
|
||||
submitter=self.request.user
|
||||
)
|
||||
|
||||
if result['total_submissions'] > 0:
|
||||
messages.info(
|
||||
self.request,
|
||||
f"Created {result['total_submissions']} moderation submission(s) "
|
||||
"for new entities"
|
||||
)
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user