# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-02-10 16:52
from __future__ import unicode_literals

import ast
import csv
import os.path

from django.conf import settings
from django.db import migrations

from data.models import Variant


def load_from_csv(apps, schema_editor):
    file_path = os.path.join(settings.BASE_DIR, 'data', 'resources', 'merged_v5.csv')
    with open(file_path) as csv_file:
        reader = csv.reader(csv_file)
        header = reader.next()
        for row in reader:
            # The first 6 columns of the database are booleans
            for i in range(6):
                row[i] = ast.literal_eval(row[i])
            Variant.objects.create_variant(dict(zip(header, row)))


class Migration(migrations.Migration):
    dependencies = [
        ('data', '0002_search_index'),
    ]

    operations = [
        migrations.RunPython(load_from_csv),
    ]

@@ -490,170 +490,231 @@
     
-for row in reader:%0A            # The first 6 columns of the database are booleans%0A            for i in range(6):%0A                row%5Bi%5D = ast.literal_eval(row%5Bi%5D)
+source_column = header.index(%22Source%22)%0A        for row in reader:%0A            # Fill the boolean columns using Source%0A            for source in row%5Bsource_column%5D.split('%7C'):%0A                row%5B'variant_in_'+source%5D = True
 %0A   

change migration to split Source column into booleans