init defaults completed
This commit is contained in:
@@ -21,7 +21,7 @@ active_confirmed = dict(
|
||||
|
||||
def create_all_events_from_actions():
|
||||
import api_events.events as events
|
||||
|
||||
from databases import EndpointRestriction
|
||||
an_empty_list, duplicate_list = [], []
|
||||
|
||||
for event in events.__all__:
|
||||
@@ -32,26 +32,34 @@ def create_all_events_from_actions():
|
||||
) in event_selected.__event_keys__.items():
|
||||
an_empty_list.append(event_selected_key)
|
||||
event_selected_function = getattr(event_selected, event_selected_one, None)
|
||||
|
||||
if endpoint_match := event_selected.action_match:
|
||||
if not event_selected.action.endpoint:
|
||||
raise Exception(
|
||||
f"Endpoint not found in {event_selected.__name__} class"
|
||||
)
|
||||
endpoint_restriction = EndpointRestriction.filter_one(
|
||||
EndpointRestriction.endpoint_name.ilike(f"%{event_selected.action.endpoint}%"),
|
||||
system=True
|
||||
).data
|
||||
if endpoint_restriction:
|
||||
if event_selected_function:
|
||||
selected_event = Events.filter_one(
|
||||
Events.event_type==event_selected.event_type,
|
||||
Events.function_class==event,
|
||||
Events.function_code==event_selected_key,
|
||||
Events.endpoint_id==endpoint_match.id,
|
||||
Events.endpoint_uu_id==str(endpoint_match.uu_id),
|
||||
*Events.valid_record_args(Events)
|
||||
Events.endpoint_id==endpoint_restriction.id,
|
||||
Events.endpoint_uu_id==str(endpoint_restriction.uu_id),
|
||||
system=True
|
||||
).data
|
||||
if not selected_event:
|
||||
created_event = Events.create(
|
||||
created_event = Events.find_or_create(
|
||||
event_type=event_selected.event_type,
|
||||
function_class=event,
|
||||
function_code=event_selected_key,
|
||||
endpoint_id=endpoint_match.id,
|
||||
endpoint_uu_id=str(endpoint_match.uu_id),
|
||||
endpoint_id=endpoint_restriction.id,
|
||||
endpoint_uu_id=str(endpoint_restriction.uu_id),
|
||||
**active_confirmed
|
||||
)
|
||||
Events.save()
|
||||
print(f"Event created: {created_event.uu_id}")
|
||||
|
||||
for item in an_empty_list:
|
||||
@@ -63,19 +71,17 @@ def create_all_events_from_actions():
|
||||
raise Exception(
|
||||
f"Duplicate events found: {duplicate_list}. Check events folder look for given uu-ids."
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def add_events_all_services_and_occupant_types():
|
||||
import api_events.tasks2events as tasks2events
|
||||
|
||||
|
||||
for event_block in tasks2events.__all__:
|
||||
event_block_class = getattr(tasks2events, event_block)
|
||||
service_selected = Services.filter_one(
|
||||
Services.service_code==getattr(event_block_class, "service_code", None),
|
||||
*Services.valid_record_args(Services)
|
||||
system=True
|
||||
).data
|
||||
if not service_selected:
|
||||
raise Exception(f"{event_block_class.service_code} service is not found")
|
||||
@@ -90,21 +96,24 @@ def add_events_all_services_and_occupant_types():
|
||||
service_uu_id=str(service_selected.uu_id),
|
||||
event_id=event_id,
|
||||
event_uu_id=event_uu_id,
|
||||
**active_confirmed
|
||||
)
|
||||
Service2Events.save()
|
||||
Service2Events.is_confirmed = True
|
||||
Service2Events.save()
|
||||
return
|
||||
|
||||
|
||||
def add_events_to_system_super_user():
|
||||
|
||||
add_service = Services.filter_by_one(service_code="SRE-SUE", **Services.valid_record_dict).data
|
||||
add_service = Services.filter_by_one(system=True, service_code="SRE-SUE").data
|
||||
if not add_service:
|
||||
raise Exception("Service not found")
|
||||
|
||||
find_staff = Staff.filter_by_one(staff_code="SUE", **Staff.valid_record_dict).data
|
||||
find_staff = Staff.filter_by_one(system=True, staff_code="SUE").data
|
||||
if not find_staff:
|
||||
raise Exception("Super User not found")
|
||||
|
||||
add_employee = Employees.filter_by_one(staff_id=find_staff.id, **Employees.valid_record_dict).data
|
||||
add_employee = Employees.filter_by_one(system=True, staff_id=find_staff.id).data
|
||||
if not add_employee:
|
||||
raise Exception("Super User Employee not found")
|
||||
|
||||
@@ -112,3 +121,4 @@ def add_events_to_system_super_user():
|
||||
service_id=add_service.id,
|
||||
employee_id=add_employee.id,
|
||||
)
|
||||
Employees.save()
|
||||
|
||||
Reference in New Issue
Block a user