1818)
1919from posts .models import Post
2020from posts .services .subscriptions import notify_post_status_change
21- from questions .models import Question , UserForecastNotification
21+ from questions .models import Forecast , Question , UserForecastNotification
2222from questions .services import (
2323 build_question_forecasts ,
2424 get_forecasts_per_user ,
@@ -283,7 +283,7 @@ def multiple_choice_delete_option_notificiations(
283283 ),
284284 )
285285
286- # send out an email
286+ # send out an immediate email
287287 forecaster_emails = (
288288 User .objects .filter (
289289 forecast__in = question .user_forecasts .filter (
@@ -331,6 +331,23 @@ def multiple_choice_add_option_notificiations(
331331 options_history = question .options_history
332332 added_options = list (set (options_history [- 1 ][1 ]) - set (options_history [- 2 ][1 ]))
333333
334+ forecasters = (
335+ User .objects .filter (
336+ forecast__in = question .user_forecasts .filter (
337+ end_time = grace_period_end
338+ ) # all effected forecasts have their end_time set to grace_period_end
339+ )
340+ .exclude (
341+ ubsubscribed_mailing_tags__contains = [
342+ MailingTags .BEFORE_PREDICTION_AUTO_WITHDRAWAL # seems most reasonable
343+ ]
344+ )
345+ .exclude (email__isnull = True )
346+ .exclude (email = "" )
347+ .distinct ("id" )
348+ .order_by ("id" )
349+ )
350+
334351 # send out a comment
335352 comment_author = User .objects .get (id = comment_author_id )
336353 create_comment (
@@ -347,24 +364,8 @@ def multiple_choice_add_option_notificiations(
347364 ),
348365 )
349366
350- # send out an email
351- forecaster_emails = (
352- User .objects .filter (
353- forecast__in = question .user_forecasts .filter (
354- Q (end_time__isnull = True ) | Q (end_time__gt = timestep )
355- )
356- )
357- .exclude (
358- ubsubscribed_mailing_tags__contains = [
359- MailingTags .BEFORE_PREDICTION_AUTO_WITHDRAWAL # seems most reasonable
360- ]
361- )
362- .exclude (email__isnull = True )
363- .exclude (email = "" )
364- .values_list ("email" , flat = True )
365- .distinct ("id" )
366- .order_by ("id" )
367- )
367+ # send out an immediate email
368+ forecaster_emails = forecasters .values_list ("email" , flat = True )
368369 start = 0
369370 batch_size = 300
370371 while True :
@@ -384,7 +385,24 @@ def multiple_choice_add_option_notificiations(
384385
385386 # schedule a followup email for 1 day before grace period
386387 # (if grace period is more than 1 day away)
387- ...
388+ if grace_period_end - timedelta (days = 1 ) > timestep :
389+ for forecaster in forecasters :
390+ UserForecastNotification .objects .filter (
391+ user = forecaster , question = question
392+ ).delete () # is this necessary?
393+ UserForecastNotification .objects .update_or_create (
394+ user = forecaster ,
395+ question = question ,
396+ defaults = {
397+ "trigger_time" : grace_period_end - timedelta (days = 1 ),
398+ "email_sent" : False ,
399+ "forecast" : Forecast .objects .filter (
400+ question = question , author = forecaster
401+ )
402+ .order_by ("-start_time" )
403+ .first (),
404+ },
405+ )
388406
389407 # add Post bulletin
390408 Bulletin .objects .create (
0 commit comments