示例#1
0
    def render_to_string(self, request, inline=True):
        """Renders the review UI to an HTML string.

        This renders the review UI to a string for use in embedding into
        either an existing page or a new page.

        If inline is True, the rendered review UI will be embeddable into
        an existing page.

        If inline is False, it will be rendered for use as a full, standalone
        page, compelte with Review Board chrome.
        """
        self.request = request

        last_activity_time, updated_object = \
            self.review_request.get_last_activity()

        draft = self.review_request.get_draft(request.user)
        review_request_details = draft or self.review_request
        context = {
            'caption': self.get_caption(draft),
            'comments': self.get_comments(),
            'draft': draft,
            'last_activity_time': last_activity_time,
            'review_request_details': review_request_details,
            'review_request': self.review_request,
            'review_ui': self,
            'review_ui_uuid': six.text_type(uuid4()),
            self.object_key: self.obj,
            self.diff_object_key: self.diff_against_obj,
        }

        if inline:
            context.update({
                'base_template': 'reviews/ui/base_inline.html',
                'review_ui_inline': True,
            })
        else:
            if self.review_request.repository_id:
                diffset_count = DiffSet.objects.filter(
                    history__pk=self.review_request.diffset_history_id).count()
            else:
                diffset_count = 0

            context.update({
                'base_template': 'reviews/ui/base.html',
                'has_diffs': (draft and draft.diffset) or diffset_count > 0,
                'review': self.review_request.get_pending_review(request.user),
                'review_ui_inline': False,
            })

        context.update(self.get_extra_context(request))

        return render_to_string(
            self.template_name,
            RequestContext(
                request,
                make_review_request_context(request, self.review_request,
                                            context)))
示例#2
0
    def render_to_response(self, request):
        if request.GET.get('inline', False):
            base_template_name = 'reviews/ui/base_inline.html'
        else:
            base_template_name = 'reviews/ui/base.html'

        self.request = request

        draft = self.review_request.get_draft(request.user)
        review_request_details = draft or self.review_request
        review = self.review_request.get_pending_review(request.user)

        if self.review_request.repository_id:
            diffset_count = DiffSet.objects.filter(
                history__pk=self.review_request.diffset_history_id).count()
        else:
            diffset_count = 0

        return render_to_response(
            self.template_name,
            RequestContext(
                request,
                make_review_request_context(request, self.review_request, {
                    'base_template': base_template_name,
                    'caption': self.get_caption(draft),
                    'comments': self.get_comments(),
                    'draft': draft,
                    'has_diffs': (draft and draft.diffset) or
                                 diffset_count > 0,
                    'review_request_details': review_request_details,
                    'review_request': self.review_request,
                    'review': review,
                    'review_ui': self,
                    'review_ui_uuid': str(uuid4()),
                    self.object_key: self.obj,
                }),
                **self.get_extra_context(request)))
示例#3
0
    def build_render_context(self, request, inline, **kwargs):
        """Build context for rendering the page.

        This computes the standard template context to use when rendering the
        page. Generally, subclasses should override
        :py:meth:`get_extra_context`, instead of this.

        Args:
            request (django.http.HttpRequest):
                The HTTP request from the client.

            inline (bool, optional):
                Whether to render this such that it can be embedded into an
                existing page, instead of as a standalone page.

        Returns:
            dict:
            The context to use in the template.
        """
        last_activity_time, updated_object = \
            self.review_request.get_last_activity()

        draft = self.review_request.get_draft(request.user)
        review_request_details = draft or self.review_request

        close_info = self.review_request.get_close_info()
        caption = self.get_caption(draft)

        context = make_review_request_context(request, self.review_request, {
            'caption': caption,
            'close_description': close_info['close_description'],
            'close_description_rich_text': close_info['is_rich_text'],
            'close_timestamp': close_info['timestamp'],
            'comments': self.get_comments(),
            'draft': draft,
            'last_activity_time': last_activity_time,
            'social_page_image_url': self.get_page_cover_image_url(),
            'social_page_title': (
                'Reviewable for Review Request #%s: %s'
                % (self.review_request.display_id, caption)
            ),
            'review_request_details': review_request_details,
            'review_request': self.review_request,
            'review_ui': self,
            'review_ui_uuid': six.text_type(uuid4()),
            self.object_key: self.obj,
            self.diff_object_key: self.diff_against_obj,
        })

        if inline:
            context.update({
                'base_template': 'reviews/ui/base_inline.html',
                'review_ui_inline': True,
            })
        else:
            context.update({
                'base_template': 'reviews/ui/base.html',
                'review': self.review_request.get_pending_review(request.user),
                'review_ui_inline': False,
            })

        try:
            context.update(self.get_extra_context(request))
        except Exception as e:
            logging.exception('Error when calling get_extra_context for '
                              '%r: %s',
                              self, e)

        return context
