blob: 8ef5feeb42c351dcb84a8618d8f760197d182d8f [file] [log] [blame]
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
"""Helper functions and classes used when searching for projects."""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import logging
from businesslogic import work_env
from framework import framework_helpers
from framework import paginate
from framework import permissions
class ProjectSearchPipeline(object):
"""Manage the process of project search, filter, fetch, and pagination."""
def __init__(self, mr, services,
default_results_per_page=DEFAULT_RESULTS_PER_PAGE): = mr = services
self.default_results_per_page = default_results_per_page
self.pagination = None
self.allowed_project_ids = None
self.visible_results = None
def SearchForIDs(self, domain=None):
"""Get project IDs the user has permission to view."""
with work_env.WorkEnv(, as we:
self.allowed_project_ids = we.ListProjects(domain=domain)'allowed_project_ids is %r', self.allowed_project_ids)
def GetProjectsAndPaginate(self, cnxn, list_page_url):
"""Paginate the filtered list of project names and retrieve Project PBs.
cnxn: connection to SQL database.
list_page_url: string page URL for prev and next links.
with'getting all projects'):
project_dict =
cnxn, self.allowed_project_ids)
project_list = sorted(
key=lambda p: p.project_name)'project_list is %r', project_list)
url_params = [(name, for name in
self.pagination = paginate.ArtifactPagination(
project_list,'num', self.default_results_per_page),'start'),,
list_page_url, url_params=url_params)
self.visible_results = self.pagination.visible_results