diff --git a/xivo_dao/resources/user/persistor.py b/xivo_dao/resources/user/persistor.py index f143b92b..6cd1e65f 100644 --- a/xivo_dao/resources/user/persistor.py +++ b/xivo_dao/resources/user/persistor.py @@ -58,7 +58,12 @@ def count_all_by(self, column_name, criteria): return query.all() def _search(self, parameters, is_collated=False): - view = self.user_view.select(parameters.get('view')) + selected_view = parameters.get('view') + if not selected_view: + limit = parameters.get('limit') or 0 + if 0 < limit < 101: + selected_view = 'paginated' + view = self.user_view.select(selected_view) query = view.query(self.session) if self.tenant_uuids is not None: query = query.filter(User.tenant_uuid.in_(self.tenant_uuids)) diff --git a/xivo_dao/resources/user/view.py b/xivo_dao/resources/user/view.py index eefa6e85..61912e40 100644 --- a/xivo_dao/resources/user/view.py +++ b/xivo_dao/resources/user/view.py @@ -14,6 +14,14 @@ from xivo_dao.alchemy.user_line import UserLine +class PaginatedView(View): + def query(self, session): + return session.query(User) + + def convert(self, model): + return model + + class UserView(View): def query(self, session): return session.query(User).options( @@ -137,5 +145,5 @@ def convert(self, row): user_view = ViewSelector( - default=UserView(), directory=DirectoryView(), summary=SummaryView() + default=UserView(), directory=DirectoryView(), summary=SummaryView(), paginated=PaginatedView(), )