from django.core.mail import send_mail
from django.utils import translation
from teleforma.models import *
+import re
import logging
import datetime
+import time
from django.core.exceptions import ObjectDoesNotExist
class Logger:
logger = Logger(log_file)
logger.logger.info('########### Processing #############')
- period = Period.objects.get(name=period_name)
+ cur_year = time.strftime('%Y')
+
+ all_periods = Period.objects.all()
+ periods = []
+ for period in all_periods:
+ name = period.name
+ if re.match('^.* 20[0-9][0-9]$', name):
+ year = name[-4:]
+ if year >= cur_year:
+ name = name[:-5]
+ if name == period_name:
+ periods.append(period)
+ logger.logger.info('##### Will handle periods %s' % ', '.join([ str(p) for p in periods ]))
students = Student.objects.all()
translation.activate(self.language_code)
logger.logger.warning('missing user object for %s' % student.pk)
continue
- if student.is_subscribed and user.email and student.period == period and user.is_active :
+ if student.is_subscribed and user.email and student.period in periods and user.is_active :
for payment in student.payments.filter(type = 'online').exclude(online_paid = True).filter(scheduled__lte = today):
if payment.scheduled == today:
self.email(student, 'initial', payment)
-#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
teleforma
# Author: Guillaume Pellerin <yomguy@parisson.com>
"""
+import re
import datetime
from django.conf import settings
return datetime.date(year, month, 1) - oneday
payments = None
+ period_name = period.name
+ if re.match('^.* 20[0-9][0-9]$', period_name):
+ period_name = period_name[:-5]
# Full or partial ?
if self.payment_schedule == 'split':
- if period.name in ('Semestrielle', 'Annuelle', 'Annuelle progressive'):
+ if period_name in ('Semestrielle', 'Annuelle', 'Annuelle progressive'):
part = int(total * 0.25)
remaining = total - 3 * part
payments = ((remaining, tomorrow),)
# look at 01/m+1 and then remove one day
date = endofmonth(tomorrow.year + 1, month)
payments += ((part, date),)
- elif period.name == 'Estivale':
+ elif period_name == 'Estivale':
part = int(total * 0.35)
remaining = total - 2 * part
payments = ((remaining, tomorrow),)
# Handle oral date
oral_date = None
- if period.name in ('Semestrielle', 'Annuelle', 'Annuelle progressive'):
+ if period_name in ('Semestrielle', 'Annuelle', 'Annuelle progressive'):
if tomorrow.month <= 6:
# Late registration
oral_date = endofmonth(tomorrow.year, 6)
else:
# Normal registration
oral_date = endofmonth(tomorrow.year + 1, 6)
- elif period.name == 'Estivale':
+ elif period_name == 'Estivale':
if tomorrow.month >= 6:
# Late registration
oral_date = endofmonth(tomorrow.year, max(tomorrow.month, 8))