diff --git a/osinaweb/celerybeat-schedule.db b/osinaweb/celerybeat-schedule.db index 939508de..1be98d6f 100644 Binary files a/osinaweb/celerybeat-schedule.db and b/osinaweb/celerybeat-schedule.db differ diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index cdee30b2..c349ed87 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 1ebc3ebf..3353e458 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__/models.cpython-310.pyc b/osinaweb/osinacore/__pycache__/models.cpython-310.pyc index 8a016ea2..36d64359 100644 Binary files a/osinaweb/osinacore/__pycache__/models.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/models.cpython-310.pyc differ diff --git a/osinaweb/osinacore/__pycache__/tasks.cpython-310.pyc b/osinaweb/osinacore/__pycache__/tasks.cpython-310.pyc index ba4d670b..6c4879ef 100644 Binary files a/osinaweb/osinacore/__pycache__/tasks.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/tasks.cpython-310.pyc differ diff --git a/osinaweb/osinacore/tasks.py b/osinaweb/osinacore/tasks.py index c623df84..13d12c95 100644 --- a/osinaweb/osinacore/tasks.py +++ b/osinaweb/osinacore/tasks.py @@ -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 - ) \ No newline at end of file + 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 + ) \ No newline at end of file diff --git a/osinaweb/osinaweb/__pycache__/celery.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/celery.cpython-310.pyc index 50db7250..910dfb3b 100644 Binary files a/osinaweb/osinaweb/__pycache__/celery.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/celery.cpython-310.pyc differ diff --git a/osinaweb/osinaweb/__pycache__/middleware.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/middleware.cpython-310.pyc index 4e8ee908..6b08a6a5 100644 Binary files a/osinaweb/osinaweb/__pycache__/middleware.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/middleware.cpython-310.pyc differ diff --git a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc index a2ef73de..b3af72ac 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/middleware.py b/osinaweb/osinaweb/middleware.py index 45f628eb..7251c336 100644 --- a/osinaweb/osinaweb/middleware.py +++ b/osinaweb/osinaweb/middleware.py @@ -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