示例#4
0
    def build_render_context(self, request, inline, **kwargs):
        """Build context for rendering the page.

        This computes the standard template context to use when rendering the
        page. Generally, subclasses should override
        :py:meth:`get_extra_context`, instead of this.

        Args:
            request (django.http.HttpRequest):
                The HTTP request from the client.

            inline (bool, optional):
                Whether to render this such that it can be embedded into an
                existing page, instead of as a standalone page.

        Returns:
            dict:
            The context to use in the template.
        """
        last_activity_time, updated_object = \
            self.review_request.get_last_activity()

        draft = self.review_request.get_draft(request.user)
        review_request_details = draft or self.review_request

        close_info = self.review_request.get_close_info()
        caption = self.get_caption(draft)

        context = make_review_request_context(
            request, self.review_request, {
                'caption':
                caption,
                'close_description':
                close_info['close_description'],
                'close_description_rich_text':
                close_info['is_rich_text'],
                'close_timestamp':
                close_info['timestamp'],
                'comments':
                self.get_comments(),
                'draft':
                draft,
                'last_activity_time':
                last_activity_time,
                'social_page_image_url':
                self.get_page_cover_image_url(),
                'social_page_title':
                ('Reviewable for Review Request #%s: %s' %
                 (self.review_request.display_id, caption)),
                'review_request_details':
                review_request_details,
                'review_request':
                self.review_request,
                'review_ui':
                self,
                'review_ui_uuid':
                six.text_type(uuid4()),
                self.object_key:
                self.obj,
                self.diff_object_key:
                self.diff_against_obj,
            })

        if inline:
            context.update({
                'base_template': 'reviews/ui/base_inline.html',
                'review_ui_inline': True,
            })
        else:
            context.update({
                'base_template':
                'reviews/ui/base.html',
                'review':
                self.review_request.get_pending_review(request.user),
                'review_ui_inline':
                False,
            })

        try:
            context.update(self.get_extra_context(request))
        except Exception as e:
            logging.exception(
                'Error when calling get_extra_context for '
                '%r: %s', self, e)

        return context
