def handle(self, *args, **options): now = datetime.datetime.now() dow = now.weekday() begin = now + datetime.timedelta(minutes=WARN_DELAY_MIN) end = now + datetime.timedelta(minutes=WARN_DELAY_MAX) slots = WebclassSlot.published.filter(day=dow, start_hour__gte=begin.time(), start_hour__lt=end.time()) site = Site.objects.all()[0] admin = User.objects.get(username='******') date = now.strftime('%d/%m/%Y') for slot in slots: hour = slot.start_hour.strftime('%Hh%M') print("Sending notifications for %s:%s (%s)" % (slot.webclass.course, slot.start_hour, slot.id)) subject = "Webclass_%s_%s_%s" % (slot.webclass.course, date, hour) body = """Votre Webclasse va commencer.""" users = slot.participants.all() for user in users: print(" => %s" % user) msg = Message(subject=subject, body=body, sender=admin, recipient=user) msg.moderation_status = 'a' msg.save() notify_user(msg, 'acceptance', site)
def send(self): site = Site.objects.all()[0] users = [student.user for student in self.group.students.all()] for user in users: mess = Message(sender=self.sender, recipient=user, subject=self.subject[:119], body=self.message) mess.moderation_status = 'a' mess.save() notify_user(mess, 'acceptance', site)
def reject(self): self.date_marked = datetime.datetime.now() self.date_rejected = datetime.datetime.now() site = Site.objects.all()[0] context = {'script': self, 'site': site} text = render_to_string('exam/messages/script_rejected.txt', context) a = ugettext('Script') v = ugettext('rejected') subject = '%s %s' % (a, v) mess = Message(sender=self.corrector, recipient=self.author, subject=subject[:119], body=text) mess.moderation_status = 'a' mess.save() notify_user(mess, 'acceptance', site)