emile 1 year ago
parent 3909707e4f
commit 8631d80bbb

Binary file not shown.

Binary file not shown.

@ -6,25 +6,24 @@ from django.db.models import Q
@shared_task @shared_task
def set_offline(): def set_offline():
all_staff_profiles = StaffProfile.objects.all() all_staff_profiles = StaffProfile.objects.all()
for staff_profile in all_staff_profiles: for staff_profile in all_staff_profiles:
last_working_point_activity = PointActivity.objects.filter( last_working_point_activity = PointActivity.objects.filter(
point__status='Working On', point__status='Working On',
point__task__assigned_to=staff_profile, point__task__assigned_to=staff_profile
).order_by('-end_time').first() ).last()
if last_working_point_activity and last_working_point_activity.end_time:
if last_working_point_activity and last_working_point_activity.end_time <= datetime.now() - timedelta(minutes=10): if last_working_point_activity.end_time <= datetime.now() - timedelta(minutes=10):
user = staff_profile.user user = staff_profile.user
last_connection = Connection.objects.filter(user=user).order_by('-date').first() last_connection = Connection.objects.filter(user=user).order_by('-date').first()
if last_connection is None or last_connection.status != 'Offline': if last_connection.status != 'Offline':
Connection.objects.create( Connection.objects.create(
status='Offline', status='Offline',
date=datetime.now(), date=datetime.now(),
user=user user=user
) )
Status.objects.create( Status.objects.create(
text='I am now offline!', text='I am now offline!',
date=datetime.now().date(), date=datetime.now().date(),
time=datetime.now().strftime('%I:%M %p'), time=datetime.now().strftime('%I:%M %p'),
staff=user.staffprofile staff=staff_profile
) )
Loading…
Cancel
Save