alchemy flush and save functions updated
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
|
||||
|
||||
confirmed_dict = {
|
||||
"is_confirmed": True,
|
||||
"active": True,
|
||||
"is_notification_send": True,
|
||||
"created_by": "System",
|
||||
"confirmed_by": "System",
|
||||
}
|
||||
|
||||
class TerminalColors:
|
||||
HEADER = '\033[95m'
|
||||
OKBLUE = '\033[94m'
|
||||
@@ -26,7 +18,7 @@ def do_alembic():
|
||||
|
||||
generate_alembic_with_session(text=text)
|
||||
|
||||
def create_one_address(confirmed_dict):
|
||||
def create_one_address():
|
||||
from databases import (
|
||||
AddressCity,
|
||||
AddressStreet,
|
||||
@@ -36,32 +28,32 @@ def create_one_address(confirmed_dict):
|
||||
AddressState,
|
||||
AddressCountry,
|
||||
)
|
||||
country = AddressCountry.find_or_create(
|
||||
country_name="TÜRKİYE", country_code="TR", **confirmed_dict
|
||||
)
|
||||
address_list = []
|
||||
country = AddressCountry.find_or_create(country_name="TÜRKİYE", country_code="TR")
|
||||
address_list.append(country)
|
||||
state = AddressState.find_or_create(
|
||||
state_name="TÜRKİYE",
|
||||
state_code="TR",
|
||||
phone_code="90",
|
||||
country_id=country.id,
|
||||
country_uu_id=str(country.uu_id),
|
||||
**confirmed_dict,
|
||||
)
|
||||
address_list.append(state)
|
||||
city = AddressCity.find_or_create(
|
||||
city_name="ANKARA",
|
||||
city_code="6",
|
||||
licence_plate="06",
|
||||
state_id=state.id,
|
||||
state_uu_id=str(state.uu_id),
|
||||
**confirmed_dict,
|
||||
)
|
||||
address_list.append(city)
|
||||
district = AddressDistrict.find_or_create(
|
||||
district_name="ÇANKAYA",
|
||||
district_code="1231",
|
||||
city_id=city.id,
|
||||
city_uu_id=str(city.uu_id),
|
||||
**confirmed_dict,
|
||||
)
|
||||
address_list.append(district)
|
||||
locality = AddressLocality.find_or_create(
|
||||
locality_name="MERKEZ",
|
||||
locality_code="2431",
|
||||
@@ -69,8 +61,8 @@ def create_one_address(confirmed_dict):
|
||||
type_description=None,
|
||||
district_id=district.id,
|
||||
district_uu_id=str(district.uu_id),
|
||||
**confirmed_dict,
|
||||
)
|
||||
address_list.append(locality)
|
||||
neighborhood = AddressNeighborhood.find_or_create(
|
||||
neighborhood_name="AYRANCI MAHALLESİ",
|
||||
neighborhood_code="1522",
|
||||
@@ -78,8 +70,8 @@ def create_one_address(confirmed_dict):
|
||||
type_description="MAHALLESİ",
|
||||
locality_id=locality.id,
|
||||
locality_uu_id=str(locality.uu_id),
|
||||
**confirmed_dict,
|
||||
)
|
||||
address_list.append(neighborhood)
|
||||
street = AddressStreet.find_or_create(
|
||||
street_name="REŞAT NURİ CADDESİ",
|
||||
type_description="CADDESİ",
|
||||
@@ -87,8 +79,12 @@ def create_one_address(confirmed_dict):
|
||||
street_code="52270",
|
||||
neighborhood_id=neighborhood.id,
|
||||
neighborhood_uu_id=str(neighborhood.uu_id),
|
||||
**confirmed_dict,
|
||||
)
|
||||
address_list.append(street)
|
||||
for address_single in address_list:
|
||||
address_single.save()
|
||||
address_single.is_confirmed = True
|
||||
address_single.save()
|
||||
return
|
||||
|
||||
|
||||
@@ -139,7 +135,7 @@ def create_application_defaults_func(create_address=False):
|
||||
try:
|
||||
if not create_address:
|
||||
return
|
||||
create_one_address(confirmed_dict=confirmed_dict)
|
||||
create_one_address()
|
||||
except Exception as e:
|
||||
print(f"{TerminalColors.WARNING} create_one_address Defaults Error", e)
|
||||
|
||||
@@ -147,8 +143,6 @@ def create_application_defaults_func(create_address=False):
|
||||
if __name__ == "__main__":
|
||||
print("Service App Initial Default Runner is running")
|
||||
do_alembic()
|
||||
init_alembic_address = True
|
||||
if init_alembic_address:
|
||||
create_application_defaults_func(create_address=False)
|
||||
create_application_defaults_func(create_address=True)
|
||||
print("Service App Initial Default Runner is completed")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user