mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-29 07:47:01 -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:
@@ -1,8 +1,8 @@
|
||||
import json
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import User
|
||||
|
||||
|
||||
class UserExportService:
|
||||
"""Service for exporting all user data."""
|
||||
|
||||
@@ -10,18 +10,18 @@ class UserExportService:
|
||||
def export_user_data(user: User) -> dict:
|
||||
"""
|
||||
Export all data associated with a user or an object containing counts/metadata and actual data.
|
||||
|
||||
|
||||
Args:
|
||||
user: The user to export data for
|
||||
|
||||
|
||||
Returns:
|
||||
dict: The complete user data export
|
||||
"""
|
||||
# Import models locally to avoid circular imports
|
||||
from apps.lists.models import UserList
|
||||
from apps.parks.models import ParkReview
|
||||
from apps.rides.models import RideReview
|
||||
from apps.lists.models import UserList
|
||||
|
||||
|
||||
# User account and profile
|
||||
user_data = {
|
||||
"username": user.username,
|
||||
@@ -32,7 +32,7 @@ class UserExportService:
|
||||
"is_active": user.is_active,
|
||||
"role": user.role,
|
||||
}
|
||||
|
||||
|
||||
profile_data = {}
|
||||
if hasattr(user, "profile"):
|
||||
profile = user.profile
|
||||
@@ -60,11 +60,11 @@ class UserExportService:
|
||||
park_reviews = list(ParkReview.objects.filter(user=user).values(
|
||||
"park__name", "rating", "review", "created_at", "updated_at", "is_published"
|
||||
))
|
||||
|
||||
|
||||
ride_reviews = list(RideReview.objects.filter(user=user).values(
|
||||
"ride__name", "rating", "review", "created_at", "updated_at", "is_published"
|
||||
))
|
||||
|
||||
|
||||
# Lists
|
||||
user_lists = []
|
||||
for user_list in UserList.objects.filter(user=user):
|
||||
@@ -75,7 +75,7 @@ class UserExportService:
|
||||
"created_at": user_list.created_at,
|
||||
"items": items
|
||||
})
|
||||
|
||||
|
||||
export_data = {
|
||||
"account": user_data,
|
||||
"profile": profile_data,
|
||||
@@ -90,5 +90,5 @@ class UserExportService:
|
||||
"version": "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return export_data
|
||||
|
||||
Reference in New Issue
Block a user