validations and dockerfiles are updated

This commit is contained in:
2025-01-10 12:40:52 +03:00
parent f4f9e584ff
commit 4eb95e4d9c
107 changed files with 400185 additions and 1338 deletions

View File

@@ -73,6 +73,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
]
creds = None # The credentials to use in the model.
lang = "tr" # The language to use in the model.
client_arrow: DateTimeLocal = None # The arrow to use in the model.
valid_record_dict: dict = {"active": True, "deleted": False}
valid_record_args = lambda class_: [class_.active == True, class_.deleted == False]
@@ -89,6 +90,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
def set_user_define_properties(cls, token):
cls.creds = token.credentials
cls.client_arrow = DateTimeLocal(is_client=True, timezone=token.timezone)
cls.lang = str(token.lang).lower()
@classmethod
def remove_non_related_inputs(cls, kwargs):
@@ -179,7 +181,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
"message": "",
}
return already_record
elif already_record.is_confirmed:
elif not already_record.is_confirmed:
already_record.meta_data = {
"created": False,
"error_case": "IsNotConfirmed",
@@ -202,7 +204,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
cls.created_by_id = cls.creds.get("person_id", None)
cls.created_by = cls.creds.get("person_name", None)
created_record.flush()
already_record.meta_data = {"created": True, "error_case": None, "message": ""}
created_record.meta_data = {"created": True, "error_case": None, "message": ""}
return created_record
@classmethod

View File

@@ -8,13 +8,14 @@ engine_config = {
"url": WagDatabase.DATABASE_URL,
"pool_size": 20,
"max_overflow": 10,
"echo": False,
"echo": True,
"echo_pool":True,
"isolation_level": "READ COMMITTED",
"pool_pre_ping": True,
}
engine = create_engine(**engine_config)
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False, echo=True)
engine = create_engine(**engine_config, )
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
session = scoped_session(sessionmaker(bind=engine))
Base = declarative_base()

View File

@@ -45,6 +45,31 @@ class FilterAttributes:
self.__session__.delete(self)
self.__session__.commit()
@classmethod
def save_via_metadata(cls):
"""Save the data via the metadata."""
try:
meta_data = getattr(cls, "meta_data", {})
meta_data_created = meta_data.get("created", False)
if meta_data_created:
print('meta_data_created commit', meta_data_created)
cls.__session__.commit()
print('meta_data_created rollback', meta_data_created)
cls.__session__.rollback()
# cls.raise_http_exception(
# status_code="HTTP_304_NOT_MODIFIED",
# error_case=meta_data.get("error_case", "Error on save and commit"),
# data={},
# message=meta_data.get("message", "Error on save and commit"),
# )
except SQLAlchemyError as e:
cls.raise_http_exception(
status_code="HTTP_304_NOT_MODIFIED",
error_case=e.__class__.__name__,
data={},
message=str(e.__context__).split("\n")[0],
)
@classmethod
def save(cls):
"""Saves the updated model to the current entity db."""
@@ -52,11 +77,15 @@ class FilterAttributes:
cls.__session__.commit()
except SQLAlchemyError as e:
cls.raise_http_exception(
status_code="HTTP_400_BAD_REQUEST",
status_code="HTTP_304_NOT_MODIFIED",
error_case=e.__class__.__name__,
data={},
message=str(e.__context__).split("\n")[0],
)
@classmethod
def rollback(cls):
"""Rollback the current session."""
cls.__session__.rollback()
def save_and_confirm(self):
"""Saves the updated model to the current entity db."""