mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 12:11:13 -05:00
- Added functions for checking user privileges, handling photo uploads, preparing form data, and managing form errors. - Created views for listing, creating, updating, and displaying rides, including category-specific views. - Integrated submission handling for ride changes and improved user feedback through messages. - Enhanced data handling with appropriate context and queryset management for better performance and usability.
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from django.utils.deprecation import MiddlewareMixin
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.views.generic.detail import DetailView
|
|
from .models import PageView
|
|
|
|
class PageViewMiddleware(MiddlewareMixin):
|
|
def process_view(self, request, view_func, view_args, view_kwargs):
|
|
# Only track GET requests
|
|
if request.method != 'GET':
|
|
return None
|
|
|
|
# Get view class if it exists
|
|
view_class = getattr(view_func, 'view_class', None)
|
|
if not view_class or not issubclass(view_class, DetailView):
|
|
return None
|
|
|
|
# Get the object if it's a detail view
|
|
try:
|
|
view_instance = view_class()
|
|
view_instance.request = request
|
|
view_instance.args = view_args
|
|
view_instance.kwargs = view_kwargs
|
|
obj = view_instance.get_object()
|
|
except (AttributeError, Exception):
|
|
return None
|
|
|
|
# Record the page view
|
|
try:
|
|
PageView.objects.create(
|
|
content_type=ContentType.objects.get_for_model(obj.__class__),
|
|
object_id=obj.pk,
|
|
ip_address=request.META.get('REMOTE_ADDR', ''),
|
|
user_agent=request.META.get('HTTP_USER_AGENT', '')[:512]
|
|
)
|
|
except Exception:
|
|
# Fail silently to not interrupt the request
|
|
pass
|
|
|
|
return None
|