mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-30 04:47: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:
@@ -1,16 +1,18 @@
|
||||
from typing import Any, Dict, Optional, Type, cast
|
||||
import json
|
||||
from typing import Any, cast
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.http import (
|
||||
JsonResponse,
|
||||
HttpResponseForbidden,
|
||||
HttpRequest,
|
||||
HttpResponse,
|
||||
HttpResponseForbidden,
|
||||
JsonResponse,
|
||||
)
|
||||
from django.views.generic import DetailView
|
||||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
import json
|
||||
|
||||
from .models import EditSubmission, PhotoSubmission, UserType
|
||||
|
||||
User = get_user_model()
|
||||
@@ -21,12 +23,12 @@ class EditSubmissionMixin(DetailView):
|
||||
Mixin for handling edit submissions with proper moderation.
|
||||
"""
|
||||
|
||||
model: Optional[Type[models.Model]] = None
|
||||
model: type[models.Model] | None = None
|
||||
|
||||
def handle_edit_submission(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
changes: Dict[str, Any],
|
||||
changes: dict[str, Any],
|
||||
reason: str = "",
|
||||
source: str = "",
|
||||
submission_type: str = "EDIT",
|
||||
@@ -148,7 +150,7 @@ class PhotoSubmissionMixin(DetailView):
|
||||
Mixin for handling photo submissions with proper moderation.
|
||||
"""
|
||||
|
||||
model: Optional[Type[models.Model]] = None
|
||||
model: type[models.Model] | None = None
|
||||
|
||||
def handle_photo_submission(self, request: HttpRequest) -> JsonResponse:
|
||||
"""Handle a photo submission based on user's role"""
|
||||
@@ -214,7 +216,7 @@ class PhotoSubmissionMixin(DetailView):
|
||||
class ModeratorRequiredMixin(UserPassesTestMixin):
|
||||
"""Require moderator or higher role for access"""
|
||||
|
||||
request: Optional[HttpRequest] = None
|
||||
request: HttpRequest | None = None
|
||||
|
||||
def test_func(self) -> bool:
|
||||
if not self.request:
|
||||
@@ -235,7 +237,7 @@ class ModeratorRequiredMixin(UserPassesTestMixin):
|
||||
class AdminRequiredMixin(UserPassesTestMixin):
|
||||
"""Require admin or superuser role for access"""
|
||||
|
||||
request: Optional[HttpRequest] = None
|
||||
request: HttpRequest | None = None
|
||||
|
||||
def test_func(self) -> bool:
|
||||
if not self.request:
|
||||
@@ -255,9 +257,9 @@ class AdminRequiredMixin(UserPassesTestMixin):
|
||||
class InlineEditMixin:
|
||||
"""Add inline editing context to views"""
|
||||
|
||||
request: Optional[HttpRequest] = None
|
||||
request: HttpRequest | None = None
|
||||
|
||||
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
|
||||
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
||||
context = super().get_context_data(**kwargs) # type: ignore
|
||||
if self.request and self.request.user.is_authenticated:
|
||||
context["can_edit"] = True
|
||||
@@ -285,7 +287,7 @@ class InlineEditMixin:
|
||||
class HistoryMixin:
|
||||
"""Add edit history context to views"""
|
||||
|
||||
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
|
||||
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
||||
context = super().get_context_data(**kwargs) # type: ignore
|
||||
|
||||
# Only add history context for DetailViews
|
||||
|
||||
Reference in New Issue
Block a user