Commit b56b732b authored by jocelyn's avatar jocelyn

Silently ignore subscriptions that already exist

Instead of IntegrityError
parent 76fbd52e
......@@ -60,7 +60,9 @@ class Command(BaseCommand):
def _iter_emails(filename):
with open(filename) as f:
for l in f.readlines():
yield l.strip()
email = l.strip()
if len(email) > 0:
yield l.strip()
@staticmethod
def _get_unknown_email(emails):
......@@ -86,12 +88,21 @@ class Command(BaseCommand):
except Member.DoesNotExist:
unknown_emails.append(email)
else:
mls = MaillingListSubscription(
mls_exists = MaillingListSubscription.objects.filter(
member=member,
maillinglist=ml,
)
mls.skip_sync = True
mls.save()
).exists()
# Not using get_or_create because we want to set skip_sync
# before saving
if not mls_exists:
mls = MaillingListSubscription(
member=member,
maillinglist=ml,
)
mls.skip_sync = True
mls.save()
# Do it once… (db will be rollback if it fails)
sys.stdout.write('Pousse la liste sur le serveur… ',)
......
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