emile 11 months ago
parent 2619112708
commit cb9ae3f711

@ -224,22 +224,21 @@ def status_mobile_modal (request, *args, **kwargs):
@staff_login_required @staff_login_required
def user_recent_activities_modal(request, user_id): def user_recent_activities_modal(request, user_id):
current_time = timezone.now() today = datetime.now().date()
# Calculate the datetime of 24 hours ago
twenty_four_hours_ago = current_time - timezone.timedelta(hours=24)
if user_id: if user_id:
specific_user = get_object_or_404(User, id=user_id) specific_user = get_object_or_404(User, id=user_id)
# Fetch the specific user's statuses from the last 24 hours # Fetch the specific user's statuses from the last 24 hours
user_statuses = Status.objects.filter(staff__user=specific_user, date__gte=twenty_four_hours_ago).order_by('-id') user_statuses = Status.objects.filter(staff__user=specific_user, date=today).order_by('-id')
# Calculate time ago for each user status and store it in a dictionary # Calculate time ago for each user status and store it in a dictionary
user_statuses_time_ago = [{'status': status, 'time_ago': calculate_time_ago(status)} for status in user_statuses] user_statuses_time_ago = [{'status': status, 'time_ago': calculate_time_ago(status)} for status in user_statuses]
else: else:
# No specific user ID provided, fetch statuses for all users in the last 24 hours # No specific user ID provided, fetch statuses for all users in the last 24 hours
all_user_statuses = Status.objects.filter(date__gte=twenty_four_hours_ago).order_by('-id') all_user_statuses = Status.objects.filter(date=today).order_by('-id')
# Calculate time ago for each user status and store it in a dictionary # Calculate time ago for each user status and store it in a dictionary
user_statuses_time_ago = [{'status': status, 'time_ago': calculate_time_ago(status)} for status in all_user_statuses] user_statuses_time_ago = [{'status': status, 'time_ago': calculate_time_ago(status)} for status in all_user_statuses]

Loading…
Cancel
Save