<commit_before>from django.db.models import Q
from rest_framework.generics import CreateAPIView, ListAPIView, UpdateAPIView

from account.models import User
from agency.models import AgencyOffice
from agency.permissions import AgencyPermission
from common.permissions import HasUNPPPermission
from management.serializers import AgencyUserManagementSerializer, PartnerOfficeManagementSerializer, \
    AgencyOfficeManagementSerializer, PartnerUserManagementSerializer
from partner.models import Partner
from partner.permissions import PartnerPermission


class UserViewSet(CreateAPIView, ListAPIView, UpdateAPIView):

    permission_classes = (
        HasUNPPPermission(
            agency_permissions=[
                AgencyPermission.MANAGE_OWN_AGENCY_USERS,
            ],
            partner_permissions=[
                PartnerPermission.MANAGE_OFFICE_USERS,
            ]
        ),
    )

    def get_serializer_class(self):
        if self.request.agency_member:
            return AgencyUserManagementSerializer
        elif self.request.partner_member:
            return PartnerUserManagementSerializer

    def get_queryset(self):
        if self.request.agency_member:
            return User.objects.filter(agency_members__office__agency=self.request.user.agency)
        elif self.request.partner_member:
            query = Q(partner_members__partner=self.request.partner_member.partner)
            if self.request.partner_member.partner.is_hq:
                query |= Q(partner_members__partner__hq=self.request.partner_member.partner)

            return User.objects.filter(query)


class OfficeListView(ListAPIView):

    permission_classes = (
        HasUNPPPermission(
            agency_permissions=[
                AgencyPermission.MANAGE_OWN_AGENCY_USERS,
            ],
            partner_permissions=[
                PartnerPermission.MANAGE_OFFICE_USERS,
            ]
        ),
    )

    def get_queryset(self):
        if self.request.agency_member:
            return AgencyOffice.objects.filter(agency=self.request.user.agency)
        elif self.request.partner_member:
            query = Q(id=self.request.partner_member.partner_id)
            if self.request.partner_member.partner.is_hq:
                query |= Q(hq=self.request.partner_member.partner)

            return Partner.objects.filter(query)

    def get_serializer_class(self):
        if self.request.agency_member:
            return AgencyOfficeManagementSerializer
        elif self.request.partner_member:
            return PartnerOfficeManagementSerializer
<commit_msg>Added pagination to user management list<commit_after>from django.db.models import Q
from rest_framework.generics import CreateAPIView, ListAPIView, UpdateAPIView

from account.models import User
from agency.models import AgencyOffice
from agency.permissions import AgencyPermission
from common.pagination import SmallPagination
from common.permissions import HasUNPPPermission
from management.serializers import AgencyUserManagementSerializer, PartnerOfficeManagementSerializer, \
    AgencyOfficeManagementSerializer, PartnerUserManagementSerializer
from partner.models import Partner
from partner.permissions import PartnerPermission


class UserViewSet(CreateAPIView, ListAPIView, UpdateAPIView):

    permission_classes = (
        HasUNPPPermission(
            agency_permissions=[
                AgencyPermission.MANAGE_OWN_AGENCY_USERS,
            ],
            partner_permissions=[
                PartnerPermission.MANAGE_OFFICE_USERS,
            ]
        ),
    )
    pagination_class = SmallPagination

    def get_serializer_class(self):
        if self.request.agency_member:
            return AgencyUserManagementSerializer
        elif self.request.partner_member:
            return PartnerUserManagementSerializer

    def get_queryset(self):
        if self.request.agency_member:
            return User.objects.filter(agency_members__office__agency=self.request.user.agency)
        elif self.request.partner_member:
            query = Q(partner_members__partner=self.request.partner_member.partner)
            if self.request.partner_member.partner.is_hq:
                query |= Q(partner_members__partner__hq=self.request.partner_member.partner)

            return User.objects.filter(query)


class OfficeListView(ListAPIView):

    permission_classes = (
        HasUNPPPermission(
            agency_permissions=[
                AgencyPermission.MANAGE_OWN_AGENCY_USERS,
            ],
            partner_permissions=[
                PartnerPermission.MANAGE_OFFICE_USERS,
            ]
        ),
    )

    def get_queryset(self):
        if self.request.agency_member:
            return AgencyOffice.objects.filter(agency=self.request.user.agency)
        elif self.request.partner_member:
            query = Q(id=self.request.partner_member.partner_id)
            if self.request.partner_member.partner.is_hq:
                query |= Q(hq=self.request.partner_member.partner)

            return Partner.objects.filter(query)

    def get_serializer_class(self):
        if self.request.agency_member:
            return AgencyOfficeManagementSerializer
        elif self.request.partner_member:
            return PartnerOfficeManagementSerializer

{'fraction_non_alphanumeric': 0.06129398410896708, 'fraction_numerical': 0.0, 'mean_word_length': 2.870424597364568, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '514490', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1366, 'n_words': 233}