Upgrade django-allauth.
[wolnelektury.git] / apps / funding / management / commands / funding_notify.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from optparse import make_option
6 from django.core.management.base import BaseCommand
7
8
9 class Command(BaseCommand):
10     option_list = BaseCommand.option_list + (
11         make_option('-q', '--quiet', action='store_false', dest='verbose', default=True,
12             help='Suppress output'),
13     )
14     help = 'Sends relevant funding notifications.'
15
16     def handle(self, **options):
17
18         from datetime import date, timedelta
19         from funding.models import Offer
20         from funding import app_settings
21
22         verbose = options['verbose']
23
24         for offer in Offer.past().filter(notified_end=None):
25             if verbose:
26                 print 'Notify end:', offer
27             offer.notify_end()
28
29         current = Offer.current()
30         if (current is not None and
31                 current.end <= date.today() + timedelta(app_settings.DAYS_NEAR - 1) and
32                 not current.notified_near):
33             if verbose:
34                 print 'Notify near:', current
35             current.notify_near()