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