You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
from .models import Task, Status
|
|
from django.contrib.auth.models import AnonymousUser
|
|
|
|
def utilities(request):
|
|
|
|
|
|
if request.user.is_authenticated and request.user.is_superuser:
|
|
open_task_count = Task.objects.filter(status='Open').count()
|
|
working_on_task_count = Task.objects.filter(status='Working On').count()
|
|
last_status = Status.objects.filter(staff=request.user.staffprofile).last()
|
|
elif request.user.is_authenticated:
|
|
open_task_count = Task.objects.filter(assigned_to=request.user.staffprofile, status='Open').count()
|
|
working_on_task_count = Task.objects.filter(assigned_to=request.user.staffprofile, status='Working On').count()
|
|
last_status = Status.objects.filter(staff=request.user.staffprofile).last()
|
|
else:
|
|
# Handle the case when the user is not logged in
|
|
open_task_count = 0
|
|
working_on_task_count = 0
|
|
last_status = None
|
|
|
|
total_tasks = open_task_count + working_on_task_count
|
|
latest_statuses = Status.objects.all().order_by('-id')[:12]
|
|
|
|
return {'total_tasks': total_tasks, 'last_status' : last_status, 'latest_statuses' : latest_statuses, }
|