o
    di	                     @   s"   d dl mZ G dd dejZdS )    )
paginationc                       s8   e Zd ZdZdZdd Zd
ddZd
 fdd		Z  ZS )CustomPaginationa  
    A custom pagination class that extends LimitOffsetPagination to provide custom behavior.

    Attributes:
        default_limit (int): The default limit for paginated results.

    Methods:
        __init__(): Initialize instance variables.
        paginate_queryset(queryset, request, view): Paginate the queryset based on the request and view.
        get_limit(request, total_count): Get the pagination limit based on the request query parameters.
    
   c                 C   s   d| _ d| _d| _d| _dS )zs
        Initialize instance variables.

        Args:
            None

        Returns:
            None
        N)requestoffsetlimitcount)self r
   I/var/www/html/evchargy.com/django-station-ev/station_ev/base/paginator.py__init__   s   

zCustomPagination.__init__Nc                 C   s   |  || _| j|| jd| _| jdu rdS | || _|| _| j| jkr-| jdur-d| _| jdks8| j| jkr:g S t	|| j| j| j  S )a~  
        Paginate the queryset based on the request and view.

        Args:
            queryset: The queryset to be paginated.
            request: The HTTP request.
            view: The view that handles the request.

        Returns:
            list or None: The paginated queryset based on the request parameters,
            or None if pagination is not applicable.
        )total_countNTr   )
	get_countr   	get_limitr   Z
get_offsetr   r   templatedisplay_page_controlslist)r	   querysetr   viewr
   r
   r   paginate_queryset"   s   
z"CustomPagination.paginate_querysetc                    s$   |j | jdkr|S t j|dS )a  
        Get the pagination limit based on the request query parameters.

        Args:
            request: The HTTP request.
            total_count: The total count of items in the queryset (optional).

        Returns:
            int: The limit for pagination.
        all)r   )query_paramsgetZlimit_query_paramsuperr   )r	   r   r   	__class__r
   r   r   =   s   zCustomPagination.get_limit)N)	__name__
__module____qualname____doc__Zdefault_limitr   r   r   __classcell__r
   r
   r   r   r      s    
r   N)rest_frameworkr   ZLimitOffsetPaginationr   r
   r
   r
   r   <module>   s    