blob: 316e1d52ce7e613a2a934d497c6db1ff06ecc466 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""A class to display the project summary page."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
Copybara854996b2021-09-07 19:36:02 +000010from businesslogic import work_env
11from framework import permissions
12from framework import servlet
13from project import project_helpers
14from project import project_views
15
Copybara854996b2021-09-07 19:36:02 +000016
17class ProjectSummary(servlet.Servlet):
18 """Page to show brief project description and process documentation."""
19
20 _PAGE_TEMPLATE = 'project/project-summary-page.ezt'
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010021 _MAIN_TAB_MODE = servlet.Servlet.MAIN_TAB_PROCESS
Copybara854996b2021-09-07 19:36:02 +000022
23 def GatherPageData(self, mr):
24 """Build up a dictionary of data values to use when rendering the page."""
25
26 with mr.profiler.Phase('getting project star count'):
27 num_stars = self.services.project_star.CountItemStars(
28 mr.cnxn, mr.project_id)
29 plural = '' if num_stars == 1 else 's'
30
31 page_data = {
32 'admin_tab_mode': self.PROCESS_TAB_SUMMARY,
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020033 'formatted_project_description': mr.project.description,
Copybara854996b2021-09-07 19:36:02 +000034 'access_level': project_views.ProjectAccessView(mr.project.access),
35 'num_stars': num_stars,
36 'plural': plural,
37 'home_page': mr.project.home_page,
38 'docs_url': mr.project.docs_url,
39 'source_url': mr.project.source_url,
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020040 }
Copybara854996b2021-09-07 19:36:02 +000041
42 return page_data
43
44 def GatherHelpData(self, mr, page_data):
45 """Return a dict of values to drive on-page user help.
46
47 Args:
48 mr: common information parsed from the HTTP request.
49 page_data: Dictionary of base and page template data.
50
51 Returns:
52 A dict of values to drive on-page user help, to be added to page_data.
53 """
54 help_data = super(ProjectSummary, self).GatherHelpData(mr, page_data)
55 with work_env.WorkEnv(mr, self.services) as we:
56 userprefs = we.GetUserPrefs(mr.auth.user_id)
57 dismissed = [
58 pv.name for pv in userprefs.prefs if pv.value == 'true']
59 project = mr.project
60
61 # Cue cards for project owners.
62 if self.CheckPerm(mr, permissions.EDIT_PROJECT):
63 if ('document_team_duties' not in dismissed and
64 len(project_helpers.AllProjectMembers(project)) > 1 and
65 not self.services.project.GetProjectCommitments(
66 mr.cnxn, mr.project_id).commitments):
67 help_data['cue'] = 'document_team_duties'
68
69 return help_data
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020070
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010071 def GetProjectSummaryPage(self, **kwargs):
72 return self.handler(**kwargs)