8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 09:26:27 +00:00
re2o/users/management/commands/email.py

36 lines
973 B
Python
Raw Normal View History

2017-12-12 03:33:50 +00:00
from django.core.management.base import BaseCommand, CommandError
from datetime import datetime, timedelta
from pytz
from users.models import User
UTC = pytz.timezone('UTC')
2018-04-14 01:25:05 +00:00
# TODO : remove of finsihed this because currently it should
# be failing! Who commited that ?!
2017-12-12 03:33:50 +00:00
class Command(BaseCommand):
2018-04-14 01:25:05 +00:00
commands = ['email_remainder']
2017-12-12 03:33:50 +00:00
args = '[command]'
help = 'Send email remainders'
def handle(self, *args, **options):
'''
Sends an email before the end of a user's subscription
'''
users = User.objects.filter(state="STATE_ACTIVE")
for user in users:
remaining = user.end_adhesion() - datetime.today(tz=UTC)
if (timedelta(weeks=4) - remaining).days == 1:
4_weeks_reminder()
elif (timedelta(weeks=1) - remaining).days == 1:
week_reminder()
elif remaining.days == 1:
last_day_reminder()
2018-04-14 01:25:05 +00:00
2017-12-12 03:33:50 +00:00
def month_reminder():
pass