From a90adc9792dc27026e24cdb3ae767928160c7391 Mon Sep 17 00:00:00 2001 From: emile Date: Sat, 23 Sep 2023 22:00:19 +0300 Subject: [PATCH] fixes --- osinaweb/db.sqlite3 | Bin 421888 -> 421888 bytes .../custom_context.cpython-310.pyc | Bin 1335 -> 1538 bytes osinaweb/osinacore/custom_context.py | 52 +++++++++++------- osinaweb/templates/main.html | 2 +- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 14933d756b673fb6d467ce972c972760cd2da20d..be908ce153f25dfdf2ae3779e41e8680b03eb826 100644 GIT binary patch delta 341 zcmZp8AldLha)LDDiHS1Kj3+iGMCyv45K&;(Wy~+m%u7tpFG`IsE=epYEmmv3pu7Eo zE~7~i^9dG??d%H}JD3?cruQvotYBwjW@Hj!Jh7dB3FB98<`b+JwzF?w>}O_Ty|CF) z!Gej6m6?-?@kINzt&Bj-1jNkSuWe<~(_$9lUpAfn0gECF|7!kan*|S4@lW@7&m1!S z*LxN&W+9&c)7d`&C3$6d{sRrV%ws97#>OD5D9f3VnQ3HTWUOmoscU3xU}j}%t`OiW zrOL)22$amrhRYd&&$Tt4}jW)DsV zK|{u1Movd#^I))t74nm^Qj<#*G>pxs7v5l$RZc8PRf?^xjTM0#Z>(TwVP$G&Wn`jf QY-nk0VzK=mADdDl0L}bn4gdfE delta 183 zcmZp8AldLha)LDD(TOt7j7K*nMCytk7g1o=Wy~+m%u7tpFG`IsE=epYEmmp1pu7Eo zE~7~i^Klmb?d%H}JD8_WT+CQLF@SSB{}RTp+|0*WuWe`Fz}U~c*-^oPY5Ik&jI8aq zw=x1T6A&|RzrB@3Q;S)Ef5UY42P}%41rN0IGYU`N@SY`vS%BAKI{OEppre5RZ@a}` jmhBdQSu<+eu;9th?!!ONu52)cB-}ZZaY)Xj$h}lBP diff --git a/osinaweb/osinacore/__pycache__/custom_context.cpython-310.pyc b/osinaweb/osinacore/__pycache__/custom_context.cpython-310.pyc index 7bcf86ec3b907a06b37acd1fbadb5c53585bacd2..caacc4c5db3c471854e8cfd418152d7d84c283ac 100644 GIT binary patch delta 571 zcmZutO=}cE5bdh&*`2SQ?B;s|Y6vVi#>I<)Ab1cxcn^qrSr&Ve?1Y`gp3Y_IK@E8H zu=LRcc2AOv2QOaz5#nJIe}LdG@MKL$4uLe(tA4MV_vrfWABEAV(eN3aqpi8*cQA=g zJ0Y<;)l;e*kueDc7?!dWRCdu(Ws~#AFtls%V%LDIA2@1Q^)*(w#{JABq4W-f+Lu1D z@I>q|8C=~med%_tc`8!pg1Hi9;}cG6Ggja=T~zwy-yJxs^4?wMo!yxC>&Cnq{Q#-B zWQ8zj_zEjLT~EbyVaBG5GMa&8a_%FxS>bDc+8}jFHfK--#xuhB223DZ$IcFmVcx#P zM^DDi`u^xpDWD~lke6&M*86*-7|Woa=Yzd0kv%<99*xJmJCJ{>t&ZK!t8Qo5?a0`% z-*CHGhHuCt$#hTlbrLVzzxZ{fbaSnC^Y5S^LbOZLvo<;1TwQW zK!U10@1)wJpJQy9O}sqlT>a19`z+y!Ggm^A6wfryO(3NOpJ)E)cL%50cC(YS>14qq zq+F9`8<2{AKH=k)35-{zJ3$H3d!#a?t`?eWSEF2d;};P5=8GC;i)~ZH%^5qSXwAH` zk3!_l@+!U^#J#>+HZ8t~MRU*VfeP$NDzr2ORWaW@$vN4P4bybWRT>H^VF}lfV?aLJ vWj+a{A!pn=*(@McGf&Rxel5$XEK=3VnK-)X%E5Kqv~Po+uoQxiA^P+O;Dbw$ diff --git a/osinaweb/osinacore/custom_context.py b/osinaweb/osinacore/custom_context.py index fdb1e3ae..0e896c68 100644 --- a/osinaweb/osinacore/custom_context.py +++ b/osinaweb/osinacore/custom_context.py @@ -2,6 +2,7 @@ from .models import Task, Status from django.contrib.auth.models import AnonymousUser from datetime import datetime, timedelta + def utilities(request): minutes_ago = 0 if request.user.is_authenticated and request.user.is_superuser: @@ -9,34 +10,46 @@ def utilities(request): 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') + # 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() + # 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) + # 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) + # Check if it's 60 minutes or more + if minutes_ago >= 60: + # Calculate the time difference in hours + hours_ago = minutes_ago // 60 + return f'{hours_ago} hour{"s" if hours_ago > 1 else ""} 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') + # 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() - # 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) - # 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) + # Check if it's 60 minutes or more + if minutes_ago >= 60: + # Calculate the time difference in hours + hours_ago = minutes_ago // 60 + return f'{hours_ago} hour{"s" if hours_ago > 1 else ""} ago' else: # Handle the case when the user is not logged in open_task_count = 0 @@ -45,5 +58,6 @@ def utilities(request): total_tasks = open_task_count + working_on_task_count latest_statuses = Status.objects.all().order_by('-id')[:12] + current_date = datetime.now().strftime('%Y-%m-%d') - return {'total_tasks': total_tasks, 'last_status' : last_status, 'latest_statuses' : latest_statuses, 'minutes_ago' : minutes_ago, } + return {'total_tasks': total_tasks, 'last_status' : last_status, 'latest_statuses' : latest_statuses, 'minutes_ago' : minutes_ago, 'current_date' : current_date, } diff --git a/osinaweb/templates/main.html b/osinaweb/templates/main.html index 299892a7..6b549b08 100644 --- a/osinaweb/templates/main.html +++ b/osinaweb/templates/main.html @@ -221,7 +221,7 @@

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%}

+

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