mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-22 23:51:09 -05:00
- 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.
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
"""
|
|
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
|