예제 #1
0
    def update_devices(original: set, updated: set, replaced_place_id: str
                       or None):
        """
        Given the original set of devices of a place, and the updated version, it updates the database to achieve
        the updated set of devices.

        :param original:
        :param updated:
        :param replaced_place_id: The identifier of the replaced place. If updated is empty, this value is not used.
        :return:
        """
        devices_to_remove_id = original - updated
        children_to_remove_id = ComponentDomain.get_components_in_set(
            list(devices_to_remove_id))
        devices_to_remove_id |= children_to_remove_id

        devices_to_add_id = updated - original
        children_to_add_id = ComponentDomain.get_components_in_set(
            list(devices_to_add_id))
        devices_to_add_id |= children_to_add_id

        for device_id in devices_to_remove_id:
            PlaceDomain.device_unset_place(device_id)
        for device_id in devices_to_add_id:
            PlaceDomain.device_set_place(device_id, replaced_place_id)
예제 #2
0
파일: domain.py 프로젝트: eReuse/DeviceHub
    def update_devices(original: set, updated: set, replaced_place_id: str or None):
        """
        Given the original set of devices of a place, and the updated version, it updates the database to achieve
        the updated set of devices.

        :param original:
        :param updated:
        :param replaced_place_id: The identifier of the replaced place. If updated is empty, this value is not used.
        :return:
        """
        devices_to_remove_id = original - updated
        children_to_remove_id = ComponentDomain.get_components_in_set(list(devices_to_remove_id))
        devices_to_remove_id |= children_to_remove_id

        devices_to_add_id = updated - original
        children_to_add_id = ComponentDomain.get_components_in_set(list(devices_to_add_id))
        devices_to_add_id |= children_to_add_id

        for device_id in devices_to_remove_id:
            PlaceDomain.device_unset_place(device_id)
        for device_id in devices_to_add_id:
            PlaceDomain.device_set_place(device_id, replaced_place_id)
예제 #3
0
파일: hooks.py 프로젝트: eReuse/DeviceHub
def materialize_components(resource_name: str, events: list):
    """
    Materializes the field 'components' of selected events (not all of them) with the union of all the affected
    components, when the event is performed to computers
    :param resource_name:
    :param events:
    :return:
    """
    if resource_name in Event.resource_types:
        for event in events:
            sub_schema = current_app.config["DOMAIN"][resource_name]["schema"]
            if "components" in sub_schema and sub_schema["components"].get("readonly", False):
                event["components"] = list(ComponentDomain.get_components_in_set(event["devices"]))
예제 #4
0
def materialize_components(resource_name: str, events: list):
    """
    Materializes the field 'components' of selected events (not all of them) with the union of all the affected
    components, when the event is performed to computers
    :param resource_name:
    :param events:
    :return:
    """
    if resource_name in Event.resource_types:
        for event in events:
            sub_schema = current_app.config['DOMAIN'][resource_name]['schema']
            if 'components' in sub_schema and sub_schema['components'].get('readonly', False):
                event['components'] = list(ComponentDomain.get_components_in_set(event['devices']))