fix transfer location
This commit is contained in:
parent
21978639bd
commit
59c9c06d64
|
|
@ -10,7 +10,7 @@ from tqdm import tqdm
|
||||||
from account.models import Role
|
from account.models import Role
|
||||||
from collection.models import Collection
|
from collection.models import Collection
|
||||||
from gallery.models import Image
|
from gallery.models import Image
|
||||||
from location.models import Country, Region, City, Address, CityGallery
|
from location.models import Country, Region, City, Address
|
||||||
from main.models import AwardType
|
from main.models import AwardType
|
||||||
from news.models import News
|
from news.models import News
|
||||||
from review.models import Review
|
from review.models import Review
|
||||||
|
|
@ -218,29 +218,6 @@ def migrate_city_map_situation(get_exists_cities=False):
|
||||||
pprint(f"City info serializer errors: {serialized_data.errors}")
|
pprint(f"City info serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
|
||||||
def migrate_city_photos():
|
|
||||||
queryset = transfer_models.CityPhotos.objects.raw("""SELECT city_photos.id, city_photos.city_id, city_photos.attachment_file_name
|
|
||||||
FROM city_photos WHERE
|
|
||||||
city_photos.attachment_file_name IS NOT NULL AND
|
|
||||||
city_id IN(
|
|
||||||
SELECT cities.id
|
|
||||||
FROM cities WHERE
|
|
||||||
region_code IS NOT NULL AND
|
|
||||||
region_code != "" AND
|
|
||||||
country_code_2 IS NOT NULL AND
|
|
||||||
country_code_2 != ""
|
|
||||||
)
|
|
||||||
""")
|
|
||||||
|
|
||||||
queryset = [vars(query) for query in queryset]
|
|
||||||
|
|
||||||
serialized_data = location_serializers.CityGallerySerializer(data=queryset, many=True)
|
|
||||||
if serialized_data.is_valid():
|
|
||||||
serialized_data.save()
|
|
||||||
else:
|
|
||||||
pprint(f"Address serializer errors: {serialized_data.errors}")
|
|
||||||
|
|
||||||
|
|
||||||
# Update location models with ruby library
|
# Update location models with ruby library
|
||||||
# Utils functions defined before transfer functions
|
# Utils functions defined before transfer functions
|
||||||
def get_ruby_socket(params):
|
def get_ruby_socket(params):
|
||||||
|
|
@ -554,7 +531,7 @@ def remove_old_records():
|
||||||
clean_old_region_records(Region, {"mysql_ids__isnull": True})
|
clean_old_region_records(Region, {"mysql_ids__isnull": True})
|
||||||
|
|
||||||
|
|
||||||
def transfer_city_gallery():
|
def transfer_city_photos():
|
||||||
created_counter = 0
|
created_counter = 0
|
||||||
cities_not_exists = {}
|
cities_not_exists = {}
|
||||||
cities_has_same_image = 0
|
cities_has_same_image = 0
|
||||||
|
|
@ -757,8 +734,8 @@ def setup_clean_db():
|
||||||
print('update_flags')
|
print('update_flags')
|
||||||
update_flags()
|
update_flags()
|
||||||
|
|
||||||
print('transfer_city_gallery')
|
print('transfer_city_photos')
|
||||||
transfer_city_gallery()
|
transfer_city_photos()
|
||||||
|
|
||||||
|
|
||||||
def set_unused_regions():
|
def set_unused_regions():
|
||||||
|
|
@ -811,9 +788,6 @@ data_types = {
|
||||||
"update_city_info": [
|
"update_city_info": [
|
||||||
migrate_city_map_situation
|
migrate_city_map_situation
|
||||||
],
|
],
|
||||||
"migrate_city_gallery": [
|
|
||||||
migrate_city_photos
|
|
||||||
],
|
|
||||||
"fix_location": [
|
"fix_location": [
|
||||||
add_fake_country,
|
add_fake_country,
|
||||||
fix_location_models,
|
fix_location_models,
|
||||||
|
|
@ -821,8 +795,8 @@ data_types = {
|
||||||
"remove_old_locations": [
|
"remove_old_locations": [
|
||||||
remove_old_records
|
remove_old_records
|
||||||
],
|
],
|
||||||
"fill_city_gallery": [
|
"migrate_city_photos": [
|
||||||
transfer_city_gallery,
|
transfer_city_photos,
|
||||||
],
|
],
|
||||||
"add_fake_country": [
|
"add_fake_country": [
|
||||||
add_fake_country,
|
add_fake_country,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ class Command(BaseCommand):
|
||||||
'product_review',
|
'product_review',
|
||||||
'newsletter_subscriber', # подписчики на рассылку - переносить после переноса пользователей №1
|
'newsletter_subscriber', # подписчики на рассылку - переносить после переноса пользователей №1
|
||||||
'purchased_plaques', # №6 - перенос купленных тарелок
|
'purchased_plaques', # №6 - перенос купленных тарелок
|
||||||
'fill_city_gallery', # №3 - перенос галереи городов
|
|
||||||
'guides',
|
'guides',
|
||||||
'guide_filters',
|
'guide_filters',
|
||||||
'guide_element_sections',
|
'guide_element_sections',
|
||||||
|
|
@ -51,7 +50,6 @@ class Command(BaseCommand):
|
||||||
'guide_element_label_photo',
|
'guide_element_label_photo',
|
||||||
'guide_complete',
|
'guide_complete',
|
||||||
'update_city_info',
|
'update_city_info',
|
||||||
'migrate_city_gallery',
|
|
||||||
'fix_location',
|
'fix_location',
|
||||||
'remove_old_locations',
|
'remove_old_locations',
|
||||||
'add_fake_country',
|
'add_fake_country',
|
||||||
|
|
|
||||||
|
|
@ -431,50 +431,6 @@ class CityMapCorrectSerializer(CityMapSerializer):
|
||||||
city.save()
|
city.save()
|
||||||
|
|
||||||
|
|
||||||
class CityGallerySerializer(serializers.ModelSerializer):
|
|
||||||
id = serializers.IntegerField()
|
|
||||||
city_id = serializers.IntegerField()
|
|
||||||
attachment_file_name = serializers.CharField()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = models.CityGallery
|
|
||||||
fields = ("id", "city_id", "attachment_file_name")
|
|
||||||
|
|
||||||
def validate(self, data):
|
|
||||||
data = self.set_old_id(data)
|
|
||||||
data = self.set_gallery(data)
|
|
||||||
data = self.set_city(data)
|
|
||||||
return data
|
|
||||||
|
|
||||||
def create(self, validated_data):
|
|
||||||
return models.CityGallery.objects.create(**validated_data)
|
|
||||||
|
|
||||||
def set_old_id(self, data):
|
|
||||||
data['old_id'] = data.pop('id')
|
|
||||||
return data
|
|
||||||
|
|
||||||
def set_gallery(self, data):
|
|
||||||
link_prefix = "city_photos/00baf486523f62cdf131fa1b19c5df2bf21fc9f8/"
|
|
||||||
try:
|
|
||||||
data['image'] = Image.objects.create(
|
|
||||||
image=f"{link_prefix}{data['attachment_file_name']}"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise ValueError(f"Cannot create image with {data}: {e}")
|
|
||||||
del(data['attachment_file_name'])
|
|
||||||
return data
|
|
||||||
|
|
||||||
def set_city(self, data):
|
|
||||||
try:
|
|
||||||
data['city'] = models.City.objects.get(old_id=data.pop('city_id'))
|
|
||||||
except models.City.DoesNotExist as e:
|
|
||||||
raise ValueError(f"Cannot get city with {data}: {e}")
|
|
||||||
except MultipleObjectsReturned as e:
|
|
||||||
raise ValueError(f"Multiple cities find with {data}: {e}")
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
class CepageWineRegionSerializer(TransferSerializerMixin):
|
class CepageWineRegionSerializer(TransferSerializerMixin):
|
||||||
|
|
||||||
CATEGORY_LABEL = 'Cepage'
|
CATEGORY_LABEL = 'Cepage'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user