Commit b56b732b authored by jocelyn's avatar jocelyn
Browse files

Silently ignore subscriptions that already exist

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