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 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 pprint import pprint
|
||||
|
||||
|
|
@ -112,6 +114,13 @@ def transfer_addresses():
|
|||
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 = {
|
||||
"dictionaries": [
|
||||
|
|
@ -119,5 +128,8 @@ data_types = {
|
|||
transfer_regions,
|
||||
transfer_cities,
|
||||
transfer_addresses
|
||||
],
|
||||
"update_country_flag": [
|
||||
update_flags
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class Command(BaseCommand):
|
|||
"""Типы данных для трансфера
|
||||
ВНИМАНИЕ: первые буквы типов данных должны быть уникальны!
|
||||
"""
|
||||
DATA_TYPES = [
|
||||
SHORT_DATA_TYPES = [
|
||||
'dictionaries',
|
||||
'news',
|
||||
'account',
|
||||
|
|
@ -24,17 +24,36 @@ class Command(BaseCommand):
|
|||
'location_establishment'
|
||||
]
|
||||
|
||||
LONG_DATA_TYPES = [
|
||||
'update_country_flag'
|
||||
]
|
||||
|
||||
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:
|
||||
data_type = list(set(option for option in options.keys() if options[option]) & set(self.SHORT_DATA_TYPES))
|
||||
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")
|
||||
exit(1)
|
||||
transfer_objects(data_type[0])
|
||||
else:
|
||||
data_type = data_type[0]
|
||||
else:
|
||||
data_type = data_type[0]
|
||||
|
||||
transfer_objects(data_type)
|
||||
|
||||
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"""
|
||||
for option_type in self.DATA_TYPES:
|
||||
for option_type in self.SHORT_DATA_TYPES:
|
||||
parser.add_argument(
|
||||
f'-{option_type[:1]}',
|
||||
f'--{option_type}',
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ def transfer_objects(data_type):
|
|||
for app in apps.get_app_configs():
|
||||
if exists(f"{app.path}/transfer_data.py"):
|
||||
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
|
||||
|
||||
for module_data_type, transfer_funcs in card_module.data_types.items():
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user