Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: appengine/monorail/project/project_views.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 """View objects to help display projects in EZT."""
7
8 import logging
9 import time
10
11 from third_party import ezt
12
13 from framework import framework_constants
14 from framework import framework_helpers
15 from framework import permissions
16 from framework import template_helpers
17 from framework import timestr
18 from framework import urls
19 from proto import project_pb2
20
21
22 class ProjectAccessView(object):
23 """Object for project access information that can be easily used in EZT."""
24
25 ACCESS_NAMES = {
26 project_pb2.ProjectAccess.ANYONE: 'Anyone on the Internet',
27 project_pb2.ProjectAccess.MEMBERS_ONLY: 'Project Members',
28 }
29
30 def __init__(self, project_access_enum):
31 self.key = int(project_access_enum)
32 self.name = self.ACCESS_NAMES[project_access_enum]
33
34
35 class ProjectView(template_helpers.PBProxy):
36 """View object to make it easy to display a search result in EZT."""
37
38 _MAX_SUMMARY_CHARS = 70
39 _LIMITED_DESCRIPTION_CHARS = 500
40
41 def __init__(self, pb, starred=False, now=None, num_stars=None,
42 membership_desc=None):
43 super(ProjectView, self).__init__(pb)
44
45 self.limited_summary = template_helpers.FitUnsafeText(
46 pb.summary, self._MAX_SUMMARY_CHARS)
47
48 self.limited_description = template_helpers.FitUnsafeText(
49 pb.description, self._LIMITED_DESCRIPTION_CHARS)
50
51 self.state_name = str(pb.state) # Gives the enum name
52 self.relative_home_url = '/p/%s' % pb.project_name
53
54 if now is None:
55 now = time.time()
56
57 last_full_hour = now - (now % framework_constants.SECS_PER_HOUR)
58 self.cached_content_timestamp = max(
59 pb.cached_content_timestamp, last_full_hour)
60 self.last_updated_exists = ezt.boolean(pb.recent_activity)
61 course_grain, fine_grain = timestr.GetHumanScaleDate(pb.recent_activity)
62 if course_grain == 'Older':
63 self.recent_activity = fine_grain
64 else:
65 self.recent_activity = course_grain
66
67 self.starred = ezt.boolean(starred)
68
69 self.num_stars = num_stars
70 self.plural = '' if num_stars == 1 else 's'
71 self.membership_desc = membership_desc
72
73
74 class MemberView(object):
75 """EZT-view of details of how a person is participating in a project."""
76
77 def __init__(self, logged_in_user_id, member_id, user_view, project,
78 project_commitments, effective_ids=None):
79 """Initialize a MemberView with the given information.
80
81 Args:
82 logged_in_user_id: int user ID of the viewing user, or 0 for anon.
83 member_id: int user ID of the project member being viewed.
84 user_view: UserView object for this member.
85 project: Project PB for the currently viewed project.
86 project_commitments: ProjectCommitments PB for the currently viewed
87 project, or None if commitments are not to be displayed.
88 effective_ids: optional set of user IDs for this user, if supplied
89 we show the highest role that they have via any group membership.
90 """
91 self.viewing_self = ezt.boolean(logged_in_user_id == member_id)
92
93 self.user = user_view
94 member_qs_param = user_view.user_id
95 self.detail_url = '/p/%s%s?u=%s' % (
96 project.project_name, urls.PEOPLE_DETAIL, member_qs_param)
97 self.role = framework_helpers.GetRoleName(
98 effective_ids or {member_id}, project)
99 self.extra_perms = permissions.GetExtraPerms(project, member_id)
100 self.notes = None
101 if project_commitments is not None:
102 for commitment in project_commitments.commitments:
103 if commitment.member_id == member_id:
104 self.notes = commitment.notes
105 break
106
107 # Attributes needed by table_view_helpers.py
108 self.labels = []
109 self.derived_labels = []
OLDNEW
« no previous file with comments | « appengine/monorail/project/project_helpers.py ('k') | appengine/monorail/project/projectadmin.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698