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

Side by Side Diff: appengine/monorail/sitewide/hostinghome.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 unified diff | Download patch
« no previous file with comments | « appengine/monorail/sitewide/grouplist.py ('k') | appengine/monorail/sitewide/moved.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 """A class to display the hosting home page."""
7
8 import logging
9 from third_party import ezt
10
11 import settings
12 from framework import permissions
13 from framework import servlet
14 from framework import template_helpers
15 from framework import urls
16 from project import project_views
17 from sitewide import projectsearch
18 from sitewide import sitewide_helpers
19
20
21 class HostingHome(servlet.Servlet):
22 """HostingHome shows the Monorail site homepage and link to create a project.
23
24 This needs to be a full Servlet rather than just a static page
25 because we need to check permissions before offering the link to create
26 a project.
27 """
28
29 _PAGE_TEMPLATE = 'sitewide/hosting-home-page.ezt'
30
31 def GatherPageData(self, mr):
32 """Build up a dictionary of data values to use when rendering the page.
33
34 Args:
35 mr: commonly used info parsed from the request.
36
37 Returns:
38 Dict of values used by EZT for rendering the page.
39 """
40 can_create_project = permissions.CanCreateProject(mr.perms)
41
42 # Kick off the search pipeline, it has its own promises for parallelism.
43 pipeline = projectsearch.ProjectSearchPipeline(
44 mr, self.services, self.profiler)
45
46 # Meanwhile, determine which projects the signed-in user has starred.
47 starred_project_ids = set()
48 # A dict of project id to the user's membership status.
49 project_memberships = {}
50 if mr.auth.user_id:
51 starred_projects = sitewide_helpers.GetViewableStarredProjects(
52 mr.cnxn, self.services, mr.auth.user_id,
53 mr.auth.effective_ids, mr.auth.user_pb)
54 starred_project_ids = {p.project_id for p in starred_projects}
55
56 owned, _archive_owned, member_of, contrib_of = (
57 sitewide_helpers.GetUserProjects(
58 mr.cnxn, self.services, mr.auth.user_pb, mr.auth.effective_ids,
59 mr.auth.effective_ids))
60 project_memberships.update({proj.project_id: 'Owner' for proj in owned})
61 project_memberships.update(
62 {proj.project_id: 'Member' for proj in member_of})
63 project_memberships.update(
64 {proj.project_id: 'Contributor' for proj in contrib_of})
65
66 # Finish the project search pipeline.
67 pipeline.SearchForIDs()
68 pipeline.GetProjectsAndPaginate(mr.cnxn, urls.HOSTING_HOME)
69 project_ids = [p.project_id for p in pipeline.visible_results]
70 star_count_dict = self.services.project_star.CountItemsStars(
71 mr.cnxn, project_ids)
72
73 # Make ProjectView objects
74 project_view_list = [
75 project_views.ProjectView(
76 p, starred=p.project_id in starred_project_ids,
77 num_stars=star_count_dict.get(p.project_id),
78 membership_desc=project_memberships.get(p.project_id))
79 for p in pipeline.visible_results]
80 return {
81 'can_create_project': ezt.boolean(can_create_project),
82 'learn_more_link': settings.learn_more_link,
83 'projects': project_view_list,
84 'pagination': pipeline.pagination,
85 }
86
87
88 def _MakeExampleLabelGrid(label_list):
89 """Return a list of EZTItems to make it easy to display example searches."""
90 labels = label_list[:] # Don't mess with the given labels.
91
92 if len(labels) < 15:
93 cols = 4
94 elif len(labels) < 20:
95 cols = 5
96 else:
97 cols = 6
98
99 rows = []
100 while labels:
101 current_row = labels[:cols]
102 labels = labels[cols:]
103 rows.append(template_helpers.EZTItem(labels=current_row))
104
105 return rows
OLDNEW
« no previous file with comments | « appengine/monorail/sitewide/grouplist.py ('k') | appengine/monorail/sitewide/moved.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698