New improvements

main
emile 2 years ago
parent 7ccfeaf80a
commit f228cf2c56

Binary file not shown.

@ -1,5 +1,6 @@
from .models import Task, Status from .models import Task, Status
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from datetime import datetime, timedelta
def utilities(request): def utilities(request):
@ -8,10 +9,35 @@ def utilities(request):
open_task_count = Task.objects.filter(status='Open').count() open_task_count = Task.objects.filter(status='Open').count()
working_on_task_count = Task.objects.filter(status='Working On').count() working_on_task_count = Task.objects.filter(status='Working On').count()
last_status = Status.objects.filter(staff=request.user.staffprofile).last() last_status = Status.objects.filter(staff=request.user.staffprofile).last()
if last_status:
# Convert the 'time' field to a datetime object
status_time = datetime.strptime(last_status.time, '%I:%M %p')
# Get the current time
current_time = datetime.now().time()
# Calculate the time difference
time_difference = abs(datetime.combine(datetime.today(), current_time) - datetime.combine(datetime.today(), status_time.time()))
# Get the time difference in minutes
minutes_ago = time_difference.total_seconds() / 60
minutes_ago = int(minutes_ago)
elif request.user.is_authenticated: elif request.user.is_authenticated:
open_task_count = Task.objects.filter(assigned_to=request.user.staffprofile, status='Open').count() 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() 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() last_status = Status.objects.filter(staff=request.user.staffprofile).last()
if last_status:
# Convert the 'time' field to a datetime object
status_time = datetime.strptime(last_status.time, '%I:%M %p')
# Get the current time
current_time = datetime.now().time()
# Calculate the time difference
time_difference = abs(datetime.combine(datetime.today(), current_time) - datetime.combine(datetime.today(), status_time.time()))
# Get the time difference in minutes
minutes_ago = time_difference.total_seconds() / 60
minutes_ago = int(minutes_ago)
else: else:
# Handle the case when the user is not logged in # Handle the case when the user is not logged in
open_task_count = 0 open_task_count = 0
@ -21,4 +47,4 @@ def utilities(request):
total_tasks = open_task_count + working_on_task_count total_tasks = open_task_count + working_on_task_count
latest_statuses = Status.objects.all().order_by('-id')[:12] latest_statuses = Status.objects.all().order_by('-id')[:12]
return {'total_tasks': total_tasks, 'last_status' : last_status, 'latest_statuses' : latest_statuses, } return {'total_tasks': total_tasks, 'last_status' : last_status, 'latest_statuses' : latest_statuses, 'minutes_ago' : minutes_ago, }

@ -107,7 +107,7 @@ def my_tasks(request, *args, **kwargs):
@login_required @login_required
def customers(request, *args, **kwargs): def customers(request, *args, **kwargs):
customers = CustomerProfile.objects.all().order_by('-id') customers = CustomerProfile.objects.all().order_by('-customer_id')
context = { context = {
'customers' : customers, 'customers' : customers,
@ -237,7 +237,7 @@ def businessdetails(request, business_id):
@login_required @login_required
def businesses(request): def businesses(request):
businesses = Business.objects.all().order_by('-id') businesses = Business.objects.all().order_by('-business_id')
context = { context = {
'businesses' : businesses, 'businesses' : businesses,
@ -286,7 +286,7 @@ def staff_positions(request):
@login_required @login_required
def staffs(request): def staffs(request):
staffs = StaffProfile.objects.all().order_by('-id') staffs = StaffProfile.objects.all().order_by('-staff_id')
context = { context = {
'staffs' : staffs, 'staffs' : staffs,

@ -33,7 +33,7 @@
id="notesContainer"> id="notesContainer">
{% for note in notes %} {% for note in notes %}
<div class="w-[16.33%] h-[150px] shadow-sm p-5 rounded-bl-xl" style="background-color: {{note.color}}"> <div class="w-[16.33%] h-[150px] shadow-sm p-5" style="background-color: {{note.color}}">
<p class="text-base text-slate-800">{{note.text}}</p> <p class="text-base text-slate-800">{{note.text}}</p>
</div> </div>
{% endfor %} {% endfor %}

@ -219,9 +219,9 @@
<div class="flex justify-start items-center gap-5"> <div class="flex justify-start items-center gap-5">
<div> <div>
<p class="text-sm text-gray-500">Your last update: 2023-08-31 08:13:31, 32 mins ago</p>
<p class="text-sm text-gray-500">Recent Status: <span <p class="text-sm text-gray-500">Recent Status: <span
class="text-slate-700 font-semibold">{{last_status.text}}</span></p> class="text-slate-700 font-semibold">{{last_status.text}}</span></p>
<p class="text-sm text-gray-500">Last update: {{last_status.date}} | {{last_status.time}}, {% if minutes_ago == 0 %} Just Now {%else%} {{minutes_ago}} mins ago {%endif%}</p>
</div> </div>
<button <button
class="w-[30px] h-[30px] rounded-full p-2 bg-gray-300 text-white text-[18px] outline-none border-none cursor-pointer flex justify-center items-center shadow-md addStatusButton" class="w-[30px] h-[30px] rounded-full p-2 bg-gray-300 text-white text-[18px] outline-none border-none cursor-pointer flex justify-center items-center shadow-md addStatusButton"

Loading…
Cancel
Save