OLD | NEW |
(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 """Classes for user updates pages. |
| 7 |
| 8 AbstractUserUpdatesPage: Base class for all user updates pages |
| 9 UserUpdatesProjects: Handles displaying starred projects |
| 10 UserUpdatesDevelopers: Handles displaying starred developers |
| 11 UserUpdatesIndividual: Handles displaying activities by the viewed user |
| 12 """ |
| 13 |
| 14 |
| 15 import logging |
| 16 |
| 17 from third_party import ezt |
| 18 |
| 19 from features import activities |
| 20 from framework import urls |
| 21 from sitewide import sitewide_helpers |
| 22 from sitewide import userprofile |
| 23 |
| 24 |
| 25 class AbstractUserUpdatesPage(userprofile.AbstractUserPage): |
| 26 """Base class for user updates pages.""" |
| 27 |
| 28 _PAGE_TEMPLATE = 'sitewide/user-updates-page.ezt' |
| 29 |
| 30 # Subclasses should override these constants. |
| 31 _UPDATES_PAGE_URL = None |
| 32 # What to highlight in the middle column on user updates pages - 'project', |
| 33 # 'user', or None |
| 34 _HIGHLIGHT = None |
| 35 # What the ending phrase for activity titles should be - 'by_user', |
| 36 # 'in_project', or None |
| 37 _ENDING = None |
| 38 _TAB_MODE = None |
| 39 |
| 40 def GatherPageData(self, mr): |
| 41 """Build up a dictionary of data values to use when rendering the page.""" |
| 42 # TODO(jrobbins): re-implement |
| 43 # if self.CheckRevelationCaptcha(mr, mr.errors): |
| 44 # mr.viewed_user_auth.user_view.RevealEmail() |
| 45 |
| 46 page_data = { |
| 47 'user_tab_mode': 'st5', |
| 48 'viewing_user_page': ezt.boolean(True), |
| 49 'user_updates_tab_mode': self._TAB_MODE, |
| 50 } |
| 51 |
| 52 user_ids = self._GetUserIDsForUpdates(mr) |
| 53 project_ids = self._GetProjectIDsForUpdates(mr) |
| 54 page_data.update(activities.GatherUpdatesData( |
| 55 self.services, mr, self.profiler, user_ids=user_ids, |
| 56 project_ids=project_ids, ending=self._ENDING, |
| 57 updates_page_url=self._UPDATES_PAGE_URL, highlight=self._HIGHLIGHT)) |
| 58 |
| 59 return page_data |
| 60 |
| 61 def _GetUserIDsForUpdates(self, _mr): |
| 62 """Returns a list of user IDs to retrieve activities from.""" |
| 63 return None # Means any. |
| 64 |
| 65 def _GetProjectIDsForUpdates(self, _mr): |
| 66 """Returns a list of project IDs to retrieve activities from.""" |
| 67 return None # Means any. |
| 68 |
| 69 |
| 70 class UserUpdatesProjects(AbstractUserUpdatesPage): |
| 71 """Shows a page of updates from projects starred by a user.""" |
| 72 |
| 73 _UPDATES_FEED_URL = urls.USER_UPDATES_PROJECTS |
| 74 _UPDATES_PAGE_URL = urls.USER_UPDATES_PROJECTS |
| 75 _HIGHLIGHT = 'project' |
| 76 _ENDING = 'by_user' |
| 77 _TAB_MODE = 'st2' |
| 78 |
| 79 def _GetProjectIDsForUpdates(self, mr): |
| 80 """Returns a list of project IDs whom to retrieve activities from.""" |
| 81 starred_projects = sitewide_helpers.GetViewableStarredProjects( |
| 82 mr.cnxn, self.services, mr.viewed_user_auth.user_id, |
| 83 mr.auth.effective_ids, mr.auth.user_pb) |
| 84 return [project.project_id for project in starred_projects] |
| 85 |
| 86 |
| 87 class UserUpdatesDevelopers(AbstractUserUpdatesPage): |
| 88 """Shows a page of updates from developers starred by a user.""" |
| 89 |
| 90 _UPDATES_FEED_URL = urls.USER_UPDATES_DEVELOPERS |
| 91 _UPDATES_PAGE_URL = urls.USER_UPDATES_DEVELOPERS |
| 92 _HIGHLIGHT = 'user' |
| 93 _ENDING = 'in_project' |
| 94 _TAB_MODE = 'st3' |
| 95 |
| 96 def _GetUserIDsForUpdates(self, mr): |
| 97 """Returns a list of user IDs whom to retrieve activities from.""" |
| 98 user_ids = self.services.user_star.LookupStarredItemIDs( |
| 99 mr.cnxn, mr.viewed_user_auth.user_id) |
| 100 logging.debug('StarredUsers: %r', user_ids) |
| 101 return user_ids |
| 102 |
| 103 |
| 104 class UserUpdatesIndividual(AbstractUserUpdatesPage): |
| 105 """Shows a page of updates initiated by a user.""" |
| 106 |
| 107 _UPDATES_FEED_URL = urls.USER_UPDATES_MINE + '/user' |
| 108 _UPDATES_PAGE_URL = urls.USER_UPDATES_MINE |
| 109 _HIGHLIGHT = 'project' |
| 110 _TAB_MODE = 'st1' |
| 111 |
| 112 def _GetUserIDsForUpdates(self, mr): |
| 113 """Returns a list of user IDs whom to retrieve activities from.""" |
| 114 return [mr.viewed_user_auth.user_id] |
OLD | NEW |