OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered by a BSD-style |
| 3 # license that can be found in the LICENSE file or at |
| 4 # https://developers.google.com/open-source/licenses/bsd |
| 5 |
| 6 """Helper functions and classes used when searching for projects.""" |
| 7 |
| 8 import logging |
| 9 |
| 10 from framework import framework_helpers |
| 11 from framework import paginate |
| 12 from framework import permissions |
| 13 |
| 14 |
| 15 DEFAULT_RESULTS_PER_PAGE = 10 |
| 16 MAXIMUM_RESULT_PAGES_OFFERED = 10 |
| 17 |
| 18 |
| 19 class ProjectSearchPipeline(object): |
| 20 """Manage the process of project search, filter, fetch, and pagination.""" |
| 21 |
| 22 def __init__(self, mr, services, prof, |
| 23 default_results_per_page=DEFAULT_RESULTS_PER_PAGE): |
| 24 |
| 25 self.mr = mr |
| 26 self.services = services |
| 27 self.profiler = prof |
| 28 self.default_results_per_page = default_results_per_page |
| 29 self.pagination = None |
| 30 self.allowed_project_ids = None |
| 31 self.visible_results = None |
| 32 |
| 33 def SearchForIDs(self): |
| 34 """Get project IDs the user has permission to view.""" |
| 35 with self.profiler.Phase('getting user visible projects'): |
| 36 self.allowed_project_ids = self.services.project.GetVisibleLiveProjects( |
| 37 self.mr.cnxn, self.mr.auth.user_pb, self.mr.auth.effective_ids) |
| 38 logging.info('allowed_project_ids is %r', self.allowed_project_ids) |
| 39 |
| 40 def GetProjectsAndPaginate(self, cnxn, list_page_url): |
| 41 """Paginate the filtered list of project names and retrieve Project PBs. |
| 42 |
| 43 Args: |
| 44 cnxn: connection to SQL database. |
| 45 list_page_url: string page URL for prev and next links. |
| 46 """ |
| 47 self.pagination = paginate.ArtifactPagination( |
| 48 self.mr, self.allowed_project_ids, self.default_results_per_page, |
| 49 list_page_url) |
| 50 with self.profiler.Phase('getting projects on current pagination page'): |
| 51 project_dict = self.services.project.GetProjects( |
| 52 cnxn, self.pagination.visible_results) |
| 53 self.visible_results = [ |
| 54 project_dict[pid] for pid in self.pagination.visible_results] |
| 55 logging.info('visible_results is %r', self.visible_results) |
OLD | NEW |