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
ARN
coin
Commits
a54cfd12
Commit
a54cfd12
authored
Feb 13, 2019
by
jocelyn
Browse files
Add a context-manager to temporary disable maillist sync command
parent
0558cad2
Changes
1
Hide whitespace changes
Inline
Side-by-side
maillists/models.py
View file @
a54cfd12
...
...
@@ -2,6 +2,7 @@
from
__future__
import
unicode_literals
from
contextlib
import
contextmanager
import
subprocess
from
django.conf
import
settings
...
...
@@ -84,20 +85,18 @@ class MaillingList(models.Model):
out_stderr
.
decode
(
'utf-8'
)))
@
receiver
(
post_save
,
sender
=
MaillingListSubscription
)
def
push_new_subscription
(
sender
,
instance
,
created
,
raw
,
*
args
,
**
kwargs
):
if
raw
:
print
(
"The synchronization of mailling list with Coin was not performed, please launch it by hand in the admin interface."
)
el
se
:
el
if
not
getattr
(
sender
,
'skip_sync'
,
False
)
:
instance
.
maillinglist
.
sync_to_list_server
()
@
receiver
(
post_delete
,
sender
=
MaillingListSubscription
)
def
push_remove_subscription
(
sender
,
instance
,
*
args
,
**
kwargs
):
instance
.
maillinglist
.
sync_to_list_server
()
def
push_remove_subscription
(
sender
,
instance
,
*
args
,
**
kwargs
):
if
not
getattr
(
sender
,
'skip_sync'
,
False
):
instance
.
maillinglist
.
sync_to_list_server
()
@
receiver
(
pre_save
,
sender
=
Member
)
def
store_previous_email
(
sender
,
instance
,
*
args
,
**
kwargs
):
"""Record the email address for post_save handler
...
...
@@ -131,3 +130,36 @@ def update_an_email_address(sender, instance, *args, **kwargs):
# except SyncCommandError as e:
# print("error", e)
# we cannot send a message because we don't have the request
SIGNALS
=
[
(
Member
,
pre_save
,
store_previous_email
),
(
Member
,
post_save
,
update_an_email_address
),
(
MaillingListSubscription
,
post_save
,
push_new_subscription
),
(
MaillingListSubscription
,
post_delete
,
push_remove_subscription
),
]
def
connect_signals
():
for
sender
,
signal
,
receiver
in
SIGNALS
:
signal
.
connect
(
sender
=
sender
,
receiver
=
receiver
)
def
disconnect_signals
():
for
sender
,
signal
,
receiver
in
SIGNALS
:
signal
.
disconnect
(
sender
=
sender
,
receiver
=
receiver
)
# Do it once
connect_signals
()
@
contextmanager
def
skip_maillist_sync
():
""" Allows to skip temporary signals
"""
disconnect_signals
()
try
:
yield
finally
:
connect_signals
()
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