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
2587edbe
Commit
2587edbe
authored
Oct 03, 2020
by
fred
Browse files
misc: handle existing subscribers by resetting existing data
parent
51b4b1bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
newsletter/models.py
View file @
2587edbe
...
...
@@ -28,19 +28,26 @@ from ckeditor.fields import RichTextField
class
Subscriber
(
models
.
Model
)
:
email
=
models
.
EmailField
(
unique
=
True
)
# TODO : informer si déjà inscrit ? Que faire dans ce cas.
email
=
models
.
EmailField
(
unique
=
True
)
inscription_date
=
models
.
DateField
(
auto_now_add
=
True
)
is_validated
=
models
.
NullBooleanField
()
# Au click sur le lien de confirmation. Null si erreur à l'envoi au souscripteur.
is_registered
=
models
.
NullBooleanField
()
# À l'inscription après la confirmation Null si erreur à l'envoi à mailman.
password
=
models
.
CharField
(
max_length
=
100
)
# sha1
is_validated
=
models
.
NullBooleanField
()
is_registered
=
models
.
NullBooleanField
()
password
=
models
.
CharField
(
max_length
=
100
)
def
__unicode__
(
self
)
:
return
self
.
email
def
save
(
self
,
*
args
,
**
kwargs
):
super
(
Subscriber
,
self
).
save
(
*
args
,
**
kwargs
)
if
self
.
is_validated
is
None
:
self
.
send_confirmation_email
()
existing_subscriber
=
self
.
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
:
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