def _process_row(self, row, simulate=False, ignore_old_regions=False, **options): """Process one single row.""" pk = parse_uuid(row['id']) investment_project = InvestmentProject.objects.get(pk=pk) allow_blank_possible_uk_regions = parse_bool(row['allow_blank_possible_uk_regions']) uk_region_locations = parse_uuid_list(row['uk_region_locations']) current_regions = investment_project.uk_region_locations.all() current_region_ids = set(region.pk for region in current_regions) if (investment_project.allow_blank_possible_uk_regions == allow_blank_possible_uk_regions and current_region_ids == set(uk_region_locations)): return if not ignore_old_regions: old_uk_region_locations = parse_uuid_list(row['old_uk_region_locations']) if current_region_ids != set(old_uk_region_locations): return investment_project.allow_blank_possible_uk_regions = allow_blank_possible_uk_regions if simulate: return with reversion.create_revision(): investment_project.save( update_fields=('allow_blank_possible_uk_regions',), ) investment_project.uk_region_locations.set(uk_region_locations) reversion.set_comment('Possible UK regions data migration correction.')
def _process_row(self, row, simulate=False, ignore_old_regions=False, **options): """Processes a CSV file row.""" pk = parse_uuid(row['id']) investment_project = InvestmentProject.objects.get(pk=pk) old_business_activity_ids = parse_uuid_list( row['old_business_activities']) new_business_activity_ids = parse_uuid_list( row['new_business_activities']) current_business_activities = investment_project.business_activities.all( ) current_business_activity_ids = { activity.pk for activity in current_business_activities } if current_business_activity_ids == set(new_business_activity_ids): return if current_business_activity_ids != set(old_business_activity_ids): logger.warning( 'Not updating project %s as its business activities have changed', pk) return if simulate: return with reversion.create_revision(): investment_project.business_activities.set( new_business_activity_ids) reversion.set_comment( 'Business activities data migration correction.')
def _process_row(self, row, simulate=False, **options): """Process one single row.""" pk = parse_uuid(row['id']) investment_project = InvestmentProject.objects.get(pk=pk) new_delivery_partners = parse_uuid_list(row['delivery_partners']) if investment_project.delivery_partners.all(): logger.warning( 'Not updating project with existing delivery partners: %s, %s', investment_project.project_code, investment_project, ) return if not simulate: with reversion.create_revision(): investment_project.delivery_partners.set(new_delivery_partners) reversion.set_comment('Investment delivery partners migration.')