Commit c66d8a9b5b2b7b272fddbdab161c3a32babd70d2

Authored by Zambom
1 parent 60d308d7

Adding cron to set goals for unsetted users after limit date

amadeus/settings.py
... ... @@ -188,11 +188,13 @@ STATICFILES_DIRS = [
188 188 ]
189 189  
190 190 CRON_CLASSES = [
191   - 'notifications.cron.Notify'
  191 + 'notifications.cron.Notify',
  192 + 'goals.cron.SetGoals'
192 193 ]
193 194  
194 195 CRONJOBS = [
195   - ('1 */12 * * *', 'notifications.cron.notification_cron')
  196 + ('1 */12 * * *', 'notifications.cron.notification_cron'),
  197 + ('1 */12 * * *', 'goals.cron.setgoals_cron')
196 198 ]
197 199  
198 200 CHANNEL_LAYERS = {
... ...
goals/cron.py 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +import datetime
  2 +from django_cron import CronJobBase, Schedule
  3 +
  4 +from .utils import set_goals
  5 +
  6 +class SetGoals(CronJobBase):
  7 + RUN_EVERY_MINS = 1440 # every day
  8 +
  9 + schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
  10 + code = 'amadeus.goals_cron' # a unique code
  11 +
  12 + def do(self):
  13 + set_goals()
  14 +
  15 +def setgoals_cron():
  16 + set_goals()
0 17 \ No newline at end of file
... ...
goals/utils.py 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +from django.utils import timezone
  2 +
  3 +from users.models import User
  4 +
  5 +from .models import GoalItem, MyGoals
  6 +
  7 +def set_goals():
  8 + specifications = GoalItem.objects.filter(goal__limit_submission_date__date = timezone.now())
  9 + entries = []
  10 +
  11 + for goal in specifications:
  12 + users = User.objects.filter(subject_student = goal.goal.topic.subject)
  13 +
  14 + for user in users:
  15 + if not MyGoals.objects.filter(user = user, item = goal).exists():
  16 + entries.append(MyGoals(user = user, item = goal, value = goal.ref_value))
  17 +
  18 + MyGoals.objects.bulk_create(entries)
... ...