diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 88b9e3a1..96498fa7 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinacore/__pycache__/custom_context.cpython-310.pyc b/osinaweb/osinacore/__pycache__/custom_context.cpython-310.pyc index 40d34837..946c4b97 100644 Binary files a/osinaweb/osinacore/__pycache__/custom_context.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/custom_context.cpython-310.pyc differ diff --git a/osinaweb/osinacore/__pycache__/views.cpython-310.pyc b/osinaweb/osinacore/__pycache__/views.cpython-310.pyc index 57bedd8a..98f15d8d 100644 Binary files a/osinaweb/osinacore/__pycache__/views.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/osinacore/custom_context.py b/osinaweb/osinacore/custom_context.py index a5fc332d..01241d8c 100644 --- a/osinaweb/osinacore/custom_context.py +++ b/osinaweb/osinacore/custom_context.py @@ -1,5 +1,6 @@ from .models import Task, Status from django.contrib.auth.models import AnonymousUser +from datetime import datetime, timedelta def utilities(request): @@ -8,10 +9,35 @@ def utilities(request): 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() + 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: 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() + 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: # Handle the case when the user is not logged in open_task_count = 0 @@ -21,4 +47,4 @@ def utilities(request): 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, } + return {'total_tasks': total_tasks, 'last_status' : last_status, 'latest_statuses' : latest_statuses, 'minutes_ago' : minutes_ago, } diff --git a/osinaweb/osinacore/views.py b/osinaweb/osinacore/views.py index 6950dee3..7af7dc20 100644 --- a/osinaweb/osinacore/views.py +++ b/osinaweb/osinacore/views.py @@ -107,7 +107,7 @@ def my_tasks(request, *args, **kwargs): @login_required def customers(request, *args, **kwargs): - customers = CustomerProfile.objects.all().order_by('-id') + customers = CustomerProfile.objects.all().order_by('-customer_id') context = { 'customers' : customers, @@ -237,7 +237,7 @@ def businessdetails(request, business_id): @login_required def businesses(request): - businesses = Business.objects.all().order_by('-id') + businesses = Business.objects.all().order_by('-business_id') context = { 'businesses' : businesses, @@ -286,7 +286,7 @@ def staff_positions(request): @login_required def staffs(request): - staffs = StaffProfile.objects.all().order_by('-id') + staffs = StaffProfile.objects.all().order_by('-staff_id') context = { 'staffs' : staffs, diff --git a/osinaweb/templates/index.html b/osinaweb/templates/index.html index 2f9da78f..4fcfb8b7 100644 --- a/osinaweb/templates/index.html +++ b/osinaweb/templates/index.html @@ -33,7 +33,7 @@ id="notesContainer"> {% for note in notes %} -
+

{{note.text}}

{% endfor %} diff --git a/osinaweb/templates/main.html b/osinaweb/templates/main.html index 2de178f6..299892a7 100644 --- a/osinaweb/templates/main.html +++ b/osinaweb/templates/main.html @@ -219,9 +219,9 @@
-

Your last update: 2023-08-31 08:13:31, 32 mins ago

Recent Status: {{last_status.text}}

+

Last update: {{last_status.date}} | {{last_status.time}}, {% if minutes_ago == 0 %} Just Now {%else%} {{minutes_ago}} mins ago {%endif%}