Commit 43c7d892 authored by fred's avatar fred

remove uniqueness requirement for emails

(this will later allow for stats on bot subscriptions)
parent 78977bd7
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2021-01-31 16:30
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('newsletter', '0002_auto_20171002_2231'),
]
operations = [
migrations.AlterField(
model_name='subscriber',
name='email',
field=models.EmailField(max_length=254),
),
]
......@@ -28,7 +28,7 @@ from ckeditor.fields import RichTextField
class Subscriber(models.Model) :
email = models.EmailField(unique=True)
email = models.EmailField(unique=False)
inscription_date = models.DateField(auto_now_add=True)
is_validated = models.NullBooleanField()
is_registered = models.NullBooleanField()
......@@ -38,20 +38,9 @@ class Subscriber(models.Model) :
return self.email
def save(self, *args, **kwargs):
existing_subscriber = Subscriber.objects.filter(email=self.email).first()
if existing_subscriber and existing_subscriber.id != self.id:
# reset existing subscriber
existing_subscriber.is_validated = None
existing_subscriber.is_registered = None
existing_subscriber.save()
else:
try:
super(Subscriber, self).save(*args, **kwargs)
except IntegrityError:
# probably concurrent calls, skip that.
return
if self.is_validated is None:
self.send_confirmation_email()
super(Subscriber, self).save(*args, **kwargs)
if self.is_validated is None:
self.send_confirmation_email()
def send_confirmation_email(self):
self.password = hashlib.sha1(force_bytes(str(random.random()))).hexdigest()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment