Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
radiopanik
django-panik-newsletter
Commits
43c7d892
Commit
43c7d892
authored
Jan 31, 2021
by
fred
Browse files
remove uniqueness requirement for emails
(this will later allow for stats on bot subscriptions)
parent
78977bd7
Changes
2
Hide whitespace changes
Inline
Side-by-side
newsletter/migrations/0003_auto_20210131_1630.py
0 → 100644
View file @
43c7d892
# -*- 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
),
),
]
newsletter/models.py
View file @
43c7d892
...
...
@@ -28,7 +28,7 @@ from ckeditor.fields import RichTextField
class
Subscriber
(
models
.
Model
)
:
email
=
models
.
EmailField
(
unique
=
Tru
e
)
email
=
models
.
EmailField
(
unique
=
Fals
e
)
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
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment