Add subcommand to transfer AA country with regions, subregions and cities
This commit is contained in:
parent
17ca27c751
commit
7b22ac72ca
122
apps/location/csv/aa_cities.csv
Normal file
122
apps/location/csv/aa_cities.csv
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
old_id,name,zip_code,country,,region,subregion,is_island
|
||||||
|
9854,Sainte Marie,97230,Antilles Guyane West Indies,11,null,null,1
|
||||||
|
9846,La Guyane,,Antilles Guyane West Indies,,null,null,1
|
||||||
|
9845,Macouba,97218,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9844,La Martinique,,Antilles Guyane West Indies,,null,null,1
|
||||||
|
9843,Guadeloupe,,Antilles Guyane West Indies,,Guadeloupe,null,1
|
||||||
|
9693,Gustavia,97133,Antilles Guyane West Indies,,St Barthelemy,null,0
|
||||||
|
9663,Saint Martin,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
9662,Saint-Barthélemy,97133,Antilles Guyane West Indies,,St Barthelemy,null,0
|
||||||
|
9661,Javouhey,97318,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9660,Kaw,97353,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9659,Apatou,97317,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9658,La comte,97352,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9657,St elie,97312,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9656,Grand santi,97340,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9655,Camopi,97330,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9654,Maripasoula,97370,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9653,Saul,97314,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9652,Ouanary,97380,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9651,Montsinery tonnegrande,97300,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9650,Sinnamary,97315,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9649,St Laurent du Maroni,97320,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9648,Roura,97311,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9647,Rémiré Montjoly,97354,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9646,St georges,97313,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9645,Matoury,97351,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9644,Mana,97360,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9643,Macouria,97355,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9642,Kourou,97310,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9641,Iracoubo,97350,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9640,Cayenne,97300,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9639,Regina,97390,Antilles Guyane West Indies,,Guyane,null,0
|
||||||
|
9638,Vert Pré,97231,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9637,Vauclin,97280,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9636,Trois Ilets,97229,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9635,La Trinité,97220,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9634,Schoelcher,97233,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9633,Saint-Pierre,97250,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9632,Sainte Marie,97230,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9631,Sainte-Luce,97228,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9630,Saint Joseph,97212,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9629,Saint Esprit,97270,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9628,Sainte-Anne,97227,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9627,Le Robert,97231,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9626,Rivière Salée,97215,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9625,Rivière Pilote,97211,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9624,Prêcheur,97250,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9623,Morne Vert,97226,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9622,Morne Rouge,97260,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9621,Le Marin,97290,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9620,Marigot,97225,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9619,Lorrain,97214,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9618,Lamentin,97232,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9617,Gros Morne,97213,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9616,Grand Rivière,97218,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9615,Le François,97240,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9614,Fort de France,97200,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9613,Fonds Saint Denis,97250,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9612,Ducos,97224,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9611,Le Diamant,97223,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9610,Case Pilote,97222,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9609,Le Carbet,97221,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9608,Bellefontaine,97222,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9607,Basse Pointe,97218,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9606,Anses d'Arlet,97217,Antilles Guyane West Indies,,Martinique,Sud,0
|
||||||
|
9605,Ajoupa Bouillon,97216,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9604,Les mangles,97131,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9603,Douville,97180,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9602,Sainte-Marie,97230,Antilles Guyane West Indies,,Martinique,Nord,0
|
||||||
|
9601,Pigeon,97132,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9600,Bananier,97130,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9599,Vieux-Habitants,97119,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9598,Vieux fort,97141,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9597,Trois rivieres,97114,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9596,Terre de Haut,97137,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||||
|
9595,Terre de bas,97136,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||||
|
9594,Sainte-Rose,97115,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9593,Sainte-Anne,97180,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9592,St louis,97134,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||||
|
9591,Saint-François,97118,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9590,St claude,97120,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9589,Port louis,97117,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9588,Pointe noire,97116,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9587,Pointe-A-Pitre,97110,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9586,Petit canal,97131,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9585,Petit bourg,97170,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9584,Le moule,97160,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9583,Morne a l eau,97111,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9582,Lamentin,97129,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9581,Goyave,97128,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9580,Le Gosier,97190,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9579,Grand-Bourg,97112,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||||
|
9578,Deshaies,97126,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9577,La desirade,97127,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||||
|
9576,Gourbeyre,97113,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9575,Capesterre de Marie-Galante,97140,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||||
|
9574,Capesterre belle eau,97130,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9573,Bouillante,97125,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9572,Basse terre,97100,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9571,Baillif,97123,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9570,Baie-Mahault,97122,Antilles Guyane West Indies,,Guadeloupe,Basse Terre,0
|
||||||
|
9569,Anse-Bertrand,97121,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
9568,Les abymes,97139,Antilles Guyane West Indies,,Guadeloupe,Grande Terre,0
|
||||||
|
11371,Cul-de-Sac,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11370,Ilet Pinel,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11369,Simpson Bay,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11368,Anse Marcel,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11367,Orient Bay,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11366,Marigot,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11365,Baie Longue,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11364,Baie Nettle,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11363,Baie Orientale,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11362,Oyster Pond,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
11349,Rodney Bay,LC01 401,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||||
|
11348,Good Lands,null,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||||
|
11347,Soufriere,null,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||||
|
11343,Gros Islet,LC0001,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||||
|
11342,CAP ESTATE,null,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||||
|
11341,Castries,null,Antilles Guyane West Indies,,Sainte-Lucie,null,0
|
||||||
|
11303,Saint- Louis,97134,Antilles Guyane West Indies,,Guadeloupe,Autres les Îles de Guadeloupe,0
|
||||||
|
11302,Grand Cul de Sac,97133,Antilles Guyane West Indies,,St Barthelemy,null,0
|
||||||
|
11301,Grand Case,97150,Antilles Guyane West Indies,,St Martin,null,0
|
||||||
|
|
|
@ -3,6 +3,7 @@ from transfer import models as transfer_models
|
||||||
from location.models import Country, Region, City, Address, WineRegion, CityGallery
|
from location.models import Country, Region, City, Address, WineRegion, CityGallery
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import json
|
import json
|
||||||
|
from django.db.transaction import atomic
|
||||||
|
|
||||||
from gallery.models import Image
|
from gallery.models import Image
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
@ -17,6 +18,8 @@ from news.models import News
|
||||||
from review.models import Review
|
from review.models import Review
|
||||||
from tag.models import TagCategory, ChosenTagSettings
|
from tag.models import TagCategory, ChosenTagSettings
|
||||||
|
|
||||||
|
import csv
|
||||||
|
|
||||||
from transfer.utils import clean_old_records
|
from transfer.utils import clean_old_records
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -541,65 +544,84 @@ def transfer_city_gallery():
|
||||||
f'Already added: {gallery_obj_exists_counter}')
|
f'Already added: {gallery_obj_exists_counter}')
|
||||||
|
|
||||||
|
|
||||||
|
@atomic
|
||||||
def add_fake_country():
|
def add_fake_country():
|
||||||
# add country
|
# add country
|
||||||
country_data = {
|
country_data = {
|
||||||
"name": '{"en-GB": "Antilles Guyane West Indies"}',
|
"name": '{"en-GB": "Antilles Guyane West Indies"}',
|
||||||
"code": "aa"
|
"code": "aa",
|
||||||
|
"svg_image": "svg/country/11-02-2019/658714.svg",
|
||||||
|
"mysql_ids": []
|
||||||
}
|
}
|
||||||
country_mysql_ids = transfer_models.Cities.objects.filter(country_code_2="AA").only("id")
|
|
||||||
if len(country_mysql_ids) < 1:
|
|
||||||
raise ValueError("Incorrect country code")
|
|
||||||
|
|
||||||
country_data['mysql_ids'] = list(country_mysql_ids.values_list('id', flat=True))
|
|
||||||
|
|
||||||
country = Country.objects.create(**country_data)
|
country = Country.objects.create(**country_data)
|
||||||
|
|
||||||
|
# add regions and subregions
|
||||||
regions_data = [
|
regions_data = [
|
||||||
{
|
{
|
||||||
"name": "Guadeloupe",
|
"name": "Guadeloupe",
|
||||||
"code": "GP",
|
"code": "gp",
|
||||||
"subregions": [
|
"subregions": [
|
||||||
{
|
{
|
||||||
"name": "Basse Terre",
|
"name": "Basse Terre",
|
||||||
"code": "",
|
"code": "bat",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Grande Terre",
|
"name": "Grande Terre",
|
||||||
"code": "",
|
"code": "grt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Autres les Îles de Guadeloupe",
|
||||||
|
"code": "aug",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Martinique",
|
"name": "Martinique",
|
||||||
"code": "MQ",
|
"code": "mq",
|
||||||
|
"subregions": [
|
||||||
|
{
|
||||||
|
"name": "Nord",
|
||||||
|
"code": "nor",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sud",
|
||||||
|
"code": "sud",
|
||||||
|
},
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Guyane",
|
"name": "Guyane",
|
||||||
"code": "GY",
|
"code": "gy",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "St Barthelemy",
|
"name": "St Barthelemy",
|
||||||
"code": "BL",
|
"code": "bl",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "St Martin",
|
"name": "St Martin",
|
||||||
"code": "MF",
|
"code": "mf",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Sainte-Lucie",
|
"name": "Sainte-Lucie",
|
||||||
"code": "LC",
|
"code": "lc",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
regions = {}
|
regions = {}
|
||||||
|
|
||||||
for region_data in regions_data:
|
for region_data in regions_data:
|
||||||
subregions = region_data['subregions'] if "subregions" in region_data else False
|
if "subregions" in region_data:
|
||||||
|
subregions = region_data['subregions']
|
||||||
|
del(region_data['subregions'])
|
||||||
|
else:
|
||||||
|
subregions = False
|
||||||
|
|
||||||
region_name = region_data['name']
|
region_name = region_data['name']
|
||||||
region_data['name'] = '{"en-GB": "' + region_name + '"}'
|
region_data['name'] = '{"en-GB": "' + region_name + '"}'
|
||||||
region_data['country'] = country
|
region_data['country'] = country
|
||||||
|
|
||||||
|
region_data['mysql_ids'] = []
|
||||||
|
|
||||||
regions[region_name] = Region.objects.create(**region_data)
|
regions[region_name] = Region.objects.create(**region_data)
|
||||||
|
|
||||||
if subregions:
|
if subregions:
|
||||||
|
|
@ -608,9 +630,70 @@ def add_fake_country():
|
||||||
subregion_data['name'] = '{"en-GB": "' + subregion_name + '"}'
|
subregion_data['name'] = '{"en-GB": "' + subregion_name + '"}'
|
||||||
subregion_data['country'] = country
|
subregion_data['country'] = country
|
||||||
subregion_data['parent_region'] = regions[region_name]
|
subregion_data['parent_region'] = regions[region_name]
|
||||||
|
subregion_data['mysql_ids'] = []
|
||||||
|
|
||||||
regions[subregion_name] = Region.objects.create(**subregion_data)
|
regions[subregion_name] = Region.objects.create(**subregion_data)
|
||||||
|
|
||||||
|
# add cities
|
||||||
|
file = open(f"{settings.PROJECT_ROOT}/apps/location/csv/aa_cities.csv")
|
||||||
|
reader = csv.DictReader(file, delimiter=',')
|
||||||
|
for city_data in reader:
|
||||||
|
del(city_data[''])
|
||||||
|
|
||||||
|
city_data['mysql_id'] = city_data['old_id']
|
||||||
|
del(city_data['old_id'])
|
||||||
|
|
||||||
|
city_data['postal_code'] = city_data['zip_code']
|
||||||
|
del(city_data['zip_code'])
|
||||||
|
|
||||||
|
if city_data['postal_code'] == 'null' or city_data['postal_code'] == '':
|
||||||
|
del(city_data['postal_code'])
|
||||||
|
|
||||||
|
city_data["country"] = country
|
||||||
|
|
||||||
|
if city_data['subregion'] != 'null':
|
||||||
|
region = regions[city_data['subregion']]
|
||||||
|
elif city_data['region'] != 'null':
|
||||||
|
region = regions[city_data['region']]
|
||||||
|
else:
|
||||||
|
del(city_data['region'])
|
||||||
|
region = None
|
||||||
|
|
||||||
|
del(city_data['subregion'])
|
||||||
|
|
||||||
|
city_data['region'] = region
|
||||||
|
|
||||||
|
city_data['name_translated'] = '{"en-GB": "' + city_data['name'] + '"}'
|
||||||
|
|
||||||
|
city_data['is_island'] = True if int(city_data['is_island']) > 0 else False
|
||||||
|
|
||||||
|
if region is not None:
|
||||||
|
region.mysql_ids.append(city_data['mysql_id'])
|
||||||
|
|
||||||
|
country.mysql_ids.append(city_data['mysql_id'])
|
||||||
|
|
||||||
|
try:
|
||||||
|
mysql_data = transfer_models.Cities.objects.\
|
||||||
|
only("map1", "map2", "map_ref", "situation").get(id=city_data['mysql_id'])
|
||||||
|
city_data['map1'] = mysql_data.map1
|
||||||
|
city_data['map2'] = mysql_data.map2
|
||||||
|
city_data['map_ref'] = mysql_data.map_ref
|
||||||
|
city_data['situation'] = mysql_data.situation
|
||||||
|
|
||||||
|
except transfer_models.Cities.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
City.objects.create(**city_data)
|
||||||
|
|
||||||
|
country.save()
|
||||||
|
|
||||||
|
for region_name, region in regions.items():
|
||||||
|
if len(region.mysql_ids) > 0:
|
||||||
|
region.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
"dictionaries": [
|
"dictionaries": [
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,19 @@ DATABASES.update({
|
||||||
'PORT': 3306,
|
'PORT': 3306,
|
||||||
'NAME': 'dev',
|
'NAME': 'dev',
|
||||||
'USER': 'dev',
|
'USER': 'dev',
|
||||||
'PASSWORD': 'octosecret123'}})
|
'PASSWORD': 'octosecret123'},
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.contrib.gis.db.backends.postgis',
|
||||||
|
'NAME': os.environ.get('DB_NAME'),
|
||||||
|
'USER': os.environ.get('DB_USERNAME'),
|
||||||
|
'PASSWORD': os.environ.get('DB_PASSWORD'),
|
||||||
|
'HOST': os.environ.get('DB_HOSTNAME'),
|
||||||
|
'PORT': os.environ.get('DB_PORT'),
|
||||||
|
'OPTIONS': {
|
||||||
|
'options': '-c search_path=gm,public'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# LOGGING
|
# LOGGING
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user