diff --git a/.DS_Store b/.DS_Store index ed53ceb8..03287122 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/osinaweb/.DS_Store b/osinaweb/.DS_Store index b808fa34..96c2e92c 100644 Binary files a/osinaweb/.DS_Store and b/osinaweb/.DS_Store differ diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index ff6fbd28..e2078050 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/node_modules/.DS_Store b/osinaweb/node_modules/.DS_Store new file mode 100644 index 00000000..461c75d6 Binary files /dev/null and b/osinaweb/node_modules/.DS_Store differ diff --git a/osinaweb/osinacore/.DS_Store b/osinaweb/osinacore/.DS_Store index 2068222b..8a244c53 100644 Binary files a/osinaweb/osinacore/.DS_Store and b/osinaweb/osinacore/.DS_Store differ diff --git a/osinaweb/osinacore/__pycache__/custom_context.cpython-310.pyc b/osinaweb/osinacore/__pycache__/custom_context.cpython-310.pyc index 28f6354f..e091a245 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/custom_context.py b/osinaweb/osinacore/custom_context.py index 487d3c40..9f509bdc 100644 --- a/osinaweb/osinacore/custom_context.py +++ b/osinaweb/osinacore/custom_context.py @@ -3,6 +3,22 @@ from django.contrib.auth.models import AnonymousUser from datetime import datetime, timedelta +def calculate_time_ago(status): + # Convert status.date to a datetime.date object + status_date = datetime.strptime(status.date, '%Y-%m-%d').date() + timestamp = datetime.combine(status_date, datetime.strptime(status.time, '%I:%M %p').time()) + time_difference = datetime.now() - timestamp + + if time_difference.total_seconds() < 3600: + # If less than an hour, display in minutes + return f"{int(time_difference.total_seconds() / 60)}min ago" + else: + # Display in hours and remaining minutes + hours = int(time_difference.total_seconds() // 3600) + minutes = int((time_difference.total_seconds() % 3600) // 60) + return f"{hours}hr {minutes}min ago" + + def utilities(request): if request.user.is_authenticated and request.user.is_superuser: open_task_count = Task.objects.filter(status='Open').count() @@ -24,10 +40,15 @@ def utilities(request): total_tasks = open_task_count + working_on_task_count latest_statuses = Status.objects.all().order_by('-id')[:12] + + + # Calculate time ago for each status and store it in a dictionary + latest_statuses_time_ago = [{'status': status, 'time_ago': calculate_time_ago(status)} for status in latest_statuses] + - return {'total_tasks': total_tasks, 'latest_statuses' : latest_statuses,} + return {'total_tasks': total_tasks, 'latest_statuses' : latest_statuses, 'latest_statuses_time_ago': latest_statuses_time_ago, } diff --git a/osinaweb/osinaweb/.DS_Store b/osinaweb/osinaweb/.DS_Store index e3aa90fe..4cb947f3 100644 Binary files a/osinaweb/osinaweb/.DS_Store and b/osinaweb/osinaweb/.DS_Store differ diff --git a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc index dec6b68c..ab338508 100644 Binary files a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc differ diff --git a/osinaweb/osinaweb/settings.py b/osinaweb/osinaweb/settings.py index 433ebdcf..7d924100 100644 --- a/osinaweb/osinaweb/settings.py +++ b/osinaweb/osinaweb/settings.py @@ -65,6 +65,7 @@ TEMPLATES = [ 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ + 'osinacore.custom_context.utilities', 'osinacore.custom_context.last_status', 'django.template.context_processors.debug', diff --git a/osinaweb/static/.DS_Store b/osinaweb/static/.DS_Store index e3f3bdaf..9e374c7b 100644 Binary files a/osinaweb/static/.DS_Store and b/osinaweb/static/.DS_Store differ diff --git a/osinaweb/templates/.DS_Store b/osinaweb/templates/.DS_Store index 3c58a480..f6005b07 100644 Binary files a/osinaweb/templates/.DS_Store and b/osinaweb/templates/.DS_Store differ diff --git a/osinaweb/templates/index.html b/osinaweb/templates/index.html index 7744b60f..09f43aa9 100644 --- a/osinaweb/templates/index.html +++ b/osinaweb/templates/index.html @@ -188,20 +188,24 @@
{{latest.time}}
+Just Now
+ {%else %} +{{ latest.time_ago}}
+ {%endif%}{{latest.text}}
+{{latest.status.text}}