mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 14:51:08 -05:00
code commit
This commit is contained in:
@@ -10,6 +10,10 @@ from typing import Optional, Any, cast
|
||||
from accounts.models import User
|
||||
|
||||
from .models import EditSubmission, PhotoSubmission
|
||||
from parks.models import Park, ParkArea
|
||||
from designers.models import Designer
|
||||
from companies.models import Manufacturer
|
||||
from rides.models import RideModel
|
||||
|
||||
MODERATOR_ROLES = ['MODERATOR', 'ADMIN', 'SUPERUSER']
|
||||
|
||||
@@ -29,6 +33,108 @@ class ModeratorRequiredMixin(UserPassesTestMixin):
|
||||
return super().handle_no_permission()
|
||||
raise PermissionDenied("You do not have moderator permissions.")
|
||||
|
||||
@login_required
|
||||
def search_parks(request: HttpRequest) -> HttpResponse:
|
||||
"""HTMX endpoint for searching parks in moderation dashboard"""
|
||||
user = cast(User, request.user)
|
||||
if not (user.role in MODERATOR_ROLES or user.is_superuser):
|
||||
return HttpResponse(status=403)
|
||||
|
||||
query = request.GET.get('q', '').strip()
|
||||
submission_id = request.GET.get('submission_id')
|
||||
|
||||
# If no query, show first 10 parks
|
||||
if not query:
|
||||
parks = Park.objects.all().order_by('name')[:10]
|
||||
else:
|
||||
parks = Park.objects.filter(name__icontains=query).order_by('name')[:10]
|
||||
|
||||
context = {
|
||||
'parks': parks,
|
||||
'search_term': query,
|
||||
'submission_id': submission_id
|
||||
}
|
||||
|
||||
return render(request, 'moderation/partials/park_search_results.html', context)
|
||||
|
||||
@login_required
|
||||
def search_manufacturers(request: HttpRequest) -> HttpResponse:
|
||||
"""HTMX endpoint for searching manufacturers in moderation dashboard"""
|
||||
user = cast(User, request.user)
|
||||
if not (user.role in MODERATOR_ROLES or user.is_superuser):
|
||||
return HttpResponse(status=403)
|
||||
|
||||
query = request.GET.get('q', '').strip()
|
||||
submission_id = request.GET.get('submission_id')
|
||||
|
||||
# If no query, show first 10 manufacturers
|
||||
if not query:
|
||||
manufacturers = Manufacturer.objects.all().order_by('name')[:10]
|
||||
else:
|
||||
manufacturers = Manufacturer.objects.filter(name__icontains=query).order_by('name')[:10]
|
||||
|
||||
context = {
|
||||
'manufacturers': manufacturers,
|
||||
'search_term': query,
|
||||
'submission_id': submission_id
|
||||
}
|
||||
|
||||
return render(request, 'moderation/partials/manufacturer_search_results.html', context)
|
||||
|
||||
@login_required
|
||||
def search_designers(request: HttpRequest) -> HttpResponse:
|
||||
"""HTMX endpoint for searching designers in moderation dashboard"""
|
||||
user = cast(User, request.user)
|
||||
if not (user.role in MODERATOR_ROLES or user.is_superuser):
|
||||
return HttpResponse(status=403)
|
||||
|
||||
query = request.GET.get('q', '').strip()
|
||||
submission_id = request.GET.get('submission_id')
|
||||
|
||||
# If no query, show first 10 designers
|
||||
if not query:
|
||||
designers = Designer.objects.all().order_by('name')[:10]
|
||||
else:
|
||||
designers = Designer.objects.filter(name__icontains=query).order_by('name')[:10]
|
||||
|
||||
context = {
|
||||
'designers': designers,
|
||||
'search_term': query,
|
||||
'submission_id': submission_id
|
||||
}
|
||||
|
||||
return render(request, 'moderation/partials/designer_search_results.html', context)
|
||||
|
||||
@login_required
|
||||
def search_ride_models(request: HttpRequest) -> HttpResponse:
|
||||
"""HTMX endpoint for searching ride models in moderation dashboard"""
|
||||
user = cast(User, request.user)
|
||||
if not (user.role in MODERATOR_ROLES or user.is_superuser):
|
||||
return HttpResponse(status=403)
|
||||
|
||||
query = request.GET.get('q', '').strip()
|
||||
submission_id = request.GET.get('submission_id')
|
||||
manufacturer_id = request.GET.get('manufacturer')
|
||||
|
||||
queryset = RideModel.objects.all()
|
||||
|
||||
if manufacturer_id:
|
||||
queryset = queryset.filter(manufacturer_id=manufacturer_id)
|
||||
|
||||
# If no query, show first 10 models
|
||||
if not query:
|
||||
ride_models = queryset.order_by('name')[:10]
|
||||
else:
|
||||
ride_models = queryset.filter(name__icontains=query).order_by('name')[:10]
|
||||
|
||||
context = {
|
||||
'ride_models': ride_models,
|
||||
'search_term': query,
|
||||
'submission_id': submission_id
|
||||
}
|
||||
|
||||
return render(request, 'moderation/partials/ride_model_search_results.html', context)
|
||||
|
||||
class DashboardView(LoginRequiredMixin, ModeratorRequiredMixin, ListView):
|
||||
template_name = 'moderation/dashboard.html'
|
||||
context_object_name = 'submissions'
|
||||
@@ -40,7 +146,7 @@ class DashboardView(LoginRequiredMixin, ModeratorRequiredMixin, ListView):
|
||||
return [self.template_name]
|
||||
|
||||
def get_queryset(self):
|
||||
status = self.request.GET.get('status', 'NEW')
|
||||
status = self.request.GET.get('status', 'PENDING')
|
||||
submission_type = self.request.GET.get('submission_type', '')
|
||||
|
||||
if submission_type == 'photo':
|
||||
@@ -63,7 +169,7 @@ def submission_list(request: HttpRequest) -> HttpResponse:
|
||||
if not (user.role in MODERATOR_ROLES or user.is_superuser):
|
||||
return HttpResponse(status=403)
|
||||
|
||||
status = request.GET.get('status', 'NEW')
|
||||
status = request.GET.get('status', 'PENDING')
|
||||
submission_type = request.GET.get('submission_type', '')
|
||||
|
||||
if submission_type == 'photo':
|
||||
@@ -80,6 +186,11 @@ def submission_list(request: HttpRequest) -> HttpResponse:
|
||||
context = {
|
||||
'submissions': queryset,
|
||||
'user': request.user,
|
||||
'parks': [(p.id, str(p)) for p in Park.objects.all()],
|
||||
'designers': [(d.id, str(d)) for d in Designer.objects.all()],
|
||||
'manufacturers': [(m.id, str(m)) for m in Manufacturer.objects.all()],
|
||||
'ride_models': [(m.id, str(m)) for m in RideModel.objects.all()],
|
||||
'owners': [(u.id, str(u)) for u in User.objects.filter(role__in=['OWNER', 'ADMIN', 'SUPERUSER'])]
|
||||
}
|
||||
|
||||
# If it's an HTMX request, return just the content
|
||||
@@ -89,6 +200,64 @@ def submission_list(request: HttpRequest) -> HttpResponse:
|
||||
# For direct URL access, return the full dashboard template
|
||||
return render(request, 'moderation/dashboard.html', context)
|
||||
|
||||
@login_required
|
||||
def edit_submission(request: HttpRequest, submission_id: int) -> HttpResponse:
|
||||
"""HTMX endpoint for editing a submission"""
|
||||
user = cast(User, request.user)
|
||||
if not (user.role in MODERATOR_ROLES or user.is_superuser):
|
||||
return HttpResponse(status=403)
|
||||
|
||||
submission = get_object_or_404(EditSubmission, id=submission_id)
|
||||
|
||||
if request.method == 'POST':
|
||||
# Handle the edit submission
|
||||
notes = request.POST.get('notes')
|
||||
if not notes:
|
||||
return HttpResponse("Notes are required when editing a submission", status=400)
|
||||
|
||||
try:
|
||||
# Update the moderator_changes with the edited values
|
||||
edited_changes = submission.changes.copy()
|
||||
for field in submission.changes.keys():
|
||||
if field == 'stats':
|
||||
edited_stats = {}
|
||||
for key in submission.changes['stats'].keys():
|
||||
if new_value := request.POST.get(f'stats.{key}'):
|
||||
edited_stats[key] = new_value
|
||||
edited_changes['stats'] = edited_stats
|
||||
else:
|
||||
if new_value := request.POST.get(field):
|
||||
# Handle special field types
|
||||
if field in ['latitude', 'longitude', 'size_acres']:
|
||||
try:
|
||||
edited_changes[field] = float(new_value)
|
||||
except ValueError:
|
||||
return HttpResponse(f"Invalid value for {field}", status=400)
|
||||
else:
|
||||
edited_changes[field] = new_value
|
||||
|
||||
submission.moderator_changes = edited_changes
|
||||
submission.notes = notes
|
||||
submission.save()
|
||||
|
||||
# Return the updated submission
|
||||
context = {
|
||||
'submission': submission,
|
||||
'user': request.user,
|
||||
'parks': [(p.id, str(p)) for p in Park.objects.all()],
|
||||
'designers': [(d.id, str(d)) for d in Designer.objects.all()],
|
||||
'manufacturers': [(m.id, str(m)) for m in Manufacturer.objects.all()],
|
||||
'ride_models': [(m.id, str(m)) for m in RideModel.objects.all()],
|
||||
'owners': [(u.id, str(u)) for u in User.objects.filter(role__in=['OWNER', 'ADMIN', 'SUPERUSER'])],
|
||||
'park_areas': [(a.id, str(a)) for a in ParkArea.objects.filter(park_id=edited_changes.get('park'))] if edited_changes.get('park') else []
|
||||
}
|
||||
return render(request, 'moderation/partials/submission_list.html', context)
|
||||
|
||||
except Exception as e:
|
||||
return HttpResponse(str(e), status=400)
|
||||
|
||||
return HttpResponse("Invalid request method", status=405)
|
||||
|
||||
@login_required
|
||||
def approve_submission(request: HttpRequest, submission_id: int) -> HttpResponse:
|
||||
"""HTMX endpoint for approving a submission"""
|
||||
@@ -105,7 +274,7 @@ def approve_submission(request: HttpRequest, submission_id: int) -> HttpResponse
|
||||
_update_submission_notes(submission, request.POST.get('notes'))
|
||||
|
||||
# Get updated queryset with filters
|
||||
status = request.GET.get('status', 'NEW')
|
||||
status = request.GET.get('status', 'PENDING')
|
||||
submission_type = request.GET.get('submission_type', '')
|
||||
|
||||
if submission_type == 'photo':
|
||||
@@ -143,7 +312,7 @@ def reject_submission(request: HttpRequest, submission_id: int) -> HttpResponse:
|
||||
_update_submission_notes(submission, request.POST.get('notes'))
|
||||
|
||||
# Get updated queryset with filters
|
||||
status = request.GET.get('status', 'NEW')
|
||||
status = request.GET.get('status', 'PENDING')
|
||||
submission_type = request.GET.get('submission_type', '')
|
||||
|
||||
if submission_type == 'photo':
|
||||
@@ -179,7 +348,7 @@ def escalate_submission(request: HttpRequest, submission_id: int) -> HttpRespons
|
||||
_update_submission_notes(submission, request.POST.get('notes'))
|
||||
|
||||
# Get updated queryset with filters
|
||||
status = request.GET.get('status', 'NEW')
|
||||
status = request.GET.get('status', 'PENDING')
|
||||
submission_type = request.GET.get('submission_type', '')
|
||||
|
||||
if submission_type == 'photo':
|
||||
|
||||
Reference in New Issue
Block a user