def filter_queryset_service_type(queryset, type):
    """ Filters a given REST framework queryset by a given query.

    Only keeps elements which are of type 'type'.

    Args:
        queryset: A queryset containing elements
        type: A service type ('wms' or 'wfs')
    Returns:
        queryset: The given queryset which only contains matching elements
    """
    if type is not None and len(type) > 0:
        queryset = queryset.filter(
            service_type__name=type
        )
    return queryset