Ë
    ×[Ãio+  ã                  ó�   — d dl mZ d dlZd dlmZ d dlZd dlm	Z
 d dlmZ d dlmZ  G d„ d«      Z G d„ d	e«      Z G d
„ de«      Zy)é    )ÚannotationsN)Úceil)Úabort)Úrequestc                  óX  — e Zd ZdZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zedddddœ	 	 	 	 	 	 	 	 	 dd„«       Zedd„«       Zdd„Z	dd	„Z
edd
„«       Zedd„«       Zedd„«       Zedd„«       Zed d„«       Zddœd!d„Zedd„«       Zed d„«       Zddœd!d„Zdddddœ	 	 	 	 	 	 	 	 	 d"d„Zd#d„Zy)$Ú
PaginationaU  Apply an offset and limit to the query based on the current page and number of
    items per page.

    Don't create pagination objects manually. They are created by
    :meth:`.SQLAlchemy.paginate` and :meth:`.Query.paginate`.

    This is a base class, a subclass must implement :meth:`_query_items` and
    :meth:`_query_count`. Those methods will use arguments passed as ``kwargs`` to
    perform the queries.

    :param page: The current page, used to calculate the offset. Defaults to the
        ``page`` query arg during a request, or 1 otherwise.
    :param per_page: The maximum number of items on a page, used to calculate the
        offset and limit. Defaults to the ``per_page`` query arg during a request,
        or 20 otherwise.
    :param max_per_page: The maximum allowed value for ``per_page``, to limit a
        user-provided value. Use ``None`` for no limit. Defaults to 100.
    :param error_out: Abort with a ``404 Not Found`` error if no items are returned
        and ``page`` is not 1, or if ``page`` or ``per_page`` is less than 1, or if
        either are not ints.
    :param count: Calculate the total number of values by issuing an extra count
        query. For very complex queries this may be inaccurate or slow, so it can be
        disabled and set manually if necessary.
    :param kwargs: Information about the query to paginate. Different subclasses will
        require different arguments.

    .. versionchanged:: 3.0
        Iterating over a pagination object iterates over its items.

    .. versionchanged:: 3.0
        Creating instances manually is not a public API.
    NTc                ó  — || _         | j                  ||||¬«      \  }}|| _        	 || _        	 || _        	 | j                  «       }|s|dk7  r|rt        d«       || _        	 |r| j                  «       }|| _	        y d }|| _	        y )N©ÚpageÚper_pageÚmax_per_pageÚ	error_outé   é”  )
Ú_query_argsÚ_prepare_page_argsr   r   r   Ú_query_itemsr   ÚitemsÚ_query_countÚtotal)	Úselfr   r   r   r   ÚcountÚkwargsr   r   s	            úS/var/www/timesheet/venv/lib/python3.12/site-packages/flask_sqlalchemy/pagination.pyÚ__init__zPagination.__init__.   s®   € ð "ˆÔØ×0Ñ0ØØØ%Øð	 1ó 
‰ˆˆhð ˆŒ	Øà%ˆŒØ4à(4ˆÔØ9à×!Ñ!Ó#ˆá˜ š¡yÜ�#ŒJà"'ˆŒ
ð	ñ Ø×%Ñ%Ó'ˆEð "'ˆŒ
Ø9ð ˆEà!&ˆŒ
Ø9ó    r
   c                óÞ  — t         rY| €*	 t        t         j                  j                  dd«      «      } |€3	 t        t         j                  j                  dd«      «      }n| €d} |€d}|�t        ||«      }| dk  r|rt        d«       nd} |dk  r|rt        d«       | |fS d}| |fS # t        t
        f$ r |rt        d«       d} Y Œ”w xY w# t        t
        f$ r |rt        d«       d}Y Œƒw xY w)Nr   r   r   r   é   )r   ÚintÚargsÚgetÚ	TypeErrorÚ
