def __init__(self, request, response, services=None, *args, **kwargs): super(InboundEmail, self).__init__(request, response, *args, **kwargs) self.services = services or self.app.config.get('services') self._templates = {} for name, template_path in MSG_TEMPLATES.items(): self._templates[name] = template_helpers.MonorailTemplate( TEMPLATE_PATH_BASE + template_path, compress_whitespace=False, base_format=ezt.FORMAT_RAW)
def __init__(self, *args, **kwargs): super(NotifyTaskBase, self).__init__(*args, **kwargs) if not self._EMAIL_TEMPLATE: raise Exception('Subclasses must override _EMAIL_TEMPLATE.' ' This class must not be called directly.') # We use FORMAT_RAW for emails because they are plain text, not HTML. # TODO(jrobbins): consider sending HTML formatted emails someday. self.email_template = template_helpers.MonorailTemplate( framework_constants.TEMPLATE_PATH + self._EMAIL_TEMPLATE, compress_whitespace=False, base_format=ezt.FORMAT_RAW) if self._LINK_ONLY_EMAIL_TEMPLATE: self.link_only_email_template = template_helpers.MonorailTemplate( framework_constants.TEMPLATE_PATH + self._LINK_ONLY_EMAIL_TEMPLATE, compress_whitespace=False, base_format=ezt.FORMAT_RAW)
def __init__(self, request, response, services=None, content_type='text/html; charset=UTF-8'): """Load and parse the template, saving it for later use.""" super(Servlet, self).__init__(request, response) if self._PAGE_TEMPLATE: # specified in subclasses template_path = self._TEMPLATE_PATH + self._PAGE_TEMPLATE self.template = template_helpers.GetTemplate( template_path, eliminate_blank_lines=self._ELIMINATE_BLANK_LINES) else: self.template = None self._missing_permissions_template = template_helpers.MonorailTemplate( self._TEMPLATE_PATH + self._MISSING_PERMISSIONS_TEMPLATE) self.services = services or self.app.config.get('services') self.content_type = content_type self.mr = None self.ratelimiter = ratelimiter.RateLimiter()
class ActivityView(template_helpers.PBProxy): """EZT-friendly wrapper for Activities.""" _TITLE_TEMPLATE = template_helpers.MonorailTemplate( framework_constants.TEMPLATE_PATH + 'features/activity-title.ezt', compress_whitespace=True, base_format=ezt.FORMAT_HTML) _BODY_TEMPLATE = template_helpers.MonorailTemplate( framework_constants.TEMPLATE_PATH + 'features/activity-body.ezt', compress_whitespace=True, base_format=ezt.FORMAT_HTML) 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