Connected first functional version

main
emile 1 year ago
parent 61c71b1a6a
commit 7f7c1f0fe9

Binary file not shown.

Binary file not shown.

@ -17,8 +17,16 @@ def set_offline():
# Create a new connection record for each user with status set to 'Offline'
for user in users_without_working_points:
Connection.objects.create(
status='Offline',
date=timezone.now(),
user=user
)
last_connection = Connection.objects.filter(user=user).order_by('-date').first()
if last_connection is None or last_connection.status != 'Offline':
Connection.objects.create(
status='Offline',
date=timezone.now(),
user=user
)
new_status = Status.objects.create(
text='I am now offline!',
date=datetime.now().date(), # Getting the current date
time=datetime.now().strftime('%I:%M %p'),
staff=user.staffprofile
)

@ -1,5 +1,5 @@
from datetime import datetime, timedelta
from osinacore.models import Connection
from osinacore.models import *
class OnlineConnectionMiddleware:
def __init__(self, get_response):
@ -9,21 +9,18 @@ class OnlineConnectionMiddleware:
# Call the view function or next middleware in the stack
response = self.get_response(request)
# If user is authenticated, create or update the Connection instance
if request.user.is_authenticated:
current_datetime = datetime.now()
thirty_minutes_ago = current_datetime - timedelta(minutes=30)
# Check if an online Connection instance exists within the last 30 minutes
existing_connection = Connection.objects.filter(
user=request.user,
date__gte=thirty_minutes_ago,
status='Online'
).first()
# If there is no online connection within the last 30 minutes, create a new one
if not existing_connection:
if request.user.is_authenticated and request.user.staffprofile:
current_datetime = datetime.now()
last_connection = Connection.objects.filter(user=request.user).order_by('-date').first()
if not last_connection or last_connection.status != 'Online':
Connection.objects.create(user=request.user, status='Online', date=current_datetime)
new_status = Status.objects.create(
text='I am now online!',
date=datetime.now().date(), # Getting the current date
time=datetime.now().strftime('%I:%M %p'),
staff=request.user.staffprofile
)
return response

Loading…
Cancel
Save