Fixed subject of account activation email templates

This commit is contained in:
M.Ravi 2017-09-03 18:17:25 +02:00
parent f7129e0b23
commit d481737518

View file

@ -1,17 +1,19 @@
from datetime import datetime from datetime import datetime
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django.contrib.auth.hashers import make_password
from django.core.validators import RegexValidator
from django.contrib.sites.models import Site
from django.conf import settings
from django.utils.crypto import get_random_string
from utils.stripe_utils import StripeUtils from django.conf import settings
from utils.mailer import DigitalGlarusRegistrationMailer from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, \
PermissionsMixin
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.validators import RegexValidator
from django.db import models
from django.utils.crypto import get_random_string
from django.utils.translation import ugettext_lazy as _
from utils.mailer import BaseEmail from utils.mailer import BaseEmail
from utils.mailer import DigitalGlarusRegistrationMailer
from utils.stripe_utils import StripeUtils
REGISTRATION_MESSAGE = {'subject': "Validation mail", REGISTRATION_MESSAGE = {'subject': "Validation mail",
'message': 'Please validate Your account under this link ' 'message': 'Please validate Your account under this link '
@ -64,11 +66,13 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(unique=True) email = models.EmailField(unique=True)
validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0) validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0)
validation_slug = models.CharField(db_index=True, unique=True, max_length=50) validation_slug = models.CharField(db_index=True, unique=True,
max_length=50)
is_admin = models.BooleanField( is_admin = models.BooleanField(
_('staff status'), _('staff status'),
default=False, default=False,
help_text=_('Designates whether the user can log into this admin site.'), help_text=_(
'Designates whether the user can log into this admin site.'),
) )
objects = MyUserManager() objects = MyUserManager()
@ -77,28 +81,32 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
REQUIRED_FIELDS = ['name', 'password'] REQUIRED_FIELDS = ['name', 'password']
@classmethod @classmethod
def register(cls, name, password, email, app='digital_glarus', base_url=None, send_email=True): def register(cls, name, password, email, app='digital_glarus',
base_url=None, send_email=True):
user = cls.objects.filter(email=email).first() user = cls.objects.filter(email=email).first()
if not user: if not user:
user = cls.objects.create_user(name=name, email=email, password=password) user = cls.objects.create_user(name=name, email=email,
password=password)
if user: if user:
if app == 'digital_glarus': if app == 'digital_glarus':
dg = DigitalGlarusRegistrationMailer(user.validation_slug) dg = DigitalGlarusRegistrationMailer(user.validation_slug)
dg.send_mail(to=user.email) dg.send_mail(to=user.email)
elif app == 'dcl': elif app == 'dcl':
dcl_text = settings.DCL_TEXT dcl_text = settings.DCL_TEXT
# not used
# dcl_from_address = settings.DCL_SUPPORT_FROM_ADDRESS
user.is_active = False user.is_active = False
if send_email is True: if send_email is True:
email_data = { email_data = {
'subject': str(_('Activate your ')) + dcl_text + str(_(' account')), 'subject': '{dcl_text} {account_activation}'.format(
dcl_text=dcl_text,
account_activation=_('Account Activation')
),
'from_address': settings.DCL_SUPPORT_FROM_ADDRESS, 'from_address': settings.DCL_SUPPORT_FROM_ADDRESS,
'to': user.email, 'to': user.email,
'context': {'base_url': base_url, 'context': {'base_url': base_url,
'activation_link': reverse('hosting:validate', 'activation_link': reverse(
kwargs={'validate_slug': user.validation_slug}), 'hosting:validate',
kwargs={
'validate_slug': user.validation_slug}),
'dcl_text': dcl_text 'dcl_text': dcl_text
}, },
'template_name': 'user_activation', 'template_name': 'user_activation',
@ -114,7 +122,8 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
@classmethod @classmethod
def get_all_members(cls): def get_all_members(cls):
return cls.objects.filter(stripecustomer__membershiporder__isnull=False) return cls.objects.filter(
stripecustomer__membershiporder__isnull=False)
@classmethod @classmethod
def validate_url(cls, validation_slug): def validate_url(cls, validation_slug):
@ -204,9 +213,11 @@ class CreditCards(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE) user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
card_number = models.CharField(max_length=50) card_number = models.CharField(max_length=50)
expiry_date = models.CharField(max_length=50, validators=[RegexValidator(r'\d{2}\/\d{4}', _( expiry_date = models.CharField(max_length=50, validators=[
'Use this pattern(MM/YYYY).'))]) RegexValidator(r'\d{2}\/\d{4}', _(
ccv = models.CharField(max_length=4, validators=[RegexValidator(r'\d{3,4}', _('Wrong CCV number.'))]) 'Use this pattern(MM/YYYY).'))])
ccv = models.CharField(max_length=4, validators=[
RegexValidator(r'\d{3,4}', _('Wrong CCV number.'))])
payment_type = models.CharField(max_length=5, default='N') payment_type = models.CharField(max_length=5, default='N')
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
@ -221,7 +232,8 @@ class Calendar(models.Model):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if kwargs.get('datebooked'): if kwargs.get('datebooked'):
user = kwargs.get('user') user = kwargs.get('user')
kwargs['datebooked'] = datetime.strptime(kwargs.get('datebooked', ''), '%d,%m,%Y') kwargs['datebooked'] = datetime.strptime(
kwargs.get('datebooked', ''), '%d,%m,%Y')
self.user_id = user.id self.user_id = user.id
super(Calendar, self).__init__(*args, **kwargs) super(Calendar, self).__init__(*args, **kwargs)