示例#1
0
    def __init__(self,
                 pb,
                 starred=False,
                 now=None,
                 num_stars=None,
                 membership_desc=None):
        super(ProjectView, self).__init__(pb)

        self.limited_summary = template_helpers.FitUnsafeText(
            pb.summary, self._MAX_SUMMARY_CHARS)

        self.limited_description = template_helpers.FitUnsafeText(
            pb.description, self._LIMITED_DESCRIPTION_CHARS)

        self.state_name = str(pb.state)  # Gives the enum name
        self.relative_home_url = '/p/%s' % pb.project_name

        if now is None:
            now = time.time()

        last_full_hour = now - (now % framework_constants.SECS_PER_HOUR)
        self.cached_content_timestamp = max(pb.cached_content_timestamp,
                                            last_full_hour)
        self.last_updated_exists = ezt.boolean(pb.recent_activity)
        course_grain, fine_grain = timestr.GetHumanScaleDate(
            pb.recent_activity)
        if course_grain == 'Older':
            self.recent_activity = fine_grain
        else:
            self.recent_activity = course_grain

        self.starred = ezt.boolean(starred)

        self.num_stars = num_stars
        self.plural = '' if num_stars == 1 else 's'
        self.membership_desc = membership_desc
示例#2
0
    def __init__(self,
                 pb,
                 mr,
                 prefetched_issues,
                 users_by_id,
                 prefetched_projects,
                 prefetched_configs,
                 autolink=None,
                 all_ref_artifacts=None,
                 ending=None,
                 highlight=None):
        """Constructs an ActivityView out of an Activity protocol buffer.

    Args:
      pb: an IssueComment or Activity protocol buffer.
      mr: HTTP request info, used by the artifact autolink.
      prefetched_issues: dictionary of the issues for the comments being shown.
      users_by_id: dict {user_id: UserView} for all relevant users.
      prefetched_projects: dict {project_id: project} including all the projects
          that we might need.
      prefetched_configs: dict {project_id: config} for those projects.
      autolink: Autolink instance.
      all_ref_artifacts: list of all artifacts in the activity stream.
      ending: ending type for activity titles, 'in_project' or 'by_user'
      highlight: what to highlight in the middle column on user updates pages
          i.e. 'project', 'user', or None
    """
        template_helpers.PBProxy.__init__(self, pb)

        activity_type = 'ProjectIssueUpdate'  # TODO(jrobbins): more types

        self.comment = None
        self.issue = None
        self.field_changed = None
        self.multiple_fields_changed = ezt.boolean(False)
        self.project = None
        self.user = None
        self.timestamp = time.time(
        )  # Bogus value makes bad ones highly visible.

        if isinstance(pb, tracker_pb2.IssueComment):
            self.timestamp = pb.timestamp
            issue = prefetched_issues[pb.issue_id]
            if self.timestamp == issue.opened_timestamp:
                issue_change_id = None  # This comment is the description.
            else:
                issue_change_id = pb.timestamp  # instead of seq num.

            self.comment = tracker_views.IssueCommentView(
                mr.project_name, pb, users_by_id, autolink, all_ref_artifacts,
                mr, issue)

            # TODO(jrobbins): pass effective_ids of the commenter so that he/she
            # can be identified as a project member or not.
            config = prefetched_configs[issue.project_id]
            self.issue = tracker_views.IssueView(issue, users_by_id, config)
            self.user = self.comment.creator
            project = prefetched_projects[issue.project_id]
            self.project_name = project.project_name
            self.project = project_views.ProjectView(project)

        else:
            logging.warn('unknown activity object %r', pb)

        nested_page_data = {
            'activity_type': activity_type,
            'issue_change_id': issue_change_id,
            'comment': self.comment,
            'issue': self.issue,
            'project': self.project,
            'user': self.user,
            'timestamp': self.timestamp,
            'ending_type': ending,
        }

        self.escaped_title = self._TITLE_TEMPLATE.GetResponse(
            nested_page_data).strip()
        self.escaped_body = self._BODY_TEMPLATE.GetResponse(
            nested_page_data).strip()

        if autolink is not None and all_ref_artifacts is not None:
            # TODO(jrobbins): actually parse the comment text.  Actually render runs.
            runs = autolink.MarkupAutolinks(
                mr, [template_helpers.TextRun(self.escaped_body)],
                all_ref_artifacts)
            self.escaped_body = ''.join(run.content for run in runs)

        self.date_bucket, self.date_relative = timestr.GetHumanScaleDate(
            self.timestamp)
        time_tuple = time.localtime(self.timestamp)
        self.date_tooltip = time.asctime(time_tuple)

        # We always highlight the user for starring activities
        if activity_type.startswith('UserStar'):
            self.highlight = 'user'
        else:
            self.highlight = highlight
示例#3
0
 def GetDate(*args):
     date = datetime.datetime(*args)
     timestamp = time.mktime(date.timetuple())
     return timestr.GetHumanScaleDate(timestamp, now=now)