ValueErrorr   Úminr
   s       r   r   zPagination._prepare_page_argsZ   s  € õ Øˆ|ðÜœwŸ|™|×/Ñ/°¸Ó:Ó;�Dð Ðð"Ü"¤7§<¡<×#3Ñ#3°JÀÓ#CÓD‘Hð ˆ|Ø�àÐØ�àÐ#Ü˜8 \Ó2ˆHà�!Š8ÙÜ�c•
à�à�aŠ<ÙÜ�c”
ð �Xˆ~Ðð �à�Xˆ~ÐøôI "¤:Ð.ò Ù Ü˜cœ
à’Dð	ûô "¤:Ð.ò "Ù Ü˜cœ
à!’Hð	"ús"   Š)B' ¶)C Â'CÃCÃC,Ã+C,c                ó:   — | j                   dz
  | j                  z  S )z}The index of the first item to query, passed to ``offset()``.

        :meta private:

        .. versionadded:: 3.0
        r   )r   r   ©r   s    r   Ú_query_offsetzPagination._query_offsetŒ   s   € ð —	‘	˜A‘ §¡Ñ.Ð.r   c                ó   — t         ‚)z³Execute the query to get the items on the current page.

        Uses init arguments stored in :attr:`_query_args`.

        :meta private:

        .. versionadded:: 3.0
        ©ÚNotImplementedErrorr&   s    r   r   zPagination._query_items–   ó
   € ô "Ð!r   c                ó   — t         ‚)z¯Execute the query to get the total number of items.

        Uses init arguments stored in :attr:`_query_args`.

        :meta private:

        .. versionadded:: 3.0
        r)   r&   s    r   r   zPagination._query_count¡   r+   r   c                ór   — t        | j                  «      dk(  ry| j                  dz
  | j                  z  dz   S )z†The number of the first item on the page, starting from 1, or 0 if there are
        no items.

        .. versionadded:: 3.0
        r   r   )Úlenr   r   r   r&   s    r   ÚfirstzPagination.first¬   s3   € ô ˆt�z‰z‹?˜aÒØà—	‘	˜A‘ §¡Ñ.°Ñ2Ð2r   c                ód   — | j                   }t        ||t        | j                  «      z   dz
  «      S )z�The number of the last item on the page, starting from 1, inclusive, or 0 if
        there are no items.

        .. versionadded:: 3.0
        r   )r/   Úmaxr.   r   )r   r/   s     r   ÚlastzPagination.last¸   s,   € ð —
‘
ˆÜ�5˜%¤# d§j¡j£/Ñ1°AÑ5Ó6Ð6r   c                ó~   — | j                   dk(  s| j                   €yt        | j                   | j                  z  «      S )zThe total number of pages.r   )r   r   r   r&   s    r   ÚpageszPagination.pagesÂ   s3   € ð �:‰:˜Š?˜dŸj™jÐ0Øä�D—J‘J §¡Ñ.Ó/Ð/r   c                ó    — | j                   dkD  S )z'``True`` if this is not the first page.r   )r   r&   s    r   Úhas_prevzPagination.has_prevÊ   s   € ð �y‰y˜1‰}Ðr   c                ó:   — | j                   sy| j                  dz
  S )z@The previous page number, or ``None`` if this is the first page.Nr   )r6   r   r&   s    r   Úprev_numzPagination.prev_numÏ   ó   € ð �}Š}Øà�y‰y˜1‰}Ðr   F)r   c               ó–   —  t        | «      d| j                  dz
  | j                  |ddœ| j                  ¤Ž}| j                  |_        |S )a  Query the :class:`Pagination` object for the previous page.

        :param error_out: Abort with a ``404 Not Found`` error if no items are returned
            and ``page`` is not 1, or if ``page`` or ``per_page`` is less than 1, or if
            either are not ints.
        r   F)r   r   r   r   © )Útyper   r   r   r   ©r   r   Úps      r   ÚprevzPagination.prev×   sS   € ð ŒD�‹Jð 
Ø—‘˜Q‘Ø—]‘]ØØñ	
ð
 ×Ññ
