Source code for translator_directory.collections.time_report

from __future__ import annotations

from onegov.core.collection import GenericCollection, Pagination
from onegov.translator_directory.models.time_report import (
    TranslatorTimeReport,
)
from sqlalchemy import desc


from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from onegov.translator_directory.app import TranslatorDirectoryApp
    from sqlalchemy.orm import Query
    from typing import Self


[docs] class TimeReportCollection( GenericCollection[TranslatorTimeReport], Pagination[TranslatorTimeReport] ):
[docs] batch_size = 20
def __init__( self, app: TranslatorDirectoryApp, page: int = 0, ) -> None: super().__init__(app.session())
[docs] self.app = app
[docs] self.page = page
[docs] def __eq__(self, other: object) -> bool: return isinstance(other, self.__class__) and self.page == other.page
[docs] def query(self) -> Query[TranslatorTimeReport]: return self.session.query(TranslatorTimeReport).order_by( desc(TranslatorTimeReport.assignment_date) )
@property
[docs] def page_index(self) -> int: return self.page
[docs] def subset(self) -> Query[TranslatorTimeReport]: return self.query()
[docs] def page_by_index(self, index: int) -> Self: return self.__class__(self.app, page=index)