"""考核模块按俱乐部过滤。"""
from jituan.constants import DATA_SCOPE_ALL
from jituan.services.club_context import resolve_club_id_from_request, resolve_club_scope
from users.business_models import User


def filter_shenhe_jilu_by_request(qs, request):
    """考核记录：按申请人（打手）所属俱乐部过滤。"""
    if resolve_club_scope(request) == DATA_SCOPE_ALL:
        return qs
    club_id = resolve_club_id_from_request(request)
    club_uids = list(
        User.query.filter(ClubID=club_id).values_list('UserUID', flat=True)
    )
    if not club_uids:
        return qs.none()
    return qs.filter(shenqingren_id__in=club_uids)


def yonghu_chenghao_qs_for_request(base_qs, request):
    """板块标签用户数统计：按俱乐部过滤打手。"""
    if resolve_club_scope(request) == DATA_SCOPE_ALL:
        return base_qs
    return base_qs.filter(yonghu__ClubID=resolve_club_id_from_request(request))
