示例#1
0
    def get_comment_thumbnail(self, comment):
        try:
            x = int(comment.extra_data['x'])
            y = int(comment.extra_data['y'])
            width = int(comment.extra_data['width'])
            height = int(comment.extra_data['height'])
        except (KeyError, ValueError):
            # This may be a comment from before we had review UIs. Or,
            # corrupted data. Either way, don't display anything.
            return None

        image_url = crop_image(comment.file_attachment.file, x, y, width,
                               height)
        image_html = (
            '<img class="modified-image" src="%s" width="%s" height="%s" '
            'alt="%s" />' % (image_url, width, height, escape(comment.text)))

        if comment.diff_against_file_attachment_id:
            diff_against_image_url = crop_image(
                comment.diff_against_file_attachment.file, x, y, width, height)

            diff_against_image_html = (
                '<img class="orig-image" src="%s" width="%s" '
                'height="%s" alt="%s" />' %
                (diff_against_image_url, width, height, escape(comment.text)))

            return ('<div class="image-review-ui-diff-thumbnail">%s%s</div>' %
                    (diff_against_image_html, image_html))
        else:
            return image_html
示例#2
0
    def test_get_comment_thumbnail_diff(self):
        """Testing ImageReviewUI.get_comment_thumbnail for an image diff
        comment
        """
        diff_attachment = self.create_file_attachment(self.review_request)

        ui = ImageReviewUI(self.review_request, self.attachment)
        ui.set_diff_against(diff_attachment)

        comment = self.create_file_attachment_comment(
            self.review,
            self.attachment,
            diff_attachment,
            extra_fields={
                'x': 0,
                'y': 0,
                'width': 1,
                'height': 1,
            })
        thumbnail = ui.get_comment_thumbnail(comment)

        self.assertEqual(
            thumbnail,
            '<div class="image-review-ui-diff-thumbnail">'
            '<img class="orig-image" src="%s" width="1" height="1" alt="%s" />'
            '<img class="modified-image" src="%s" width="1" height="1"'
            ' alt="%s" />'
            '</div>'
            % (build_server_url(crop_image(diff_attachment.file, 0, 0, 1, 1)),
               comment.text,
               build_server_url(crop_image(self.attachment.file, 0, 0, 1, 1)),
               comment.text)
        )
    def test_get_comment_thumbnail_diff(self):
        """Testing ImageReviewUI.get_comment_thumbnail for an image diff
        comment
        """
        diff_attachment = self.create_file_attachment(self.review_request)

        ui = ImageReviewUI(self.review_request, self.attachment)
        ui.set_diff_against(diff_attachment)

        comment = self.create_file_attachment_comment(self.review,
                                                      self.attachment,
                                                      diff_attachment,
                                                      extra_fields={
                                                          'x': 0,
                                                          'y': 0,
                                                          'width': 1,
                                                          'height': 1,
                                                      })
        thumbnail = ui.get_comment_thumbnail(comment)

        self.assertHTMLEqual(
            thumbnail, '<div class="image-review-ui-diff-thumbnail">'
            '<img class="orig-image" src="%s" width="1" height="1" alt="%s" />'
            '<img class="modified-image" src="%s" width="1" height="1"'
            ' alt="%s" />'
            '</div>' %
            (build_server_url(crop_image(diff_attachment.file, 0, 0, 1,
                                         1)), comment.text,
             build_server_url(crop_image(self.attachment.file, 0, 0, 1,
                                         1)), comment.text))