示例#5
0
    def render_to_string(self, request, inline=True):
        """Renders the review UI to an HTML string.

        This renders the review UI to a string for use in embedding into
        either an existing page or a new page.

        If inline is True, the rendered review UI will be embeddable into
        an existing page.

        If inline is False, it will be rendered for use as a full, standalone
        page, compelte with Review Board chrome.
        """
        self.request = request

        last_activity_time, updated_object = \
            self.review_request.get_last_activity()

        draft = self.review_request.get_draft(request.user)
        review_request_details = draft or self.review_request

        close_description, close_description_rich_text = \
            self.review_request.get_close_description()

        context = {
            'caption': self.get_caption(draft),
            'close_description': close_description,
            'close_description_rich_text': close_description_rich_text,
            'comments': self.get_comments(),
            'draft': draft,
            'last_activity_time': last_activity_time,
            'review_request_details': review_request_details,
            'review_request': self.review_request,
            'review_ui': self,
            'review_ui_uuid': six.text_type(uuid4()),
            self.object_key: self.obj,
            self.diff_object_key: self.diff_against_obj,
        }

        if inline:
            context.update({
                'base_template': 'reviews/ui/base_inline.html',
                'review_ui_inline': True,
            })
        else:
            if self.review_request.repository_id:
                diffset_count = DiffSet.objects.filter(
                    history__pk=self.review_request.diffset_history_id).count(
                    )
            else:
                diffset_count = 0

            context.update({
                'base_template':
                'reviews/ui/base.html',
                'has_diffs': (draft and draft.diffset) or diffset_count > 0,
                'review':
                self.review_request.get_pending_review(request.user),
                'review_ui_inline':
                False,
            })
        try:
            context.update(self.get_extra_context(request))
        except Exception as e:
            logging.error(
                'Error when calling get_extra_context for '
                'FileAttachmentReviewUI %r: %s',
                self,
                e,
                exc_info=1)
        try:
            return render_to_string(
                self.template_name,
                RequestContext(
                    request,
                    make_review_request_context(request, self.review_request,
                                                context)))
        except Exception as e:
            logging.error(
                'Error when calling get_js_model_data or '
                'get_js_view_data for FileAttachmentReviewUI '
                '%r: %s',
                self,
                e,
                exc_info=1)
示例#6
0
    def render_to_string(self, request, inline=True):
        """Renders the review UI to an HTML string.

        This renders the review UI to a string for use in embedding into
        either an existing page or a new page.

        If inline is True, the rendered review UI will be embeddable into
        an existing page.

        If inline is False, it will be rendered for use as a full, standalone
        page, compelte with Review Board chrome.
        """
        self.request = request

        last_activity_time, updated_object = \
            self.review_request.get_last_activity()

        draft = self.review_request.get_draft(request.user)
        review_request_details = draft or self.review_request

        close_description, close_description_rich_text = \
            self.review_request.get_close_description()
        caption = self.get_caption(draft)

        context = make_review_request_context(request, self.review_request, {
            'caption': caption,
            'close_description': close_description,
            'close_description_rich_text': close_description_rich_text,
            'comments': self.get_comments(),
            'draft': draft,
            'last_activity_time': last_activity_time,
            'social_page_image_url': self.get_page_cover_image_url(),
            'social_page_title': (
                'Attachment for Review Request #%s: %s'
                % (self.review_request.display_id, caption)
            ),
            'review_request_details': review_request_details,
            'review_request': self.review_request,
            'review_ui': self,
            'review_ui_uuid': six.text_type(uuid4()),
            self.object_key: self.obj,
            self.diff_object_key: self.diff_against_obj,
        })

        if inline:
            context.update({
                'base_template': 'reviews/ui/base_inline.html',
                'review_ui_inline': True,
            })
        else:
            context['tabs'].append({
                'url': request.path,
                'text': _('File'),
            })

            context.update({
                'base_template': 'reviews/ui/base.html',
                'review': self.review_request.get_pending_review(request.user),
                'review_ui_inline': False,
            })

            prev_file_attachment, next_file_attachment = \
                self._get_adjacent_file_attachments(review_request_details)

            context.update({
                'next_file_attachment': next_file_attachment,
                'prev_file_attachment': prev_file_attachment,
            })

        try:
            context.update(self.get_extra_context(request))
        except Exception as e:
            logging.error('Error when calling get_extra_context for '
                          'FileAttachmentReviewUI %r: %s',
                          self, e, exc_info=1)
        try:
            return render_to_string(
                self.template_name,
                RequestContext(request, context))
        except Exception as e:
            logging.error('Error when calling get_js_model_data or '
                          'get_js_view_data for FileAttachmentReviewUI '
                          '%r: %s',
                          self, e, exc_info=1)