[docs]classCommand(BaseCommand):help="Notify users who have not signed up for Eighth Period or need to change their signup selection."defadd_arguments(self,parser):parser.add_argument("--silent",action="store_true",dest="silent",default=False,help="Be silent.")parser.add_argument("--only-tomorrow",action="store_true",dest="only-tomorrow",default=False,help="Only run if there is a block tomorrow.")parser.add_argument("--only-today",action="store_true",dest="only-today",default=False,help="Only run if there is a block today.")parser.add_argument("--pretend",action="store_true",dest="pretend",default=False,help="Pretend, and don't actually do anything.")parser.add_argument("--everyone",action="store_true",dest="everyone",default=False,help="Send to everyone, even those who have no eighth emails set.")defhandle(self,*args,**options):log=notoptions["silent"]ifoptions["everyone"]:users=get_user_model().objects.get_students()else:users=get_user_model().objects.filter(receive_eighth_emails=True)next_blocks=EighthBlock.objects.get_next_upcoming_blocks()ifnext_blocks.count()<1:iflog:self.stdout.write("No upcoming blocks.")returntoday=timezone.localdate()ifoptions["only-tomorrow"]:tomorrow=today+timedelta(days=1)blk_date=next_blocks[0].dateifblk_date!=tomorrow:iflog:self.stdout.write(f"Block {next_blocks[0]} on {blk_date} is not tomorrow ({tomorrow}).")returnifoptions["only-today"]:blk_date=next_blocks[0].dateifblk_date!=today:iflog:self.stdout.write(f"Block {next_blocks[0]} on {blk_date} is not today ({today}).")returniflog:self.stdout.write(str(next_blocks))self.stdout.write(str(options))self.stdout.write(str(users))foruserinusers:user_signups=EighthSignup.objects.filter(user=user,scheduled_activity__block__in=next_blocks)ifuser_signups.count()<next_blocks.count():"""User hasn't signed up for a block."""iflog:self.stdout.write(f"User {user} hasn't signed up for a block")ifnotoptions["pretend"]:try:signup_status_email(user,next_blocks)exceptExceptionase:self.stdout.write(e)elifuser_signups.filter(scheduled_activity__cancelled=True).count()>0:"""User is in a cancelled activity."""iflog:self.stdout.write(f"User {user} is in a cancelled activity.")ifnotoptions["pretend"]:try:signup_status_email(user,next_blocks)exceptExceptionase:self.stdout.write(e)iflog:self.stdout.write("Done.")