59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
"""
|
|
Context processors for global template variables
|
|
"""
|
|
from django.db.models import Q
|
|
|
|
|
|
def sidebar_counts(request):
|
|
"""
|
|
Provide counts for sidebar badges.
|
|
|
|
Returns counts for:
|
|
- Active complaints
|
|
- Pending feedback
|
|
- Open PX actions
|
|
"""
|
|
if not request.user.is_authenticated:
|
|
return {}
|
|
|
|
from apps.complaints.models import Complaint
|
|
from apps.feedback.models import Feedback
|
|
from apps.px_action_center.models import PXAction
|
|
|
|
user = request.user
|
|
|
|
# Filter based on user role
|
|
if user.is_px_admin():
|
|
complaint_count = Complaint.objects.filter(
|
|
status__in=['open', 'in_progress']
|
|
).count()
|
|
feedback_count = Feedback.objects.filter(
|
|
status__in=['submitted', 'reviewed']
|
|
).count()
|
|
action_count = PXAction.objects.filter(
|
|
status__in=['open', 'in_progress']
|
|
).count()
|
|
elif user.hospital:
|
|
complaint_count = Complaint.objects.filter(
|
|
hospital=user.hospital,
|
|
status__in=['open', 'in_progress']
|
|
).count()
|
|
feedback_count = Feedback.objects.filter(
|
|
hospital=user.hospital,
|
|
status__in=['submitted', 'reviewed']
|
|
).count()
|
|
action_count = PXAction.objects.filter(
|
|
hospital=user.hospital,
|
|
status__in=['open', 'in_progress']
|
|
).count()
|
|
else:
|
|
complaint_count = 0
|
|
feedback_count = 0
|
|
action_count = 0
|
|
|
|
return {
|
|
'complaint_count': complaint_count,
|
|
'feedback_count': feedback_count,
|
|
'action_count': action_count,
|
|
}
|