Coverage for bundesliga_tippspiel/background/reminders.py: 97%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2017 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of bundesliga-tippspiel.
6bundesliga-tippspiel is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11bundesliga-tippspiel is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from jerrycan.base import app, db
21from jerrycan.db.User import User
22from bundesliga_tippspiel.enums import ReminderType
23from bundesliga_tippspiel.db.settings.ReminderSettings import ReminderSettings
26def send_due_reminders():
27 """
28 Sends all email reminders that are due
29 :return: None
30 """
31 app.logger.info("Checking for new email reminders")
32 reminders = ReminderSettings.query.join(ReminderSettings.user).all()
34 all_users = User.query.filter_by(confirmed=True).all()
35 for reminder_type in ReminderType:
36 reminder_users = [
37 reminder.user_id
38 for reminder in reminders
39 if reminder.reminder_type == reminder_type
40 ]
42 for user in all_users:
43 if user.id not in reminder_users and user.confirmed:
44 reminder = ReminderSettings(
45 user=user, reminder_type=reminder_type
46 )
47 db.session.add(reminder)
48 reminders.append(reminder)
49 db.session.commit()
51 for reminder in reminders:
52 if reminder.active: 52 ↛ 51line 52 didn't jump to line 51, because the condition on line 52 was never false
53 reminder.send_reminder()