Send a mail when someone is subscribed

This commit is contained in:
Skia
2016-08-31 18:40:17 +02:00
parent 6af16cc893
commit 1f31d3b56f
6 changed files with 162 additions and 97 deletions

View File

@ -5,6 +5,7 @@ from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.contrib.auth.forms import PasswordResetForm
from core.models import User
@ -70,8 +71,12 @@ class Subscription(models.Model):
super(Subscription, self).save()
from counter.models import Customer
if not Customer.objects.filter(user=self.member).exists():
last_id = Customer.objects.count() + 5195 # Number to keep a continuity with the old site
last_id = Customer.objects.count() + 1504 # Number to keep a continuity with the old site
Customer(user=self.member, account_id=Customer.generate_account_id(last_id+1), amount=0).save()
form = PasswordResetForm({'email': self.member.email})
if form.is_valid():
form.save(use_https=True, email_template_name='core/new_user_email.jinja',
subject_template_name='core/new_user_email_subject.jinja', from_email="ae@utbm.fr")
self.member.make_home()
try: # Create subscription on the old site: TODO remove me!
LOCATION = {

View File

@ -9,6 +9,7 @@ from django.forms import Select
from django.conf import settings
from ajax_select.fields import AutoCompleteSelectField
import random
from subscription.models import Subscriber, Subscription
from core.views import CanEditMixin, CanEditPropMixin, CanViewMixin
@ -54,6 +55,7 @@ class SubscriptionForm(forms.ModelForm):
first_name = self.cleaned_data.get("first_name"),
email = self.cleaned_data.get("email"))
u.generate_username()
u.set_password(str(random.randrange(1000000, 10000000)))
u.save()
cleaned_data["member"] = u
elif cleaned_data.get("member") is not None: