# -*- 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()
        source_column = header.index("Source")
        for row in reader:
            # Fill the boolean columns using Source
            for source in row[source_column].split('|'):
                row['variant_in_'+source] = True
            Variant.objects.create_variant(dict(zip(header, row)))


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

    operations = [
        migrations.RunPython(load_from_csv),
    ]

@@ -110,19 +110,8 @@
 ls%0A%0A
-import ast%0A
 impo
@@ -467,16 +467,17 @@
 .next()%0A
+%0A
         
@@ -515,16 +515,17 @@
 ource%22)%0A
+%0A
         
@@ -543,16 +543,17 @@
 reader:%0A
+%0A
         
@@ -562,45 +562,86 @@
   # 
-Fill the boolean columns using Source
+split Source column into booleans%0A            row_dict = dict(zip(header,row))
 %0A   
@@ -670,22 +670,22 @@
  row
-%5Bsource_column
+_dict%5B'Source'
 %5D.sp
@@ -717,11 +717,16 @@
  row
+_dict
 %5B'
-v
+V
 aria
@@ -748,16 +748,17 @@
  = True%0A
+%0A
         
@@ -796,30 +796,16 @@
 ant(
+row_
 dict
-(zip(header, row))
 )%0A%0A%0A

split Source column into boolean columns