ˆð —*‘*ˆŒØˆr   c                ó4   — | j                   | j                  k  S )z&``True`` if this is not the last page.)r   r4   r&   s    r   Úhas_nextzPagination.has_nextè   s   € ð �y‰y˜4Ÿ:™:Ñ%Ð%r   c                ó:   — | j                   sy| j                  dz   S )z;The next page number, or ``None`` if this is the last page.Nr   )rA   r   r&   s    r   Únext_numzPagination.next_numí   r9   r   c          	     ó¬   —  t        | «      d| j                  dz   | j                  | j                  |ddœ| j                  ¤Ž}| j
                  |_        |S )a  Query the :class:`Pagination` object for the next page.

        :param error_out: Abort with a ``404 Not Found`` error if no items are returned
            and ``page`` is not 1, or if ``page`` or ``per_page`` is less than 1, or if
            either are not ints.
        r   F)r   r   r   r   r   r;   )r<   r   r   r   r   r   r=   s      r   ÚnextzPagination.nextõ   s\   € ð ŒD�‹Jð 
Ø—‘˜Q‘Ø—]‘]Ø×*Ñ*ØØñ
ð ×Ññ
ˆð —*‘*ˆŒØˆr   é   é   )Ú	left_edgeÚleft_currentÚright_currentÚ
right_edgec             #  ó¨  K  — | j                   dz   }|dk(  ryt        d|z   |«      }t        d|«      E d{  –—†  ||k(  ryt        || j                  |z
  «      }t        | j                  |z   dz   |«      }||z
  dkD  rd–— t        ||«      E d{  –—†  ||k(  ryt        |||z
  «      }	|	|z
  dkD  rd–— t        |	|«      E d{  –—†  y7 Œ•7 Œ<7 Œ	­w)a‚  Yield page numbers for a pagination widget. Skipped pages between the edges
        and middle are represented by a ``None``.

        For example, if there are 20 pages and the current page is 7, the following
        values are yielded.

        .. code-block:: python

            1, 2, None, 5, 6, 7, 8, 9, 10, 11, None, 19, 20

        :param left_edge: How many pages to show from the first page.
        :param left_current: How many pages to show left of the current page.
        :param right_current: How many pages to show right of the current page.
        :param right_edge: How many pages to show from the last page.

        .. versionchanged:: 3.0
            Improved efficiency of calculating what to yield.

        .. versionchanged:: 3.0
            ``right_current`` boundary is inclusive.

        .. versionchanged:: 3.0
            All parameters are keyword-only.
        r   Nr   )r4   r$   Úranger1   r   )
r   rH   rI   rJ   rK   Ú	pages_endÚleft_endÚ	mid_startÚmid_endÚright_starts
             r   Ú
iter_pageszPagination.iter_pages  së   è ø€ ð@ —J‘J ‘Nˆ	à˜Š>Øä�q˜9‘} iÓ0ˆÜ˜˜HÓ%×%Ð%à�yÒ Øä˜ $§)¡)¨lÑ":Ó;ˆ	Ü�d—i‘i -Ñ/°!Ñ3°YÓ?ˆà�xÑ !Ò#ØŠJä˜ GÓ,×,Ð,à�iÒØä˜' 9¨zÑ#9Ó:ˆà˜Ñ  1Ò$ØŠJä˜ iÓ0×0Ñ0ð+ 	&øð 	-øð 	1ús4   ‚4C¶C·ACÂCÂ4CÃCÃCÃCÃCc              #  ó8   K  — | j                   E d {  –—†  y 7 Œ­w)N)r   r&   s    r   Ú__iter__zPagination.__iter__D  s   è ø€ Ø—:‘:×Òús   ‚’“)NNéd   TT)r   ú
int | Noner   rW   r   rW   r   Úboolr   rX   r   zt.AnyÚreturnÚNone)
r   rW   r   rW   r   rW   r   rX   rY   ztuple[int, int]©rY   r   ©rY   zlist[t.Any])rY   rX   )rY   rW   )r   rX   rY   r   )
rH   r   rI   r   rJ   r   rK   r   rY   zt.Iterator[int | None])rY   zt.Iterator[t.Any])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústaticmethodr   Úpropertyr'   r   r   r/   r2   r4   r6   r8   r?   rA   rC   rE   rS   rU   r;   r   r   r   r      s¿  „ ñðF  Ø#Ø#&ØØð*:àð*:ð ð*:ð !ð	*:ð
 ð*:ð ð*:ð ð*:ð 
