blob: 65e2d9d0884d843fc82e9153d040a372a3c22e2a [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# 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."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import ezt
12
13from features import features_bizobj
14from features import hotlist_views
15from framework import framework_views
16from framework import servlet
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020017from framework import flaskservlet
Copybara854996b2021-09-07 19:36:02 +000018
19
20class 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ínezde942802022-07-15 14:06:55 +020085
86 # def GetUserHotlistsPage(self, **kwargs):
87 # return self.handler(**kwargs)
88
89 # def PostUserHotlistsPage(self, **kwargs):
90 # return self.handler(**kwargs)