Merge branch 'feature/fix-country-transfer' into develop
This commit is contained in:
commit
e2e95256d8
|
|
@ -1,6 +1,8 @@
|
||||||
from django.db.models import Q, QuerySet
|
from django.db.models import Q, QuerySet
|
||||||
|
|
||||||
from transfer.serializers.location import CountrySerializer, RegionSerializer, CitySerializer, AddressSerializer
|
from transfer.serializers.location import CountrySerializer, RegionSerializer, \
|
||||||
|
CitySerializer, AddressSerializer, \
|
||||||
|
Country
|
||||||
from transfer.models import Cities, Locations
|
from transfer.models import Cities, Locations
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
@ -112,6 +114,13 @@ def transfer_addresses():
|
||||||
pprint(f"Address serializer errors: {serialized_data.errors}")
|
pprint(f"Address serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
|
||||||
|
def update_flags():
|
||||||
|
queryset = Country.objects.only("id", "code", "svg_image").filter(old_id__isnull=False)
|
||||||
|
|
||||||
|
for query in queryset:
|
||||||
|
query.svg_image = f"/image/image/10-31-2019/{query.code}.svg"
|
||||||
|
query.save()
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
"dictionaries": [
|
"dictionaries": [
|
||||||
|
|
@ -119,5 +128,8 @@ data_types = {
|
||||||
transfer_regions,
|
transfer_regions,
|
||||||
transfer_cities,
|
transfer_cities,
|
||||||
transfer_addresses
|
transfer_addresses
|
||||||
|
],
|
||||||
|
"update_country_flag": [
|
||||||
|
update_flags
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class Command(BaseCommand):
|
||||||
"""Типы данных для трансфера
|
"""Типы данных для трансфера
|
||||||
ВНИМАНИЕ: первые буквы типов данных должны быть уникальны!
|
ВНИМАНИЕ: первые буквы типов данных должны быть уникальны!
|
||||||
"""
|
"""
|
||||||
DATA_TYPES = [
|
SHORT_DATA_TYPES = [
|
||||||
'dictionaries',
|
'dictionaries',
|
||||||
'news',
|
'news',
|
||||||
'account',
|
'account',
|
||||||
|
|
@ -24,17 +24,36 @@ class Command(BaseCommand):
|
||||||
'location_establishment'
|
'location_establishment'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
LONG_DATA_TYPES = [
|
||||||
|
'update_country_flag'
|
||||||
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
"""Находим включённую опцию путём пересечения множества типов данных и множества включённых опций"""
|
"""Находим включённую опцию путём пересечения множества типов данных и множества включённых опций"""
|
||||||
data_type = list(set(option for option in options.keys() if options[option]) & set(self.DATA_TYPES))
|
data_type = list(set(option for option in options.keys() if options[option]) & set(self.LONG_DATA_TYPES))
|
||||||
if len(data_type) != 1:
|
if len(data_type) != 1:
|
||||||
print("You must set correct option!\r\nYou can get options list with \r\n\r\n\tmanage.py help transfer\r\n")
|
data_type = list(set(option for option in options.keys() if options[option]) & set(self.SHORT_DATA_TYPES))
|
||||||
exit(1)
|
if len(data_type) != 1:
|
||||||
transfer_objects(data_type[0])
|
print("You must set correct option!\r\nYou can get options list with \r\n\r\n\tmanage.py help transfer\r\n")
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
data_type = data_type[0]
|
||||||
|
else:
|
||||||
|
data_type = data_type[0]
|
||||||
|
|
||||||
|
transfer_objects(data_type)
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
|
for option_type in self.LONG_DATA_TYPES:
|
||||||
|
parser.add_argument(
|
||||||
|
f'--{option_type}',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help=f'Transfer {option_type} objects'
|
||||||
|
)
|
||||||
|
|
||||||
"""Добавляем опции к команде, основываясь на типах данных, определённых в DATA_TYPES"""
|
"""Добавляем опции к команде, основываясь на типах данных, определённых в DATA_TYPES"""
|
||||||
for option_type in self.DATA_TYPES:
|
for option_type in self.SHORT_DATA_TYPES:
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
f'-{option_type[:1]}',
|
f'-{option_type[:1]}',
|
||||||
f'--{option_type}',
|
f'--{option_type}',
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ def transfer_objects(data_type):
|
||||||
for app in apps.get_app_configs():
|
for app in apps.get_app_configs():
|
||||||
if exists(f"{app.path}/transfer_data.py"):
|
if exists(f"{app.path}/transfer_data.py"):
|
||||||
card_module = SourceFileLoader("transfer", f"{app.path}/transfer_data.py").load_module()
|
card_module = SourceFileLoader("transfer", f"{app.path}/transfer_data.py").load_module()
|
||||||
if not hasattr(card_module, "data_types") or not isinstance(card_module.data_types, dict) or len(card_module.data_types) < 1:
|
if not hasattr(card_module, "data_types") \
|
||||||
|
or not isinstance(card_module.data_types, dict) \
|
||||||
|
or len(card_module.data_types) < 1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for module_data_type, transfer_funcs in card_module.data_types.items():
|
for module_data_type, transfer_funcs in card_module.data_types.items():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user