refactor location transfer
This commit is contained in:
parent
11cd688851
commit
9177d41309
|
|
@ -144,8 +144,8 @@ def transfer_addresses():
|
||||||
def transfer_wine_region():
|
def transfer_wine_region():
|
||||||
queryset = transfer_models.WineLocations.objects.filter(type='WineRegion')
|
queryset = transfer_models.WineLocations.objects.filter(type='WineRegion')
|
||||||
serialized_data = location_serializers.WineRegionSerializer(
|
serialized_data = location_serializers.WineRegionSerializer(
|
||||||
data=list(queryset.values()),
|
data=list(queryset.values()),
|
||||||
many=True)
|
many=True)
|
||||||
if serialized_data.is_valid():
|
if serialized_data.is_valid():
|
||||||
serialized_data.save()
|
serialized_data.save()
|
||||||
else:
|
else:
|
||||||
|
|
@ -155,8 +155,8 @@ def transfer_wine_region():
|
||||||
def transfer_wine_sub_region():
|
def transfer_wine_sub_region():
|
||||||
queryset = transfer_models.WineLocations.objects.filter(type='WineSubRegion')
|
queryset = transfer_models.WineLocations.objects.filter(type='WineSubRegion')
|
||||||
serialized_data = location_serializers.WineSubRegionSerializer(
|
serialized_data = location_serializers.WineSubRegionSerializer(
|
||||||
data=list(queryset.values()),
|
data=list(queryset.values()),
|
||||||
many=True)
|
many=True)
|
||||||
if serialized_data.is_valid():
|
if serialized_data.is_valid():
|
||||||
serialized_data.save()
|
serialized_data.save()
|
||||||
else:
|
else:
|
||||||
|
|
@ -166,8 +166,8 @@ def transfer_wine_sub_region():
|
||||||
def transfer_wine_village():
|
def transfer_wine_village():
|
||||||
queryset = transfer_models.WineLocations.objects.filter(type='Village')
|
queryset = transfer_models.WineLocations.objects.filter(type='Village')
|
||||||
serialized_data = location_serializers.WineVillageSerializer(
|
serialized_data = location_serializers.WineVillageSerializer(
|
||||||
data=list(queryset.values()),
|
data=list(queryset.values()),
|
||||||
many=True)
|
many=True)
|
||||||
if serialized_data.is_valid():
|
if serialized_data.is_valid():
|
||||||
serialized_data.save()
|
serialized_data.save()
|
||||||
else:
|
else:
|
||||||
|
|
@ -332,7 +332,7 @@ def get_unused_data():
|
||||||
# Add correct objects of Country, Region and City with mysql_ids array (Country, Region) and mysql_id (City)
|
# Add correct objects of Country, Region and City with mysql_ids array (Country, Region) and mysql_id (City)
|
||||||
def add_correct_location_models(ruby_data):
|
def add_correct_location_models(ruby_data):
|
||||||
for mysql_id, city_object in tqdm(ruby_data.items()):
|
for mysql_id, city_object in tqdm(ruby_data.items()):
|
||||||
country_data = city_object["country"]
|
country_data = city_object['country']
|
||||||
country_code = country_data['code'] # i.e. fr
|
country_code = country_data['code'] # i.e. fr
|
||||||
try:
|
try:
|
||||||
country = Country.objects.get(
|
country = Country.objects.get(
|
||||||
|
|
@ -377,7 +377,7 @@ def add_correct_location_models(ruby_data):
|
||||||
city_object['region'] = region
|
city_object['region'] = region
|
||||||
|
|
||||||
if "subregion" in city_object:
|
if "subregion" in city_object:
|
||||||
del(city_object['subregion'])
|
del (city_object['subregion'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
City.objects.create(**city_object)
|
City.objects.create(**city_object)
|
||||||
|
|
@ -404,7 +404,7 @@ def fix_location_collection():
|
||||||
collections = Collection.objects.filter(old_id__isnull=False)
|
collections = Collection.objects.filter(old_id__isnull=False)
|
||||||
for collection in collections:
|
for collection in collections:
|
||||||
try:
|
try:
|
||||||
mysql_collection = transfer_models.Collections.objects.\
|
mysql_collection = transfer_models.Collections.objects. \
|
||||||
raw(f"""select
|
raw(f"""select
|
||||||
s.country_code_2,
|
s.country_code_2,
|
||||||
c.id
|
c.id
|
||||||
|
|
@ -425,7 +425,7 @@ def fix_location_collection():
|
||||||
def fix_award_type():
|
def fix_award_type():
|
||||||
award_types = AwardType.objects.filter(old_id__isnull=False)
|
award_types = AwardType.objects.filter(old_id__isnull=False)
|
||||||
for award_type in award_types:
|
for award_type in award_types:
|
||||||
mysql_award_type = transfer_models.AwardTypes.objects.\
|
mysql_award_type = transfer_models.AwardTypes.objects. \
|
||||||
raw(f"""SELECT at.id, s.country_code_2 AS country_code
|
raw(f"""SELECT at.id, s.country_code_2 AS country_code
|
||||||
FROM award_types as at
|
FROM award_types as at
|
||||||
JOIN sites s on s.id = at.site_id
|
JOIN sites s on s.id = at.site_id
|
||||||
|
|
@ -501,7 +501,6 @@ def fix_chosen_tag():
|
||||||
|
|
||||||
|
|
||||||
def fix_location_models():
|
def fix_location_models():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ruby_data_file = open(f"{settings.PROJECT_ROOT}/apps/location/ruby_data.py", "r")
|
ruby_data_file = open(f"{settings.PROJECT_ROOT}/apps/location/ruby_data.py", "r")
|
||||||
ruby_data = json.loads(ruby_data_file.read())
|
ruby_data = json.loads(ruby_data_file.read())
|
||||||
|
|
@ -541,11 +540,11 @@ def transfer_city_photos():
|
||||||
cities_has_same_image = 0
|
cities_has_same_image = 0
|
||||||
|
|
||||||
city_gallery = transfer_models.CityPhotos.objects.exclude(city__isnull=True) \
|
city_gallery = transfer_models.CityPhotos.objects.exclude(city__isnull=True) \
|
||||||
.exclude(city__country_code_2__isnull=True) \
|
.exclude(city__country_code_2__isnull=True) \
|
||||||
.exclude(city__country_code_2__iexact='') \
|
.exclude(city__country_code_2__iexact='') \
|
||||||
.exclude(city__region_code__isnull=True) \
|
.exclude(city__region_code__isnull=True) \
|
||||||
.exclude(city__region_code__iexact='') \
|
.exclude(city__region_code__iexact='') \
|
||||||
.values_list('city_id', 'attachment_suffix_url')
|
.values_list('city_id', 'attachment_suffix_url')
|
||||||
for old_city_id, image_suffix_url in tqdm(city_gallery):
|
for old_city_id, image_suffix_url in tqdm(city_gallery):
|
||||||
city = City.objects.filter(old_id=old_city_id)
|
city = City.objects.filter(old_id=old_city_id)
|
||||||
if city.exists():
|
if city.exists():
|
||||||
|
|
@ -639,7 +638,7 @@ def add_fake_country():
|
||||||
for region_data in regions_data:
|
for region_data in regions_data:
|
||||||
if "subregions" in region_data:
|
if "subregions" in region_data:
|
||||||
subregions = region_data['subregions']
|
subregions = region_data['subregions']
|
||||||
del(region_data['subregions'])
|
del (region_data['subregions'])
|
||||||
else:
|
else:
|
||||||
subregions = False
|
subregions = False
|
||||||
|
|
||||||
|
|
@ -665,16 +664,16 @@ def add_fake_country():
|
||||||
file = open(f"{settings.PROJECT_ROOT}/apps/location/csv/aa_cities.csv")
|
file = open(f"{settings.PROJECT_ROOT}/apps/location/csv/aa_cities.csv")
|
||||||
reader = csv.DictReader(file, delimiter=',')
|
reader = csv.DictReader(file, delimiter=',')
|
||||||
for city_data in reader:
|
for city_data in reader:
|
||||||
del(city_data[''])
|
del (city_data[''])
|
||||||
|
|
||||||
city_data['mysql_id'] = city_data['old_id']
|
city_data['mysql_id'] = city_data['old_id']
|
||||||
del(city_data['old_id'])
|
del (city_data['old_id'])
|
||||||
|
|
||||||
city_data['postal_code'] = city_data['zip_code']
|
city_data['postal_code'] = city_data['zip_code']
|
||||||
del(city_data['zip_code'])
|
del (city_data['zip_code'])
|
||||||
|
|
||||||
if city_data['postal_code'] == 'null' or city_data['postal_code'] == '':
|
if city_data['postal_code'] == 'null' or city_data['postal_code'] == '':
|
||||||
del(city_data['postal_code'])
|
del (city_data['postal_code'])
|
||||||
|
|
||||||
city_data["country"] = country
|
city_data["country"] = country
|
||||||
|
|
||||||
|
|
@ -683,10 +682,10 @@ def add_fake_country():
|
||||||
elif city_data['region'] != 'null':
|
elif city_data['region'] != 'null':
|
||||||
region = regions[city_data['region']]
|
region = regions[city_data['region']]
|
||||||
else:
|
else:
|
||||||
del(city_data['region'])
|
del (city_data['region'])
|
||||||
region = None
|
region = None
|
||||||
|
|
||||||
del(city_data['subregion'])
|
del (city_data['subregion'])
|
||||||
|
|
||||||
city_data['region'] = region
|
city_data['region'] = region
|
||||||
|
|
||||||
|
|
@ -700,7 +699,7 @@ def add_fake_country():
|
||||||
country.mysql_ids.append(city_data['mysql_id'])
|
country.mysql_ids.append(city_data['mysql_id'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mysql_data = transfer_models.Cities.objects.\
|
mysql_data = transfer_models.Cities.objects. \
|
||||||
only("map1", "map2", "map_ref", "situation").get(id=city_data['mysql_id'])
|
only("map1", "map2", "map_ref", "situation").get(id=city_data['mysql_id'])
|
||||||
city_data['map1'] = mysql_data.map1
|
city_data['map1'] = mysql_data.map1
|
||||||
city_data['map2'] = mysql_data.map2
|
city_data['map2'] = mysql_data.map2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user