示例#4
0
    def get_comment_thumbnail(self, comment):
        try:
            x = int(comment.extra_data['x'])
            y = int(comment.extra_data['y'])
            width = int(comment.extra_data['width'])
            height = int(comment.extra_data['height'])
        except (KeyError, ValueError):
            # This may be a comment from before we had review UIs. Or,
            # corrupted data. Either way, don't display anything.
            return None

        image_url = crop_image(comment.file_attachment.file,
                               x, y, width, height)
        image_html = (
            '<img class="modified-image" src="%s" width="%s" height="%s" '
            'alt="%s" />'
            % (image_url, width, height, escape(comment.text)))

        if comment.diff_against_file_attachment_id:
            diff_against_image_url = crop_image(
                comment.diff_against_file_attachment.file,
                x, y, width, height)

            diff_against_image_html = (
                '<img class="orig-image" src="%s" width="%s" '
                'height="%s" alt="%s" />'
                % (diff_against_image_url, width, height,
                   escape(comment.text)))

            return ('<div class="image-review-ui-diff-thumbnail">%s%s</div>'
                    % (diff_against_image_html, image_html))
        else:
            return image_html
示例#5
0
 def image(self):
     """
     Generates the cropped part of the screenshot referenced by this
     comment and returns the HTML markup embedding it.
     """
     url = crop_image(self.screenshot.image, self.x, self.y, self.w, self.h)
     return '<img src="%s" width="%s" height="%s" alt="%s" />' % \
         (url, self.w, self.h, escape(self.text))
示例#6
0
    def get_comment_thumbnail(self, comment):
        try:
            x = int(comment.extra_data["x"])
            y = int(comment.extra_data["y"])
            width = int(comment.extra_data["width"])
            height = int(comment.extra_data["height"])
        except (KeyError, ValueError):
            # This may be a comment from before we had review UIs. Or,
            # corrupted data. Either way, don't display anything.
            return None

        image_url = crop_image(comment.file_attachment.file, x, y, width, height)

        return u'<img src="%s" width="%s" height="%s" alt="%s" />' % (image_url, width, height, escape(comment.text))
示例#7
0
    def get_comment_thumbnail(self, comment):
        try:
            x = int(comment.extra_data['x'])
            y = int(comment.extra_data['y'])
            width = int(comment.extra_data['width'])
            height = int(comment.extra_data['height'])
        except (KeyError, ValueError):
            # This may be a comment from before we had review UIs. Or,
            # corrupted data. Either way, don't display anything.
            return None

        image_url = crop_image(comment.file_attachment.file, x, y, width,
                               height)

        return u'<img src="%s" width="%s" height="%s" alt="%s" />' % \
               (image_url, width, height, escape(comment.text))
    def test_get_comment_thumbnail(self):
        """Testing ImageReviewUI.get_comment_thumbnail for an image comment"""
        ui = ImageReviewUI(self.review_request, self.attachment)
        comment = self.create_file_attachment_comment(self.review,
                                                      self.attachment,
                                                      extra_fields={
                                                          'x': 0,
                                                          'y': 0,
                                                          'width': 1,
                                                          'height': 1,
                                                      })
        thumbnail = ui.get_comment_thumbnail(comment)

        self.assertHTMLEqual(
            thumbnail,
            '<img class="modified-image" src="%s" width="1" height="1"'
            ' alt="%s" />' % (build_server_url(
                crop_image(self.attachment.file, 0, 0, 1, 1)), comment.text))
示例#9
0
    def test_get_comment_thumbnail(self):
        """Testing ImageReviewUI.get_comment_thumbnail for an image comment"""
        ui = ImageReviewUI(self.review_request, self.attachment)
        comment = self.create_file_attachment_comment(
            self.review,
            self.attachment,
            extra_fields={
                'x': 0,
                'y': 0,
                'width': 1,
                'height': 1,
            })
        thumbnail = ui.get_comment_thumbnail(comment)

        self.assertEqual(
            thumbnail,
            '<img class="modified-image" src="%s" width="1" height="1"'
            ' alt="%s" />'
            % (build_server_url(crop_image(self.attachment.file, 0, 0, 1, 1)),
               comment.text)
        )
示例#10
0
 def get_image_url(self):
     """
     Returns the URL for the thumbnail, creating it if necessary.
     """
     return crop_image(self.screenshot.image, self.x, self.y, self.w, self.h)
示例#11
0
 def get_image_url(self):
     """Returns the URL for the thumbnail, creating it if necessary."""
     return crop_image(self.screenshot.image, self.x, self.y,
                       self.w, self.h)