|
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
|
|
import ldapdb.models
|
|
|
import unicodedata
|
|
|
import datetime
|
|
|
+
|
|
|
from django.db import models
|
|
|
from django.db.models import Q
|
|
|
from django.db.models.signals import pre_save
|
|
@@ -12,6 +13,7 @@ from django.contrib.auth.models import AbstractUser
|
|
|
from django.conf import settings
|
|
|
from django.core.validators import RegexValidator
|
|
|
from django.core.exceptions import ValidationError
|
|
|
+from django.utils import timezone
|
|
|
from ldapdb.models.fields import CharField, IntegerField, ListField
|
|
|
|
|
|
from coin.offers.models import OfferSubscription
|
|
@@ -70,6 +72,9 @@ class Member(CoinLdapSyncMixin, AbstractUser):
|
|
|
help_text="Commentaires libres (informations"
|
|
|
" spécifiques concernant l'adhésion,"
|
|
|
" raison du départ, etc)")
|
|
|
+ date_last_call_for_membership_fees_email = models.DateTimeField(null=True,
|
|
|
+ blank=True,
|
|
|
+ verbose_name="Date du dernier email de relance de cotisation envoyé")
|
|
|
|
|
|
# Following fields are managed by the parent class AbstractUser :
|
|
|
# username, first_name, last_name, email
|
|
@@ -249,20 +254,33 @@ class Member(CoinLdapSyncMixin, AbstractUser):
|
|
|
from coin.isp_database.models import ISPInfo
|
|
|
|
|
|
utils.send_templated_email(to=self.email,
|
|
|
- subject_template='members/emails/welcome_email_subject.txt',
|
|
|
- body_template='members/emails/welcome_email.html',
|
|
|
- context={'member': self, 'branding':ISPInfo.objects.first()})
|
|
|
+ subject_template='members/emails/welcome_email_subject.txt',
|
|
|
+ body_template='members/emails/welcome_email.html',
|
|
|
+ context={'member': self, 'branding':ISPInfo.objects.first()})
|
|
|
|
|
|
def send_call_for_membership_fees_email(self):
|
|
|
""" Envoi le courriel d'appel à cotisation du membre """
|
|
|
+ from dateutil.relativedelta import relativedelta
|
|
|
from coin.isp_database.models import ISPInfo
|
|
|
|
|
|
- utils.send_templated_email(to=self.email,
|
|
|
- subject_template='members/emails/call_for_membership_fees_subject.txt',
|
|
|
- body_template='members/emails/call_for_membership_fees.html',
|
|
|
- context={'member': self, 'branding':ISPInfo.objects.first(),
|
|
|
- 'membership_info_url': settings.MEMBER_MEMBERSHIP_INFO_URL,
|
|
|
- 'today': datetime.date.today})
|
|
|
+ # Si le dernier courriel de relance a été envoyé il y a moins de trois
|
|
|
+ # semaines, n'envoi pas un nouveau courriel
|
|
|
+ if (not self.date_last_call_for_membership_fees_email
|
|
|
+ or (self.date_last_call_for_membership_fees_email
|
|
|
+ <= timezone.now() + relativedelta(weeks=-3))):
|
|
|
+ utils.send_templated_email(to=self.email,
|
|
|
+ subject_template='members/emails/call_for_membership_fees_subject.txt',
|
|
|
+ body_template='members/emails/call_for_membership_fees.html',
|
|
|
+ context={'member': self, 'branding':ISPInfo.objects.first(),
|
|
|
+ 'membership_info_url': settings.MEMBER_MEMBERSHIP_INFO_URL,
|
|
|
+ 'today': datetime.date.today})
|
|
|
+ # Sauvegarde en base la date du dernier envoi de mail de relance
|
|
|
+ self.date_last_call_for_membership_fees_email = timezone.now()
|
|
|
+ self.save()
|
|
|
+ return True
|
|
|
+
|
|
|
+ return False
|
|
|
+
|
|
|
|
|
|
class Meta:
|
|
|
verbose_name = 'membre'
|