Fixe le comportement de syncmail

syncmail ne devrait pas essayer de changer un email si un email du même
shortname existe déjà. Ce n'était pas le cas auparavant
This commit is contained in:
Martin Pépin 2016-12-23 18:51:33 +01:00
parent a5b6901972
commit 74abd6c853

View file

@ -33,7 +33,6 @@ class Command(BaseCommand):
status = {'synced': 0, 'unchanged': 0}
for obj in mail_data:
model = obj['model']
fields = obj['fields']
# Pour les trois types d'objets :
@ -43,7 +42,7 @@ class Command(BaseCommand):
# plus haut
# Variable types
if model == 'custommail.variabletype':
if obj['model'] == 'custommail.variabletype':
fields['inner1'] = assoc['types'].get(fields['inner1'])
fields['inner2'] = assoc['types'].get(fields['inner2'])
if fields['typ'] == 'model':
@ -55,21 +54,30 @@ class Command(BaseCommand):
assoc['types'][obj['pk']] = var_type
# Custom mails
if model == 'custommail.custommail':
mail, created = CustomMail.objects.get_or_create(**fields)
assoc['mails'][obj['pk']] = mail
if created:
if obj['model'] == 'custommail.custommail':
mail = None
try:
mail = CustomMail.objects.get(
shortname=fields['shortname'])
status['unchanged'] += 1
except CustomMail.DoesNotExist:
mail = CustomMail.objects.create(**fields)
status['synced'] += 1
self.stdout.write(
'SYNCED {:s}'.format(fields['shortname']))
status['synced'] += 1
else:
status['unchanged'] += 1
assoc['mails'][obj['pk']] = mail
# Variables
if model == 'custommail.custommailvariable':
if obj['model'] == 'custommail.custommailvariable':
fields['custommail'] = assoc['mails'].get(fields['custommail'])
fields['typ'] = assoc['types'].get(fields['typ'])
CustomMailVariable.objects.get_or_create(**fields)
try:
CustomMailVariable.objects.get(
custommail=fields['custommail'],
name=fields['name']
)
except CustomMailVariable.DoesNotExist:
CustomMailVariable.objects.create(**fields)
# C'est agréable d'avoir le résultat affiché
self.stdout.write(