test application updated@build living space
This commit is contained in:
@@ -209,7 +209,6 @@ class UserLoginModule(AuthModule):
|
||||
People,
|
||||
MongoQueryIdentity,
|
||||
)
|
||||
|
||||
found_user = Users.check_user_exits(
|
||||
access_key=data.access_key, domain=data.domain
|
||||
)
|
||||
@@ -262,7 +261,7 @@ class UserLoginModule(AuthModule):
|
||||
record_id = uuid.uuid4().__str__()
|
||||
notice_link = ApiStatic.blacklist_login(record_id=record_id)
|
||||
found_people = People.filter_one(
|
||||
People.id == found_user.person_id, *People.valid_record_args(People)
|
||||
People.id == found_user.person_id
|
||||
).data
|
||||
access_via_user = query_engine.update_access_history_via_user(
|
||||
AccessHistoryViaUser(
|
||||
|
||||
@@ -19,6 +19,7 @@ from sqlalchemy import (
|
||||
Numeric,
|
||||
)
|
||||
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
from databases.extensions.selector_classes import SelectActionWithEmployee
|
||||
@@ -240,7 +241,6 @@ class Build(CrudCollection, SelectActionWithEmployee):
|
||||
if data.address_uu_id:
|
||||
official_address = Addresses.filter_one(
|
||||
Addresses.uu_id==data.address_uu_id,
|
||||
*Addresses.valid_record_args(Addresses)
|
||||
).data
|
||||
data_dict["address_id"] = official_address.id
|
||||
data_dict["build_no"] = str(official_address.build_number)
|
||||
@@ -305,7 +305,6 @@ class Build(CrudCollection, SelectActionWithEmployee):
|
||||
def livable_part_count(self):
|
||||
livable_parts = BuildParts.filter_all(
|
||||
BuildParts.build_id == self.id, BuildParts.human_livable == True,
|
||||
*BuildParts.valid_record_args(BuildParts)
|
||||
)
|
||||
if not livable_parts.data:
|
||||
raise HTTPException(
|
||||
@@ -422,7 +421,6 @@ class BuildParts(CrudCollection):
|
||||
|
||||
if build_types := BuildTypes.filter_one(
|
||||
BuildTypes.uu_id == data.build_part_type_uu_id,
|
||||
*BuildTypes.valid_record_args(BuildTypes)
|
||||
).data:
|
||||
part_direction = ApiEnumDropdown.get_by_uuid(
|
||||
uuid=str(data.part_direction_uu_id)
|
||||
@@ -554,15 +552,24 @@ class BuildLivingSpace(CrudCollection):
|
||||
from api_events.events.events.events_bind_services import (
|
||||
ServiceBindOccupantEventMethods,
|
||||
)
|
||||
|
||||
if data.get('expiry_starts'):
|
||||
data['expiry_starts'] = str(system_arrow.get(data['expiry_starts']))
|
||||
if data.get('expiry_ends'):
|
||||
data['expiry_ends'] = str(system_arrow.get(data['expiry_ends']))
|
||||
created_living_space = BuildLivingSpace.find_or_create(**data)
|
||||
occupant_type = OccupantTypes.find_one(
|
||||
occupant_type = OccupantTypes.filter_by_one(
|
||||
system=True,
|
||||
uu_id=created_living_space.occupant_type_uu_id
|
||||
)
|
||||
related_service = Services.find_one(
|
||||
active=True,
|
||||
).data
|
||||
related_service = Services.filter_by_one(
|
||||
related_responsibility=occupant_type.occupant_code,
|
||||
)
|
||||
**Services.valid_record_dict
|
||||
).data
|
||||
|
||||
created_living_space.save()
|
||||
created_living_space.is_confirmed = True
|
||||
created_living_space.save()
|
||||
|
||||
if not related_service:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
||||
@@ -584,7 +591,6 @@ class BuildLivingSpace(CrudCollection):
|
||||
or_(
|
||||
cls.owner_person_id == customer_id,
|
||||
cls.life_person_id == customer_id,
|
||||
*cls.valid_record_args(cls)
|
||||
),
|
||||
cls.start_date < formatted_date - timedelta(days=add_days),
|
||||
cls.stop_date > formatted_date + timedelta(days=add_days),
|
||||
|
||||
@@ -137,7 +137,6 @@ class BuildDecisionBook(CrudCollection):
|
||||
)
|
||||
related_building = Build.filter_all(
|
||||
Build.company_id.in_(related_companies_ids)
|
||||
* Build.valid_record_args(Build),
|
||||
)
|
||||
related_building_ids = list(related_.id for related_ in related_building.data)
|
||||
return cls.filter_all(cls.build_id.in_(related_building_ids)).query
|
||||
@@ -176,7 +175,6 @@ class BuildDecisionBook(CrudCollection):
|
||||
BuildDecisionBook.build_id == building.id,
|
||||
BuildDecisionBook.expiry_ends > data_dict["expiry_starts"],
|
||||
BuildDecisionBook.decision_type == data_dict.get("decision_type"),
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
).data: # Decision book is already exist:
|
||||
cls.raise_http_exception(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
@@ -485,6 +483,9 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
expires_at = str(
|
||||
system_arrow.get(decision_book.meeting_date).shift(days=15)
|
||||
)
|
||||
related_living_space.save()
|
||||
related_living_space.is_confirmed = True
|
||||
related_living_space.save()
|
||||
ServiceBindOccupantEventMethods.bind_services_occupant_system(
|
||||
build_living_space_id=related_living_space.id,
|
||||
service_id=related_service.id,
|
||||
@@ -496,9 +497,6 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
def get_occupant_types(self):
|
||||
if occupants := BuildDecisionBookPersonOccupants.filter_all(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id,
|
||||
*BuildDecisionBookPersonOccupants.valid_record_args(
|
||||
BuildDecisionBookPersonOccupants
|
||||
),
|
||||
).data:
|
||||
return occupants
|
||||
return
|
||||
@@ -1073,12 +1071,11 @@ class BuildDecisionBookProjects(CrudCollection):
|
||||
related_.id for related_ in related_companies.all()
|
||||
)
|
||||
related_building = Build.filter_all(
|
||||
Build.company_id.in_(related_companies_ids), *Build.valid_record_args(Build)
|
||||
Build.company_id.in_(related_companies_ids)
|
||||
)
|
||||
related_building_ids = list(related_.id for related_ in related_building.data)
|
||||
related_decision_books = BuildDecisionBook.filter_all(
|
||||
BuildDecisionBook.build_id.in_(related_building_ids),
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
).data
|
||||
related_decision_books_ids = list(
|
||||
related_.id for related_ in related_decision_books
|
||||
@@ -1087,14 +1084,12 @@ class BuildDecisionBookProjects(CrudCollection):
|
||||
BuildDecisionBookItems.build_decision_book_id.in_(
|
||||
related_decision_books_ids
|
||||
),
|
||||
*BuildDecisionBookItems.valid_record_args(BuildDecisionBookItems),
|
||||
).data
|
||||
related_decision_books_items_ids = list(
|
||||
related_.id for related_ in related_decision_books_items
|
||||
)
|
||||
return cls.filter_all(
|
||||
cls.build_decision_book_item_id.in_(related_decision_books_items_ids),
|
||||
*cls.valid_record_args(cls),
|
||||
).query
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -70,12 +70,10 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
list_match_company_id = []
|
||||
send_duties = Duties.filter_one(
|
||||
Duties.uu_id == data.duty_uu_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
)
|
||||
send_user_duties = Duties.filter_one(
|
||||
Duties.duties_id == send_duties.id,
|
||||
Duties.company_id == token_duties_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
)
|
||||
if not send_user_duties:
|
||||
raise Exception(
|
||||
@@ -85,13 +83,11 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
for company_uu_id in list(data.match_company_uu_id):
|
||||
company = Companies.filter_one(
|
||||
Companies.uu_id == company_uu_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
)
|
||||
bulk_company = RelationshipDutyCompany.filter_one(
|
||||
RelationshipDutyCompany.owner_id == token_company_id,
|
||||
RelationshipDutyCompany.relationship_type == "Bulk",
|
||||
RelationshipDutyCompany.member_id == company.id,
|
||||
*RelationshipDutyCompany.valid_record_args(RelationshipDutyCompany),
|
||||
)
|
||||
if not bulk_company:
|
||||
raise Exception(
|
||||
@@ -122,12 +118,10 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
list_match_company_id = []
|
||||
send_duties = Duties.filter_one(
|
||||
Duties.uu_id == data.duty_uu_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
)
|
||||
send_user_duties = Duties.filter_one(
|
||||
Duties.duties_id == send_duties.id,
|
||||
Duties.company_id == token_duties_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
)
|
||||
if not send_user_duties:
|
||||
raise Exception(
|
||||
@@ -137,13 +131,11 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
for company_uu_id in list(data.match_company_uu_id):
|
||||
company = Companies.filter_one(
|
||||
Companies.uu_id == company_uu_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
)
|
||||
bulk_company = RelationshipDutyCompany.filter_one(
|
||||
RelationshipDutyCompany.owner_id == token_company_id,
|
||||
RelationshipDutyCompany.relationship_type == "Bulk",
|
||||
RelationshipDutyCompany.member_id == company.id,
|
||||
*RelationshipDutyCompany.valid_record_args(RelationshipDutyCompany),
|
||||
)
|
||||
if not bulk_company:
|
||||
raise Exception(
|
||||
@@ -254,7 +246,6 @@ class Companies(CrudCollection, SelectAction):
|
||||
|
||||
official_address = Addresses.filter_one(
|
||||
Addresses.uu_id == data.official_address_uu_id,
|
||||
*Addresses.valid_record_args(Addresses),
|
||||
).data
|
||||
# if not official_address:
|
||||
# raise HTTPException(
|
||||
|
||||
@@ -164,7 +164,10 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
is_found can be used to check if the record was found or created.
|
||||
"""
|
||||
check_kwargs = cls.extract_system_fields(kwargs)
|
||||
cls.pre_query = cls.query.filter(cls.expiry_ends < system_arrow.now().date())
|
||||
cls.pre_query = cls.query.filter(
|
||||
cls.expiry_ends > str(system_arrow.now()),
|
||||
cls.expiry_starts <= str(system_arrow.now()),
|
||||
)
|
||||
already_record = cls.filter_by_one(system=True, **check_kwargs).data
|
||||
cls.pre_query = None
|
||||
if already_record:
|
||||
@@ -195,8 +198,8 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
if getattr(cls.creds, "person_id", None) and getattr(
|
||||
cls.creds, "person_name", None
|
||||
):
|
||||
cls.created_by_id = cls.creds.get("person_id", "Unknown")
|
||||
cls.created_by = cls.creds.get("person_name", "Unknown")
|
||||
cls.created_by_id = cls.creds.get("person_id", None)
|
||||
cls.created_by = cls.creds.get("person_name", None)
|
||||
created_record.flush()
|
||||
return created_record
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class Modules(CrudCollection):
|
||||
|
||||
def retrieve_services(self):
|
||||
services = Services.filter_all(
|
||||
Services.module_id == self.id, *Services.valid_record_args(Services)
|
||||
Services.module_id == self.id
|
||||
).data
|
||||
if not services:
|
||||
self.raise_http_exception(
|
||||
@@ -146,11 +146,11 @@ class Event2Employee(CrudCollection):
|
||||
@classmethod
|
||||
def get_event_id_by_employee_id(cls, employee_id) -> (list, list):
|
||||
active_events = cls.filter_all(
|
||||
cls.employee_id == employee_id, *cls.valid_record_args(cls)
|
||||
cls.employee_id == employee_id
|
||||
)
|
||||
active_events_id = [event.event_id for event in active_events.data]
|
||||
active_events = Events.filter_all(
|
||||
Events.id.in_(active_events_id), *Events.valid_record_args(Events)
|
||||
Events.id.in_(active_events_id)
|
||||
)
|
||||
active_events_uu_id = [str(event.uu_id) for event in active_events.data]
|
||||
return active_events_id, active_events_uu_id
|
||||
@@ -189,11 +189,10 @@ class Event2Occupant(CrudCollection):
|
||||
) -> (list, list):
|
||||
active_events = cls.filter_all(
|
||||
cls.build_living_space_id == build_living_space_id,
|
||||
*cls.valid_record_args(cls),
|
||||
).data
|
||||
active_events_id = [event.event_id for event in active_events]
|
||||
active_events = Events.filter_all(
|
||||
Events.id.in_(active_events_id), *Events.valid_record_args(Events)
|
||||
Events.id.in_(active_events_id)
|
||||
).data
|
||||
active_events_uu_id = [str(event.uu_id) for event in active_events]
|
||||
return active_events_id, active_events_uu_id
|
||||
|
||||
@@ -139,7 +139,6 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
def create_action(cls, create_user: InsertUsers):
|
||||
found_person = People.filter_one(
|
||||
People.uu_id == create_user.people_uu_id,
|
||||
*People.valid_record_args(People),
|
||||
).data
|
||||
if not found_person:
|
||||
raise HTTPException(status_code=400, detail="Person not found.")
|
||||
@@ -164,14 +163,19 @@ 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 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,
|
||||
"person_uu_id": str(person_object.uu_id),
|
||||
}
|
||||
return {
|
||||
"person_id": person_object.id,
|
||||
"person_uu_id": str(person_object.uu_id),
|
||||
"person_id": None,
|
||||
"person_uu_id": None,
|
||||
}
|
||||
|
||||
def get_employee_and_duty_details(self):
|
||||
@@ -179,7 +183,6 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
|
||||
found_person = People.filter_one(
|
||||
People.id==self.person_id,
|
||||
*People.valid_record_args(People),
|
||||
)
|
||||
found_employees = Employees.filter_by_active(
|
||||
people_id=found_person.id, is_confirmed=True
|
||||
@@ -460,9 +463,6 @@ class Addresses(CrudCollection):
|
||||
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
||||
RelationshipEmployee2PostCode.employee_id
|
||||
== token_dict.selected_company.employee_id,
|
||||
*RelationshipEmployee2PostCode.valid_record_args(
|
||||
RelationshipEmployee2PostCode
|
||||
),
|
||||
).data
|
||||
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
||||
if not post_code_id_list:
|
||||
@@ -471,7 +471,7 @@ class Addresses(CrudCollection):
|
||||
detail="User has no post code registered. User can not list addresses.",
|
||||
)
|
||||
cls.pre_query = cls.filter_all(
|
||||
cls.post_code_id.in_(post_code_id_list), cls.valid_record_args(cls)
|
||||
cls.post_code_id.in_(post_code_id_list)
|
||||
).query
|
||||
filter_cls = cls.filter_all(*filter_expr or [])
|
||||
cls.pre_query = None
|
||||
|
||||
@@ -48,7 +48,6 @@ class FilterAttributes:
|
||||
"""Saves the updated model to the current entity db."""
|
||||
try:
|
||||
cls.__session__.commit()
|
||||
return cls
|
||||
except SQLAlchemyError as e:
|
||||
cls.raise_http_exception(
|
||||
status_code="HTTP_400_BAD_REQUEST",
|
||||
@@ -122,14 +121,26 @@ class FilterAttributes:
|
||||
)
|
||||
return arg
|
||||
|
||||
@classmethod
|
||||
def get_active_and_confirmed_query_arg(cls, arg):
|
||||
"""Add active and confirmed to the query."""
|
||||
arg = cls.add_new_arg_to_args(
|
||||
arg, "is_confirmed", cls.is_confirmed == True
|
||||
)
|
||||
arg = cls.add_new_arg_to_args(
|
||||
arg, "active", cls.active == True
|
||||
)
|
||||
arg = cls.add_new_arg_to_args(
|
||||
arg, "deleted", cls.deleted == False
|
||||
)
|
||||
return arg
|
||||
|
||||
@classmethod
|
||||
def select_only(
|
||||
cls, *args, select_args: list, order_by=None, limit=None, system=False
|
||||
):
|
||||
if not system:
|
||||
args = cls.add_new_arg_to_args(
|
||||
args, "is_confirmed", cls.is_confirmed == True
|
||||
)
|
||||
args = cls.get_active_and_confirmed_query_arg(args)
|
||||
args = cls.get_not_expired_query_arg(args)
|
||||
query = cls._query().filter(*args).with_entities(*select_args)
|
||||
cls.total_count = query.count()
|
||||
@@ -175,9 +186,7 @@ class FilterAttributes:
|
||||
"""
|
||||
arg_left = lambda arg_obj: getattr(getattr(arg_obj, "left", None), "key", None)
|
||||
if not system:
|
||||
args = cls.add_new_arg_to_args(
|
||||
args, "is_confirmed", cls.is_confirmed == True
|
||||
)
|
||||
args = cls.get_active_and_confirmed_query_arg(args)
|
||||
args = cls.get_not_expired_query_arg(args)
|
||||
filter_list = cls.get_filter_attributes()
|
||||
if filter_list.get("query", None):
|
||||
@@ -199,9 +208,7 @@ class FilterAttributes:
|
||||
Filters one record regardless of is_deleted, is_confirmed.
|
||||
"""
|
||||
if not system:
|
||||
args = cls.add_new_arg_to_args(
|
||||
args, "is_confirmed", cls.is_confirmed == True
|
||||
)
|
||||
args = cls.get_active_and_confirmed_query_arg(args)
|
||||
args = cls.get_not_expired_query_arg(args)
|
||||
query = cls._query().filter(*args)
|
||||
cls.total_count = 1
|
||||
|
||||
Reference in New Issue
Block a user