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