From a0b156ffabba27dc2f99e2134fa24a58a7d8e9e7 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 25 Nov 2015 15:33:22 +0100 Subject: [PATCH] load-pratic-ldif: allow modifying existing service instances --- .../management/commands/load-pratic-ldif.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/authentic2_pratic/management/commands/load-pratic-ldif.py b/src/authentic2_pratic/management/commands/load-pratic-ldif.py index 39132f0..9295fff 100644 --- a/src/authentic2_pratic/management/commands/load-pratic-ldif.py +++ b/src/authentic2_pratic/management/commands/load-pratic-ldif.py @@ -148,10 +148,17 @@ class PraticLDIFParser(ldif.LDIFParser): service = self.services[entry['cdg59serviceType'][0]] if not service.is_global and 'service_url' not in others: others['service_url'] = 'http://missing-url-%s.com' % others['slug'] - service_instance = ServiceInstance( + try: + service_instance = ServiceInstance.objects.get( collectivity=collectivity, - service=service, - **others) + service=service) + for k, v in others.iteritems(): + setattr(service_instance, k, v) + except ServiceInstance.DoesNotExist: + service_instance = ServiceInstance( + collectivity=collectivity, + service=service, + **others) try: service_instance.clean() except ValidationError, e: