Skip to content

Send reminders

hypha.apply.funds.management.commands.send_reminders

Command

Bases: BaseCommand

help class-attribute instance-attribute

help = 'Send reminders'

handle

handle(*args, **options)
Source code in hypha/apply/funds/management/commands/send_reminders.py
def handle(self, *args, **options):
    site = ApplyHomePage.objects.first().get_site()

    # Mock a HTTPRequest in order to pass the site settings into the
    # templates
    request = HttpRequest()
    request.META["SERVER_NAME"] = site.hostname
    request.META["SERVER_PORT"] = site.port
    request.META[settings.SECURE_PROXY_SSL_HEADER] = "https"
    request.session = {}
    request._messages = FallbackStorage(request)

    for reminder in Reminder.objects.filter(sent=False, time__lte=timezone.now()):
        messenger(
            reminder.action_message,
            request=request,
            user=None,
            source=reminder.submission,
            related=reminder,
        )
        self.stdout.write(self.style.SUCCESS(f"Reminder sent: {reminder.id}"))
        reminder.sent = True
        reminder.save()