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 | """Page for showing a user's hotlists.""" |
| 7 | from __future__ import print_function |
| 8 | from __future__ import division |
| 9 | from __future__ import absolute_import |
| 10 | |
| 11 | import ezt |
| 12 | |
| 13 | from features import features_bizobj |
| 14 | from features import hotlist_views |
| 15 | from framework import framework_views |
| 16 | from framework import servlet |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 17 | from framework import flaskservlet |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 18 | |
| 19 | |
| 20 | class UserHotlists(servlet.Servlet): |
| 21 | """Servlet to display all of a user's hotlists.""" |
| 22 | |
| 23 | _PAGE_TEMPLATE = 'features/user-hotlists.ezt' |
| 24 | |
| 25 | def GatherPageData(self, mr): |
| 26 | viewed_users_hotlists = self.services.features.GetHotlistsByUserID( |
| 27 | mr.cnxn, mr.viewed_user_auth.user_id) |
| 28 | |
| 29 | viewed_starred_hids = self.services.hotlist_star.LookupStarredItemIDs( |
| 30 | mr.cnxn, mr.viewed_user_auth.user_id) |
| 31 | viewed_users_starred_hotlists, _ = self.services.features.GetHotlistsByID( |
| 32 | mr.cnxn, viewed_starred_hids) |
| 33 | |
| 34 | viewed_users_relevant_hotlists = viewed_users_hotlists + list( |
| 35 | set(viewed_users_starred_hotlists.values()) - |
| 36 | set(viewed_users_hotlists)) |
| 37 | |
| 38 | users_by_id = framework_views.MakeAllUserViews( |
| 39 | mr.cnxn, self.services.user, |
| 40 | features_bizobj.UsersInvolvedInHotlists(viewed_users_relevant_hotlists)) |
| 41 | |
| 42 | views = [hotlist_views.HotlistView( |
| 43 | hotlist_pb, mr.perms, mr.auth, mr.viewed_user_auth.user_id, |
| 44 | users_by_id, self.services.hotlist_star.IsItemStarredBy( |
| 45 | mr.cnxn, hotlist_pb.hotlist_id, mr.auth.user_id)) |
| 46 | for hotlist_pb in viewed_users_relevant_hotlists] |
| 47 | |
| 48 | # visible to viewer, not viewed_user |
| 49 | visible_hotlists = [view for view in views if view.visible] |
| 50 | |
| 51 | owner_of_hotlists = [hotlist_view for hotlist_view in visible_hotlists |
| 52 | if hotlist_view.role_name == 'owner'] |
| 53 | editor_of_hotlists = [hotlist_view for hotlist_view in visible_hotlists |
| 54 | if hotlist_view.role_name == 'editor'] |
| 55 | follower_of_hotlists = [hotlist_view for hotlist_view in visible_hotlists |
| 56 | if hotlist_view.role_name == ''] |
| 57 | starred_hotlists = [hotlist_view for hotlist_view in visible_hotlists |
| 58 | if hotlist_view.hotlist_id in viewed_starred_hids] |
| 59 | |
| 60 | viewed_user_display_name = framework_views.GetViewedUserDisplayName(mr) |
| 61 | |
| 62 | return { |
| 63 | 'user_tab_mode': 'st6', |
| 64 | 'viewed_user_display_name': viewed_user_display_name, |
| 65 | 'owner_of_hotlists': owner_of_hotlists, |
| 66 | 'editor_of_hotlists': editor_of_hotlists, |
| 67 | 'follower_of_hotlists': follower_of_hotlists, |
| 68 | 'starred_hotlists': starred_hotlists, |
| 69 | 'viewing_user_page': ezt.boolean(True), |
| 70 | } |
| 71 | |
| 72 | def GatherHelpData(self, mr, page_data): |
| 73 | """Return a dict of values to drive on-page user help. |
| 74 | |
| 75 | Args: |
| 76 | mr: common information parsed from the HTTP request. |
| 77 | page_data: Dictionary of base and page template data. |
| 78 | |
| 79 | Returns: |
| 80 | A dict of values to drive on-page user help, to be added to page_data. |
| 81 | """ |
| 82 | help_data = super(UserHotlists, self).GatherHelpData(mr, page_data) |
| 83 | help_data['cue'] = 'explain_hotlist_starring' |
| 84 | return help_data |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 85 | |
| 86 | # def GetUserHotlistsPage(self, **kwargs): |
| 87 | # return self.handler(**kwargs) |
| 88 | |
| 89 | # def PostUserHotlistsPage(self, **kwargs): |
| 90 | # return self.handler(**kwargs) |