def apply_label(project_slug, buildings, select_all, label, search_params,
                user):
    """adds or updates a label for a ProjectBuilding related to a
       project and building in the buildings list of source_facility_ids

       :param project_slug: str, a slug to get a Project isnt.
       :param buildings: list, list of source_facility_id as str to get
       BuildingSnapshot inst.
       :param select_all: bool, if the select all checkbox was
       checked. i.e. should we get all buildings or just the ones in the list
       :param label: dict, dict of a info to get a StatusLabel inst., if label
       if an empty dict, apply_label will remove the label
       :search_params: dict, params needed to generate a queryset of buildings,
       with keys (q, other_params, project_slug)

    """
    if 'id' in label:
        label = StatusLabel.objects.get(pk=label['id'])
    else:
        label = None

    if select_all:
        # get all the buildings for a project minus unselected ones
        qs = get_search_query(user, search_params)
        pb_qs = ProjectBuilding.objects.filter(
            building_snapshot__in=qs,
            project__slug=project_slug
        ).exclude(
            building_snapshot__pk__in=buildings
        )
    else:
        # just add selected buildings
        pb_qs = ProjectBuilding.objects.filter(
            building_snapshot__pk__in=buildings,
            project__slug=project_slug,
        )
    pb_qs.update(
        status_label=label
    )
dataset/ETHPy150Open buildingenergy/buildingenergy-platform/seed/utils/projects.py/apply_label/original