updated handler exceptions
This commit is contained in:
@@ -17,7 +17,7 @@ from sqlalchemy import (
|
||||
Numeric,
|
||||
Integer,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from api_validations.validations_request import (
|
||||
InsertDecisionBook,
|
||||
@@ -26,6 +26,19 @@ from api_validations.validations_request import (
|
||||
InsertBuildDecisionBookProjects,
|
||||
)
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
from databases.language_models.building.decision_book import (
|
||||
BuildDecisionBookLanguageModel,
|
||||
BuildDecisionBookInvitationsLanguageModel,
|
||||
BuildDecisionBookPersonLanguageModel,
|
||||
BuildDecisionBookPersonOccupantsLanguageModel,
|
||||
BuildDecisionBookItemsLanguageModel,
|
||||
BuildDecisionBookItemsUnapprovedLanguageModel,
|
||||
BuildDecisionBookPaymentsLanguageModel,
|
||||
BuildDecisionBookLegalLanguageModel,
|
||||
BuildDecisionBookProjectsLanguageModel,
|
||||
BuildDecisionBookProjectPersonLanguageModel,
|
||||
BuildDecisionBookProjectItemsLanguageModel,
|
||||
)
|
||||
|
||||
|
||||
class BuildDecisionBook(CrudCollection):
|
||||
@@ -44,6 +57,7 @@ class BuildDecisionBook(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookLanguageModel
|
||||
|
||||
decision_book_pdf_path: Mapped[str] = mapped_column(
|
||||
String, server_default="", nullable=True
|
||||
@@ -242,6 +256,7 @@ class BuildDecisionBookInvitations(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book_invitations"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookInvitationsLanguageModel
|
||||
|
||||
build_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
build_uu_id: Mapped[str] = mapped_column(
|
||||
@@ -341,6 +356,7 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
__tablename__ = "build_decision_book_person"
|
||||
__exclude__fields__ = []
|
||||
__enum_list__ = [("management_typecode", "BuildManagementType", "bm")]
|
||||
__language_model__ = BuildDecisionBookPersonLanguageModel
|
||||
|
||||
dues_percent_discount: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
dues_fix_discount: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
|
||||
@@ -517,6 +533,7 @@ class BuildDecisionBookPersonOccupants(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book_person_occupants"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookPersonOccupantsLanguageModel
|
||||
|
||||
build_decision_book_person_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("build_decision_book_person.id"), nullable=False
|
||||
@@ -559,6 +576,7 @@ class BuildDecisionBookItems(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book_items"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookItemsLanguageModel
|
||||
|
||||
item_order: Mapped[int] = mapped_column(
|
||||
SmallInteger, nullable=False, comment="Order Number of Item"
|
||||
@@ -799,6 +817,7 @@ class BuildDecisionBookItemsUnapproved(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book_items_unapproved"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookItemsUnapprovedLanguageModel
|
||||
|
||||
item_objection: Mapped[str] = mapped_column(
|
||||
Text, nullable=False, comment="Objection Content"
|
||||
@@ -841,6 +860,7 @@ class BuildDecisionBookPayments(CrudCollection):
|
||||
__tablename__ = "build_decision_book_payments"
|
||||
__exclude__fields__ = []
|
||||
__enum_list__ = [("receive_debit", "DebitTypes", "D")]
|
||||
__language_model__ = BuildDecisionBookPaymentsLanguageModel
|
||||
|
||||
payment_plan_time_periods: Mapped[str] = mapped_column(
|
||||
String(10), nullable=False, comment="Payment Plan Time Periods"
|
||||
@@ -951,6 +971,7 @@ class BuildDecisionBookLegal(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book_legal"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookLegalLanguageModel
|
||||
|
||||
period_start_date: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP(timezone=True), nullable=False, comment="Start Date of Legal Period"
|
||||
@@ -1027,6 +1048,7 @@ class BuildDecisionBookProjects(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book_projects"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookProjectsLanguageModel
|
||||
|
||||
project_no: Mapped[str] = mapped_column(
|
||||
String(12), nullable=True, comment="Project Number of Decision Book"
|
||||
@@ -1194,6 +1216,7 @@ class BuildDecisionBookProjectPerson(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book_project_person"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookProjectPersonLanguageModel
|
||||
# __enum_list__ = [("management_typecode", "ProjectTeamTypes", "PTT-EMP")]
|
||||
|
||||
dues_percent_discount: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
@@ -1226,6 +1249,7 @@ class BuildDecisionBookProjectItems(CrudCollection):
|
||||
|
||||
__tablename__ = "build_decision_book_project_items"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = BuildDecisionBookProjectItemsLanguageModel
|
||||
|
||||
item_header: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Item Header"
|
||||
|
||||
@@ -5,6 +5,13 @@ from sqlalchemy import (
|
||||
Numeric,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
from databases.language_models.company.employee import (
|
||||
StaffLanguageModel,
|
||||
EmployeesLanguageModel,
|
||||
EmployeeHistoryLanguageModel,
|
||||
EmployeesSalariesLanguageModel,
|
||||
)
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
from api_validations.validations_request import InsertCompanyEmployees
|
||||
@@ -14,6 +21,7 @@ class Staff(CrudCollection):
|
||||
|
||||
__tablename__ = "staff"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = StaffLanguageModel
|
||||
|
||||
staff_description: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Staff Description"
|
||||
@@ -61,6 +69,7 @@ class Employees(CrudCollection):
|
||||
|
||||
__tablename__ = "employees"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = EmployeesLanguageModel
|
||||
|
||||
staff_id: Mapped[int] = mapped_column(ForeignKey("staff.id"))
|
||||
staff_uu_id: Mapped[str] = mapped_column(
|
||||
@@ -81,6 +90,7 @@ class EmployeeHistory(CrudCollection):
|
||||
|
||||
__tablename__ = "employee_history"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = EmployeeHistoryLanguageModel
|
||||
|
||||
staff_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("staff.id"), nullable=False, comment="Staff ID"
|
||||
@@ -105,6 +115,7 @@ class EmployeesSalaries(CrudCollection):
|
||||
|
||||
__tablename__ = "employee_salaries"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = EmployeesSalariesLanguageModel
|
||||
|
||||
gross_salary: Mapped[float] = mapped_column(
|
||||
Numeric(20, 6), nullable=False, comment="Gross Salary"
|
||||
|
||||
@@ -21,7 +21,7 @@ from sqlalchemy_mixins.serialize import SerializeMixin
|
||||
from sqlalchemy_mixins.repr import ReprMixin
|
||||
from sqlalchemy_mixins.smartquery import SmartQueryMixin
|
||||
|
||||
from api_library import DateTimeLocal, client_arrow, system_arrow
|
||||
from api_library import DateTimeLocal, system_arrow
|
||||
from databases.sql_models.sql_operations import FilterAttributes
|
||||
from databases.sql_models.postgres_database import Base
|
||||
|
||||
@@ -138,14 +138,14 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
return True, int(val)
|
||||
elif key_ == Mapped[TIMESTAMP]:
|
||||
return True, str(
|
||||
cls.client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss")
|
||||
cls.client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss +0")
|
||||
)
|
||||
elif key_ == Mapped[str]:
|
||||
return True, str(val)
|
||||
else:
|
||||
if isinstance(val, datetime.datetime):
|
||||
return True, str(
|
||||
cls.client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss")
|
||||
cls.client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss +0")
|
||||
)
|
||||
elif isinstance(value_type, bool):
|
||||
return True, bool(val)
|
||||
|
||||
@@ -122,6 +122,9 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
person_uu_id: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Person UUID", index=True
|
||||
)
|
||||
local_timezone = mapped_column(
|
||||
String, server_default="GMT+3", comment="Local timezone of user"
|
||||
)
|
||||
person = relationship("People", back_populates="user", foreign_keys=[person_id])
|
||||
|
||||
@property
|
||||
@@ -183,11 +186,6 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
@classmethod
|
||||
def credentials(cls):
|
||||
person_object = People.filter_by_one(system=True, id=cls.person_id).data
|
||||
# if not person_object:
|
||||
# raise HTTPException(
|
||||
# status_code=401,
|
||||
# detail="Person not found. Please contact the admin.",
|
||||
# )
|
||||
if person_object:
|
||||
return {
|
||||
"person_id": person_object.id,
|
||||
|
||||
@@ -15,6 +15,7 @@ from databases.sql_models.core_mixin import CrudCollection
|
||||
class ApiEnumDropdown(CrudCollection):
|
||||
__tablename__ = "api_enum_dropdown"
|
||||
__exclude__fields__ = ["enum_class"]
|
||||
__language_model__ = None
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
uu_id: Mapped[str] = mapped_column(
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from sqlalchemy import String, Boolean
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
from databases.language_models.rules.rules import EndpointRestrictionLanguageModel
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
|
||||
class EndpointRestriction(CrudCollection):
|
||||
"""
|
||||
@@ -10,6 +12,7 @@ class EndpointRestriction(CrudCollection):
|
||||
|
||||
__tablename__ = "endpoint_restriction"
|
||||
__exclude__fields__ = []
|
||||
__language_model__ = EndpointRestrictionLanguageModel
|
||||
|
||||
endpoint_function: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Function name of the API endpoint"
|
||||
|
||||
@@ -50,18 +50,9 @@ class FilterAttributes:
|
||||
"""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)
|
||||
if meta_data.get("created", False):
|
||||
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",
|
||||
@@ -233,8 +224,9 @@ class FilterAttributes:
|
||||
for smart_iter in cls.filter_expr(**filter_list.get("query", {})):
|
||||
if key := arg_left(smart_iter):
|
||||
args = cls.add_new_arg_to_args(args, key, smart_iter)
|
||||
query = cls._query().filter(*args)
|
||||
query = cls._query()
|
||||
cls.total_count = query.count()
|
||||
query = query.filter(*args)
|
||||
if cls.filter_attr:
|
||||
data_query = cls.add_query_to_filter(query, filter_list)
|
||||
cls.filter_attr = None
|
||||
|
||||
Reference in New Issue
Block a user