Creates a new instance template. It first creates the related instances and then saves the template and instances relations. :param session: SQL Alchemy Session. :param log: regular_log :param root_id: int :return:
(
session,
instance_id: int,
project,
log = regular_log.default())
| 45 | |
| 46 | |
| 47 | def instance_history_core( |
| 48 | session, |
| 49 | instance_id: int, |
| 50 | project, |
| 51 | log = regular_log.default()): |
| 52 | """ |
| 53 | Creates a new instance template. It first creates the related instances and then saves the template |
| 54 | and instances relations. |
| 55 | :param session: SQL Alchemy Session. |
| 56 | :param log: regular_log |
| 57 | :param root_id: int |
| 58 | :return: |
| 59 | """ |
| 60 | if project is None: |
| 61 | log['error']['project'] = 'Provide project object.' |
| 62 | return False, log |
| 63 | |
| 64 | if instance_id is None: |
| 65 | log['error']['root_id'] = 'Provide instance_id' |
| 66 | return False, log |
| 67 | |
| 68 | instance_child = Instance.get_by_id(session = session, instance_id = instance_id) |
| 69 | if instance_child.project_id != project.id: |
| 70 | log['error']['project_missmatch'] = 'Instance does not belong to the project.' |
| 71 | return False, log |
| 72 | |
| 73 | if instance_child.root_id is None: # We can still return itself |
| 74 | log['info']['root_id'] = 'Instance has no root ID' |
| 75 | return [instance_child.serialize_with_member_data(session)], log |
| 76 | |
| 77 | history_list = Instance.get_child_instance_history( |
| 78 | session = session, |
| 79 | root_id = instance_child.root_id) |
| 80 | |
| 81 | history_serialized = [instance.serialize_with_member_data(session) for instance in history_list] |
| 82 | |
| 83 | return history_serialized, log |
no test coverage detected