Skip to content
This repository was archived by the owner on Oct 23, 2019. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions marketpulse/main/migrations/0009_auto_20150224_1356.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

from django_countries import countries

CARRIERS = {
'Telefonica Digital': [{'Movistar': ['Spain', 'Colombia', 'Venezuela', 'Peru',
'Uruguay', 'Mexico', 'Chile', 'El Salvador',
'Nicaragua', 'Guatemala', 'Costa Rica']},
{'Vivo': ['Brazil']},
{'O2': ['Germany']}],
'Deutsche Telekom': [{'T-Mobile': ['Poland', 'Czech Republic', 'Macedonia']},
{'Congstar': ['Germany']},
{'Telekom': ['Hungary']},
{'Cosmote': ['Greece']}],
'Telenor': [{'Telenor': ['Hugnary', 'Serbia', 'Montenegro']},
{'Grameenphone': ['Bangladesh']}],
'Telecom Italia': [{'TIM': ['Italy']}],
'America Movil': [{'Telcel': ['Mexico']}],
'Retailer': [{'E.Leclerc': ['France']}],
'Snapdeal': [{'Spice': ['India']}],
'JB Hifi': [{'ZTE': ['Australia']}],
'Alcatel OneTouch': [{'TCL': ['India']}],
'www.flicpart.com': [{'ZEN Mobil': ['India']}],
'Megafon': [{'Megafon': ['Russia']}],
'Cherry Mobile': [{'Cherry Mobile': ['Philippines']}],
'Banglalink': [{'Banglalink': ['Bangladesh']}],
'KDDI': [{'KDDI': ['Japan']}]
}


COUNTRIES_DICT = {v: k for k, v in countries}


def remove_carriers(apps, schema_editor):
Carrier = apps.get_model('main', 'Carrier')
Carrier.objects.all().delete()


def add_carriers(apps, schema_editor):

Carrier = apps.get_model('main', 'Carrier')
for parent_operator, carriers in CARRIERS.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the nested for but since this is a migration we can keep this.

for carrier_data in carriers:
for carrier, carrier_countries in carrier_data.items():
for carrier_country in carrier_countries:
if carrier_country in COUNTRIES_DICT:
Carrier.objects.create(parent_operator=parent_operator,
name=carrier,
country=COUNTRIES_DICT[carrier_country])
continue
Carrier.objects.create(parent_operator='Other', name='Other')


def backwards_method(apps, schema_editor):
pass


class Migration(migrations.Migration):

dependencies = [
('main', '0008_auto_20150220_1830'),
]

operations = [
migrations.RunPython(remove_carriers, backwards_method),
migrations.RunPython(add_carriers, remove_carriers),
]