limited stopwords + better search by author + remove descendant results
[wolnelektury.git] / src / 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, help='Suppress output'),
12     )
13     help = 'Sends relevant funding notifications.'
14
15     def handle(self, **options):
16
17         from datetime import date, timedelta
18         from funding.models import Offer
19         from funding import app_settings
20         from django.core.cache import caches
21         from django.conf import settings
22
23         verbose = options['verbose']
24
25         for offer in Offer.past().filter(notified_end=None):
26             if verbose:
27                 print 'Notify end:', offer
28             # The 'WL fund' list needs to be updated.
29             caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
30             offer.flush_includes()
31             offer.notify_end()
32
33         current = Offer.current()
34         if (current is not None and
35                 current.end <= date.today() + timedelta(app_settings.DAYS_NEAR - 1) and
36                 not current.notified_near):
37             if verbose:
38                 print 'Notify near:', current
39             current.notify_near()