Commit c55da72b authored by fred's avatar fred
Browse files

handle emails already subscribed to mailman

parent 93cbe21d
......@@ -62,8 +62,18 @@ class Subscriber(models.Model):
return self.subscribe_in_mailchimp()
def subscribe_in_mailman(self):
t = subprocess.call(['listadmin', '--add-member', self.email, settings.NEWSLETTER_NAME])
if t != 0:
try:
subprocess.run(
['listadmin', '--add-member', self.email, settings.NEWSLETTER_NAME], check_call=True
)
except subprocess.CalledProcessError:
# maybe an error because email is already registered?
result = subprocess.run(
['listadmin', '-l', 'newsletter-panik'], check=True, capture_output=True, text=True
)
if self.email in result.stdout.splitlines():
self.is_registered = True
self.save()
return
self.is_registered = True
self.save()
......
Supports Markdown
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