mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-30 08:27:00 -05:00
feat: Implement MFA authentication, add ride statistics model, and update various services, APIs, and tests across the application.
This commit is contained in:
@@ -5,13 +5,14 @@ This command provides insights into transition usage, patterns, and statistics
|
||||
across all models using django-fsm-log.
|
||||
"""
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Count, Avg, F
|
||||
from django.db.models.functions import TruncDate, ExtractHour
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from django_fsm_log.models import StateLog
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Count
|
||||
from django.db.models.functions import ExtractHour, TruncDate
|
||||
from django.utils import timezone
|
||||
from django_fsm_log.models import StateLog
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -143,7 +144,7 @@ class Command(BaseCommand):
|
||||
# System vs User transitions
|
||||
system_count = queryset.filter(by__isnull=True).count()
|
||||
user_count = queryset.exclude(by__isnull=True).count()
|
||||
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('\n--- Transition Attribution ---'))
|
||||
self.stdout.write(f" User-initiated: {user_count} ({(user_count/total_transitions)*100:.1f}%)")
|
||||
self.stdout.write(f" System-initiated: {system_count} ({(system_count/total_transitions)*100:.1f}%)")
|
||||
@@ -181,7 +182,7 @@ class Command(BaseCommand):
|
||||
# Transition patterns (common sequences)
|
||||
self.stdout.write(self.style.SUCCESS('\n--- Common Transition Patterns ---'))
|
||||
self.stdout.write(' Analyzing transition sequences...')
|
||||
|
||||
|
||||
# Get recent objects and their transition sequences
|
||||
recent_objects = (
|
||||
queryset.values('content_type', 'object_id')
|
||||
@@ -198,7 +199,7 @@ class Command(BaseCommand):
|
||||
.order_by('timestamp')
|
||||
.values_list('transition', flat=True)
|
||||
)
|
||||
|
||||
|
||||
# Create pattern from consecutive transitions
|
||||
if len(transitions) >= 2:
|
||||
pattern = ' → '.join([t or 'N/A' for t in transitions[:3]])
|
||||
@@ -215,7 +216,7 @@ class Command(BaseCommand):
|
||||
self.stdout.write(f" {pattern}: {count} occurrences")
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'\n=== Analysis Complete ===\n')
|
||||
self.style.SUCCESS('\n=== Analysis Complete ===\n')
|
||||
)
|
||||
|
||||
# Export options
|
||||
@@ -228,7 +229,7 @@ class Command(BaseCommand):
|
||||
"""Export analysis results as JSON."""
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
data = {
|
||||
'analysis_date': datetime.now().isoformat(),
|
||||
'period_days': days,
|
||||
@@ -240,11 +241,11 @@ class Command(BaseCommand):
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
filename = f'transition_analysis_{datetime.now().strftime("%Y%m%d_%H%M%S")}.json'
|
||||
with open(filename, 'w') as f:
|
||||
json.dump(data, f, indent=2, default=str)
|
||||
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'Exported to {filename}')
|
||||
)
|
||||
@@ -253,16 +254,16 @@ class Command(BaseCommand):
|
||||
"""Export analysis results as CSV."""
|
||||
import csv
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
filename = f'transition_analysis_{datetime.now().strftime("%Y%m%d_%H%M%S")}.csv'
|
||||
|
||||
|
||||
with open(filename, 'w', newline='') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow([
|
||||
'ID', 'Timestamp', 'Model', 'Object ID',
|
||||
'State', 'Transition', 'User'
|
||||
])
|
||||
|
||||
|
||||
for log in queryset.select_related('content_type', 'by'):
|
||||
writer.writerow([
|
||||
log.id,
|
||||
@@ -273,7 +274,7 @@ class Command(BaseCommand):
|
||||
log.transition or 'N/A',
|
||||
log.by.username if log.by else 'System'
|
||||
])
|
||||
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'Exported to {filename}')
|
||||
)
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from datetime import date
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.moderation.models import EditSubmission, PhotoSubmission
|
||||
from apps.parks.models import Park
|
||||
from apps.rides.models import Ride
|
||||
from datetime import date
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
"""Management command to validate state machine configurations for moderation models."""
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management import CommandError
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.core.state_machine import MetadataValidator
|
||||
from apps.moderation.models import (
|
||||
EditSubmission,
|
||||
ModerationReport,
|
||||
ModerationQueue,
|
||||
BulkOperation,
|
||||
EditSubmission,
|
||||
ModerationQueue,
|
||||
ModerationReport,
|
||||
PhotoSubmission,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user