Skip to content

Commit

Permalink
Module cleanup in cron job
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoest committed Jan 11, 2025
1 parent 06e72a8 commit 09c01b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions S1/connect/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class UserDetail(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
en_preferred = models.BooleanField(default=False)
subdivision = models.CharField(max_length=10, blank=True, null=True)
flagged_for_deletion = models.BooleanField(default=False)
rating = models.IntegerField()

def __str__(self):
Expand Down
9 changes: 5 additions & 4 deletions S1/waitinglists/management/commands/module_cleanup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand
from django.utils import timezone
from waitinglists.models import Module, QuizCompletion, WaitingList
from django.contrib.auth.models import User

import os
from dotenv import load_dotenv
Expand Down Expand Up @@ -31,9 +32,6 @@ def handle(self, *args, **kwargs):
"user__username", flat=True
)
)
print(mod_1_users)
print(mod_3_users)
print(mod_4_users)
users = mod_1_users - mod_3_users - mod_4_users
for user in users:
module_1_completion_date = WaitingList.objects.get(
Expand Down Expand Up @@ -61,4 +59,7 @@ def handle(self, *args, **kwargs):
completions[-1].date_completed - completions[-2].date_completed
).days > 40:
result.append(user)
print(result)
for user in result:
obj = User.objects.get(username=user)
obj.userdetail.flagged_for_deletion = True
obj.userdetail.save()
3 changes: 2 additions & 1 deletion cron_schedule
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0 0 * * * cd /opt/s1/S1 && python manage.py collect_signups
0 0 14 * * cd /opt/s1/S1 && python manage.py inform_renewal
* * * * * cd /opt/s1/S1 && python manage.py moodle_api
* * * * * cd /opt/s1/S1 && python manage.py moodle_api
0 0 * * 0 cd /opt/s1/S1 && python manage.py module_cleanup

0 comments on commit 09c01b5

Please sign in to comment.