From 50a41f9f3cb557fac734d9ae9d4d00f58fa735f1 Mon Sep 17 00:00:00 2001 From: ismail Date: Wed, 17 Jun 2026 20:42:06 +0300 Subject: [PATCH] fix: 4 more bugs from extended URL sweep (123 pages tested) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. /complaints/templates/ — FieldError: order_by('name_en') on ComplaintTemplate model which has 'name' (not 'name_en'). Fixed. 2. /executive/* (4 URLs) — NoReverseMatch: redirect('core:home') referenced a non-existent URL name. Fixed to redirect('/'). 3. /my/ and /my/performance/ — ValueError: QIProjectTask.filter(assigned_to=user) passed a User to a Staff FK. Fixed to use user.staff_profile. 4. /organizations/hospitals/ — FieldError: Hospital.objects.filter(hospital=...) on a self-referential field that doesn't exist. Fixed to filter by pk. --- apps/complaints/ui_views_templates.py | 4 ++-- apps/dashboard/views.py | 6 +++++- apps/executive_summary/views.py | 2 +- apps/organizations/ui_views.py | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/complaints/ui_views_templates.py b/apps/complaints/ui_views_templates.py index 76a385c..78ecd6f 100644 --- a/apps/complaints/ui_views_templates.py +++ b/apps/complaints/ui_views_templates.py @@ -34,9 +34,9 @@ def template_list(request): # Search search = request.GET.get('search') if search: - templates = templates.filter(name_en__icontains=search) + templates = templates.filter(name__icontains=search) - templates = templates.order_by('-usage_count', 'name_en') + templates = templates.order_by('-usage_count', 'name') # Get hospitals for filter if request.user.is_px_admin(): diff --git a/apps/dashboard/views.py b/apps/dashboard/views.py index 149ab4b..0796918 100644 --- a/apps/dashboard/views.py +++ b/apps/dashboard/views.py @@ -893,7 +893,11 @@ def get_dashboard_chart_data(user, start_date=None, selected_hospital=None): action_qs = action_qs.filter(hospital=selected_hospital) completed_count += action_qs.count() - task_qs = QIProjectTask.objects.filter(assigned_to=user, status="closed", completed_date=date.date()) + staff_profile = getattr(user, 'staff_profile', None) + if staff_profile: + task_qs = QIProjectTask.objects.filter(assigned_to=staff_profile, status="closed", completed_date=date.date()) + else: + task_qs = QIProjectTask.objects.none() if selected_hospital: task_qs = task_qs.filter(project__hospital=selected_hospital) completed_count += task_qs.count() diff --git a/apps/executive_summary/views.py b/apps/executive_summary/views.py index 4bdbf3a..f91b0e2 100644 --- a/apps/executive_summary/views.py +++ b/apps/executive_summary/views.py @@ -42,7 +42,7 @@ class ExecutiveAccessMixin: return redirect("accounts:login") if not (request.user.is_executive() or request.user.is_px_admin()): messages.error(request, _("You do not have permission to access the executive dashboard.")) - return redirect("core:home") + return redirect("/") return super().dispatch(request, *args, **kwargs) diff --git a/apps/organizations/ui_views.py b/apps/organizations/ui_views.py index 4a75880..e7c7080 100644 --- a/apps/organizations/ui_views.py +++ b/apps/organizations/ui_views.py @@ -28,16 +28,16 @@ def hospital_list(request): if user.is_px_admin(): # PX Admins see only their selected tenant hospital if request.tenant_hospital: - queryset = queryset.filter(hospital=request.tenant_hospital) + queryset = queryset.filter(pk=request.tenant_hospital.pk) else: queryset = queryset.none() elif user.hospital: - queryset = queryset.filter(hospital=user.hospital) + queryset = queryset.filter(pk=user.hospital_id) # Apply filters hospital_filter = request.GET.get("hospital") if hospital_filter: - queryset = queryset.filter(hospital_id=hospital_filter) + queryset = queryset.filter(pk=hospital_filter) status_filter = request.GET.get("status") if status_filter: @@ -51,7 +51,7 @@ def hospital_list(request): ) # Ordering - queryset = queryset.order_by("hospital", "name") + queryset = queryset.order_by("name") # Pagination page_size = int(request.GET.get("page_size", 25))