From f504bddb85c96b3ef15b8bfe347f510acb9e80da Mon Sep 17 00:00:00 2001 From: Kasper Brandt Date: Thu, 17 Jul 2014 10:07:42 +0200 Subject: [PATCH] [#680] Hacky solutions for Cordaid script --- akvo/rsr/models.py | 6 +++++- akvo/scripts/cordaid/pre_import.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/akvo/rsr/models.py b/akvo/rsr/models.py index 0e80787d1b..d2a0fa4848 100644 --- a/akvo/rsr/models.py +++ b/akvo/rsr/models.py @@ -145,7 +145,11 @@ def save(self, *args, **kwargs): # Set location as primary location if it is the first location location_target = self.location_target - if location_target.primary_location is None or location_target.primary_location.pk > self.pk: + try: + if location_target.primary_location is None or location_target.primary_location.pk > self.pk: + location_target.primary_location = self + location_target.save() + except: location_target.primary_location = self location_target.save() diff --git a/akvo/scripts/cordaid/pre_import.py b/akvo/scripts/cordaid/pre_import.py index adc43fbb7c..ecec05864a 100644 --- a/akvo/scripts/cordaid/pre_import.py +++ b/akvo/scripts/cordaid/pre_import.py @@ -96,7 +96,10 @@ def create_cats_and_benches(business_units): log(u"Created bench: {id}, {name}", dict(id=new_bench.id, name=name)) else: log(u"Found existing bench: {id}, {name}", dict(id=new_bench.id, name=name)) - data['category'].benchmarknames.add(new_bench) + try: + data['category'].benchmarknames.add(new_bench) + except: + log(u"Did not find bench: {id}, {name}", dict(id=new_bench.id, name=name)) def import_cordaid_benchmarks(csv_file):