Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """A class to display the project summary page.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 10 | from businesslogic import work_env |
| 11 | from framework import permissions |
| 12 | from framework import servlet |
| 13 | from project import project_helpers |
| 14 | from project import project_views |
| 15 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 16 | |
| 17 | class 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 21 | _MAIN_TAB_MODE = servlet.Servlet.MAIN_TAB_PROCESS |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 22 | |
| 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ínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 33 | 'formatted_project_description': mr.project.description, |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 34 | '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ínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 40 | } |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 41 | |
| 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ínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 70 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 71 | def GetProjectSummaryPage(self, **kwargs): |
| 72 | return self.handler(**kwargs) |