Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed 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 project summary page.""" |
| 7 | from __future__ import print_function |
| 8 | from __future__ import division |
| 9 | from __future__ import absolute_import |
| 10 | |
| 11 | import logging |
| 12 | |
| 13 | from businesslogic import work_env |
| 14 | from framework import permissions |
| 15 | from framework import servlet |
| 16 | from project import project_helpers |
| 17 | from project import project_views |
| 18 | |
| 19 | from third_party import markdown |
| 20 | |
| 21 | |
| 22 | class ProjectSummary(servlet.Servlet): |
| 23 | """Page to show brief project description and process documentation.""" |
| 24 | |
| 25 | _PAGE_TEMPLATE = 'project/project-summary-page.ezt' |
| 26 | _MAIN_TAB_MODE = servlet.Servlet.MAIN_TAB_PROCESS |
| 27 | |
| 28 | def GatherPageData(self, mr): |
| 29 | """Build up a dictionary of data values to use when rendering the page.""" |
| 30 | |
| 31 | with mr.profiler.Phase('getting project star count'): |
| 32 | num_stars = self.services.project_star.CountItemStars( |
| 33 | mr.cnxn, mr.project_id) |
| 34 | plural = '' if num_stars == 1 else 's' |
| 35 | |
| 36 | page_data = { |
| 37 | 'admin_tab_mode': self.PROCESS_TAB_SUMMARY, |
| 38 | 'formatted_project_description': |
| 39 | markdown.Markdown(mr.project.description), |
| 40 | 'access_level': project_views.ProjectAccessView(mr.project.access), |
| 41 | 'num_stars': num_stars, |
| 42 | 'plural': plural, |
| 43 | 'home_page': mr.project.home_page, |
| 44 | 'docs_url': mr.project.docs_url, |
| 45 | 'source_url': mr.project.source_url, |
| 46 | } |
| 47 | |
| 48 | return page_data |
| 49 | |
| 50 | def GatherHelpData(self, mr, page_data): |
| 51 | """Return a dict of values to drive on-page user help. |
| 52 | |
| 53 | Args: |
| 54 | mr: common information parsed from the HTTP request. |
| 55 | page_data: Dictionary of base and page template data. |
| 56 | |
| 57 | Returns: |
| 58 | A dict of values to drive on-page user help, to be added to page_data. |
| 59 | """ |
| 60 | help_data = super(ProjectSummary, self).GatherHelpData(mr, page_data) |
| 61 | with work_env.WorkEnv(mr, self.services) as we: |
| 62 | userprefs = we.GetUserPrefs(mr.auth.user_id) |
| 63 | dismissed = [ |
| 64 | pv.name for pv in userprefs.prefs if pv.value == 'true'] |
| 65 | project = mr.project |
| 66 | |
| 67 | # Cue cards for project owners. |
| 68 | if self.CheckPerm(mr, permissions.EDIT_PROJECT): |
| 69 | if ('document_team_duties' not in dismissed and |
| 70 | len(project_helpers.AllProjectMembers(project)) > 1 and |
| 71 | not self.services.project.GetProjectCommitments( |
| 72 | mr.cnxn, mr.project_id).commitments): |
| 73 | help_data['cue'] = 'document_team_duties' |
| 74 | |
| 75 | return help_data |