diff --git a/amadeus/settings.py b/amadeus/settings.py index caa288d..0f0cb77 100644 --- a/amadeus/settings.py +++ b/amadeus/settings.py @@ -188,11 +188,13 @@ STATICFILES_DIRS = [ ] CRON_CLASSES = [ - 'notifications.cron.Notify' + 'notifications.cron.Notify', + 'goals.cron.SetGoals' ] CRONJOBS = [ - ('1 */12 * * *', 'notifications.cron.notification_cron') + ('1 */12 * * *', 'notifications.cron.notification_cron'), + ('1 */12 * * *', 'goals.cron.setgoals_cron') ] CHANNEL_LAYERS = { diff --git a/goals/cron.py b/goals/cron.py new file mode 100644 index 0000000..1f93737 --- /dev/null +++ b/goals/cron.py @@ -0,0 +1,16 @@ +import datetime +from django_cron import CronJobBase, Schedule + +from .utils import set_goals + +class SetGoals(CronJobBase): + RUN_EVERY_MINS = 1440 # every day + + schedule = Schedule(run_every_mins=RUN_EVERY_MINS) + code = 'amadeus.goals_cron' # a unique code + + def do(self): + set_goals() + +def setgoals_cron(): + set_goals() \ No newline at end of file diff --git a/goals/utils.py b/goals/utils.py new file mode 100644 index 0000000..c94650d --- /dev/null +++ b/goals/utils.py @@ -0,0 +1,18 @@ +from django.utils import timezone + +from users.models import User + +from .models import GoalItem, MyGoals + +def set_goals(): + specifications = GoalItem.objects.filter(goal__limit_submission_date__date = timezone.now()) + entries = [] + + for goal in specifications: + users = User.objects.filter(subject_student = goal.goal.topic.subject) + + for user in users: + if not MyGoals.objects.filter(user = user, item = goal).exists(): + entries.append(MyGoals(user = user, item = goal, value = goal.ref_value)) + + MyGoals.objects.bulk_create(entries) -- libgit2 0.21.2