ó*:ðX ð  Ø#Ø#'Øñ/àð/ð ð/ð !ð	/ð
 ð/ð 
ò/ó ð/ðb ò/ó ð/ó	"ó	"ð ò	3ó ð	3ð ò7ó ð7ð ò0ó ð0ð òó ðð òó ðð ).õ ð" ò&ó ð&ð òó ðð ).õ ð* ØØØñ;1ð ð;1ð ð	;1ð
 ð;1ð ð;1ð 
 ó;1ôzr   r   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚSelectPaginationzªReturned by :meth:`.SQLAlchemy.paginate`. Takes ``select`` and ``session``
    arguments in addition to the :class:`Pagination` arguments.

    .. versionadded:: 3.0
    c                ó  — | j                   d   }|j                  | j                  «      j                  | j                  «      }| j                   d   }t        |j                  |«      j                  «       j                  «       «      S )NÚselectÚsession)	r   Úlimitr   Úoffsetr'   ÚlistÚexecuteÚuniqueÚscalars)r   rf   rg   s      r   r   zSelectPagination._query_itemsO  sk   € Ø×!Ñ! (Ñ+ˆØ—‘˜dŸm™mÓ,×3Ñ3°D×4FÑ4FÓGˆØ×"Ñ" 9Ñ-ˆÜ�G—O‘O FÓ+×2Ñ2Ó4×<Ñ<Ó>Ó?Ð?r   c                ó~  — | j                   d   }|j                  t        j                  d«      «      j	                  d «      j                  «       }| j                   d   }|j                  t        j                  t        j                  j                  «       «      j                  |«      «      j                  «       }|S )Nrf   Ú*rg   )r   ÚoptionsÚsa_ormÚlazyloadÚorder_byÚsubqueryrk   Úsarf   Úfuncr   Úselect_fromÚscalar)r   rf   Úsubrg   Úouts        r   r   zSelectPagination._query_countU  s‡   € Ø×!Ñ! (Ñ+ˆØ�n‰nœVŸ_™_¨SÓ1Ó2×;Ñ;¸DÓA×JÑJÓLˆØ×"Ñ" 9Ñ-ˆØ�o‰oœbŸi™i¬¯©¯©«Ó8×DÑDÀSÓIÓJ×QÑQÓSˆØˆ
r   Nr\   r[   ©r]   r^   r_   r`   r   r   r;   r   r   rd   rd   H  s   „ ñó@ôr   rd   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚQueryPaginationz•Returned by :meth:`.Query.paginate`. Takes a ``query`` argument in addition to
    the :class:`Pagination` arguments.

    .. versionadded:: 3.0
    c                ó¨   — | j                   d   }|j                  | j                  «      j                  | j                  «      j                  «       }|S ©NÚquery)r   rh   r   ri   r'   Úall)r   r€   rz   s      r   r   zQueryPagination._query_itemsd  sC   € Ø× Ñ  Ñ)ˆØ�k‰k˜$Ÿ-™-Ó(×/Ñ/°×0BÑ0BÓC×GÑGÓIˆØˆ
r   c                ó^   — | j                   d   j                  d «      j                  «       }|S r   )r   rs   r   )r   rz   s     r   r   zQueryPagination._query_counti  s+   € à×Ñ˜wÑ'×0Ñ0°Ó6×<Ñ<Ó>ˆØˆ
r   Nr\   r[   r{   r;   r   r   r}   r}   ]  s   „ ñóô
r   r}   )Ú
__future__r   ÚtypingÚtÚmathr   Ú
sqlalchemyru   Úsqlalchemy.ormÚormrq   Úflaskr   r   r   rd   r}   r;   r   r   ú<module>r‹      s?   ðÝ "ã Ý ã Ý Ý Ý ÷yñ yôx	�zô ô*�jõ r   