Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2633)

Unified Diff: appengine/monorail/sitewide/projectsearch.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/monorail/sitewide/projectcreate.py ('k') | appengine/monorail/sitewide/sitewide_helpers.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/monorail/sitewide/projectsearch.py
diff --git a/appengine/monorail/sitewide/projectsearch.py b/appengine/monorail/sitewide/projectsearch.py
new file mode 100644
index 0000000000000000000000000000000000000000..ef7b07072e51d10fd995269841c1f9daa600ada5
--- /dev/null
+++ b/appengine/monorail/sitewide/projectsearch.py
@@ -0,0 +1,55 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Helper functions and classes used when searching for projects."""
+
+import logging
+
+from framework import framework_helpers
+from framework import paginate
+from framework import permissions
+
+
+DEFAULT_RESULTS_PER_PAGE = 10
+MAXIMUM_RESULT_PAGES_OFFERED = 10
+
+
+class ProjectSearchPipeline(object):
+ """Manage the process of project search, filter, fetch, and pagination."""
+
+ def __init__(self, mr, services, prof,
+ default_results_per_page=DEFAULT_RESULTS_PER_PAGE):
+
+ self.mr = mr
+ self.services = services
+ self.profiler = prof
+ self.default_results_per_page = default_results_per_page
+ self.pagination = None
+ self.allowed_project_ids = None
+ self.visible_results = None
+
+ def SearchForIDs(self):
+ """Get project IDs the user has permission to view."""
+ with self.profiler.Phase('getting user visible projects'):
+ self.allowed_project_ids = self.services.project.GetVisibleLiveProjects(
+ self.mr.cnxn, self.mr.auth.user_pb, self.mr.auth.effective_ids)
+ logging.info('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.
+
+ Args:
+ cnxn: connection to SQL database.
+ list_page_url: string page URL for prev and next links.
+ """
+ self.pagination = paginate.ArtifactPagination(
+ self.mr, self.allowed_project_ids, self.default_results_per_page,
+ list_page_url)
+ with self.profiler.Phase('getting projects on current pagination page'):
+ project_dict = self.services.project.GetProjects(
+ cnxn, self.pagination.visible_results)
+ self.visible_results = [
+ project_dict[pid] for pid in self.pagination.visible_results]
+ logging.info('visible_results is %r', self.visible_results)
« no previous file with comments | « appengine/monorail/sitewide/projectcreate.py ('k') | appengine/monorail/sitewide/sitewide_helpers.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698