Inline File Attachments
Review Request #3457 — Created Oct. 25, 2012 and discarded
Add inline file attachment support. FileAttachment now has a foreign key that associates it with a FileDiff. FileAttachment associated with a FileDiff is filtered from the get_file_attachments call so binary files that are suppose to be displayed inline will not appear in the review request file attachment box as well. DiffViewer template diff_file_fragment.html uses the get_binary_file_attachment_for assignment tag to fetch the inline file attachments by querying for FileAttachments associated with the filediff or interfilediff. Binary files uploaded with a diff will now be displayed inline, with thumbnail, download link and a link to MIME type specific review UI if available. If a review UI is not available for the MIME type of the binary file, a 'Add Comment' option will be available to the users with the same interface and workflow as the existing file attachments commenting system.
* There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in the database by making a filediff for that file and supplying the filediff_id to the fileattachment. Passing Manual tests: > Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff > Made sure the basic file information is displayed inline (file name, file-icon, download link) > Made sure "This is a binary file. The content cannot be displayed." when the query for FileAttachment returns None > Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned > Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available > Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui > Made sure if the fileattachment for the binary file is found, a link to download the file is shown > Made sure if a thumbnail is available for the fileattachment, it is displayed > Made sure that if a FileAttachment is associated with a FileDiff, it will not be included in file-list in the review_request_box template > Made sure if the new binary file attachment can't be retrieve but the older revision of it can then the older revision is displayed on the right regardless > Made sure that the two horizontal table cells in sidebyside view have the same width > Made sure a "Add comment" option exist if review UI does not > Made sure "Add comment" function like existing file attachments container action Passing Unit test(s): > ./reviewboard/manage.py test -- reviewboard.attachments.tests:BinaryFileAttachmentTests !Failing Manual tests: > Made sure there is no stale data: comments/reviews add to the file attachment will be reflected immediately
Description | From | Last Updated |
---|---|---|
What is this? |
david | |
Wrap to < 80 chars. |
chipx86 | |
The 2nd and 3rd lines should be lined up at the same column as the first parameter: ...Key(FileDiff, ... verbose_name=... … |
david | |
So normally, you probably want: try: binary_file_attachment = get_object_or_none(FileAttachment, filediff=filediff) except MultipleObjectsReturned: # log something here binary_file_attachment = None Actually, … |
chipx86 | |
I think it would make more sense to say "associated with a FileDiff" |
david | |
Blank line between these. |
chipx86 | |
Same comment here. |
david | |
Blank line between these. |
chipx86 | |
template tags should start at indentation level 0, and instead the command should be indented inside the {% ... %}. … |
chipx86 | |
Template variables should not have spaces around the variable name. {{file.binary_file_attachment.file}} |
chipx86 | |
I don't think we want this. Let's fall back to what we had before. There's too many legitimate review requests … |
chipx86 | |
This is probably not right. In the case where old diffs have binary file entries, we'd want to fall back … |
david | |
Should be inserted alphabetically in the import list. |
chipx86 | |
This should be in the next import group, since it's part of the project, and not in the 3rd party … |
chipx86 | |
Two blank lines. |
chipx86 | |
The "Error:" isn't needed. We're in an exception, so that's a pretty good assumption. |
chipx86 | |
This needs to convey some useful information we can use to track what went wrong. If we see this in … |
chipx86 | |
Blank line. |
chipx86 | |
Space before { |
chipx86 | |
Not totally thrilled with redefining all the action logic. We should standardize it (pull the common parts out of the … |
chipx86 | |
No spaces inside {{}} (Yes, the old code had them, but it's really old code and should be changed.) |
chipx86 | |
We use 1 space indentation in HTML. Make sure all the new HTML is only indented 1. |
chipx86 | |
This can probably just be merged into the parent . |
chipx86 | |
I would expect this (and the equivalent on the right-hand side) to be on its own . Also, can you … |
chipx86 | |
I'm concerned about accessing thumbnail twice. This will currently cause a lot of logic to happen twice. Perhaps the thumbnail … |
chipx86 | |
Should this be interfile_binary_file_attachment.thumbnail? |
chipx86 | |
The {% trans %} lines should go on their own lines for readability. |
chipx86 | |
Here too. |
chipx86 | |
Yeah I don't think this approach is correct. The prior code is more what I'd expect, but if it's causing … |
chipx86 | |
Since you're just returning this immediately, you can do: try: return get_object_or_none(...) except MultipleObjectsReturned: logging.error(...) return None |
david | |
I think it might be better to write this as "if not file[filedifftype]" That would check for cases where file[filedifftype] … |
AA aam1r | |
Same as above (i.e. might be better doing "if not" rather than "is None") |
AA aam1r | |
Same as above (i.e. might be better doing "if not" rather than "is None") |
AA aam1r | |
Extra docs are always nice, but for unit tests, it really should be a one-liner. You can have the rest … |
chipx86 | |
Needs to be a sentence (needs a period at the end) |
SL slchen | |
I think you should wrap these in try/except statements to catch any exceptions that might be raised |
AA aam1r | |
We're using "fileattachment, "diff_fileattachment," "file_attachments," and "diff_file_attachment." It's a bit inconsistent. I'd prefer if we kept an underscore between "file" … |
chipx86 | |
Should be alphabetical. |
chipx86 | |
Should use underscores to separate words in variables when appropriate. This should be "file_diff_type". |
chipx86 | |
This is a little awkwardly written. Can you change it to: "file_diff_type can be either 'filediff' or 'interfilediff'." |
chipx86 | |
Did you mean this, or: &.left, &.binary-left Also, space before "{". |
chipx86 | |
Same comments here. |
chipx86 | |
And here. |
chipx86 | |
And here. |
chipx86 | |
Mixins are neat and all, but my preference is to avoid them in cases like this. The code should be: … |
chipx86 | |
Similarly, this shouldn't be a mixin, as it brings in a lot of code. Instead, the elements using the various … |
chipx86 | |
Now that this is multi-line, can you put the on its own line? |
chipx86 | |
You'd have to test this, but I don't know that we need this here. Unless we're operating on elements right … |
chipx86 | |
No need for colspan="1" |
chipx86 | |
Same. |
chipx86 | |
And here. |
chipx86 | |
And here. |
chipx86 | |
Indentation: remove 1 leading empty space from line 7 |
SL slchen | |
I think mimeparse is a 3rd party lib, it should go right after: from django.test import TestCase |
SL slchen | |
Nitpick: alphabetical |
SL slchen | |
I think you can change the indentation to: diff_file_attachment = FileAttachment.objects.create( caption='binary', file=file, mimetype='image/png', filediff=filediff) |
SL slchen | |
So, something I realized is that this is going to introduce new performance degradation, since we'll be doing 1 SQL … |
chipx86 |
-
-
-
So normally, you probably want: try: binary_file_attachment = get_object_or_none(FileAttachment, filediff=filediff) except MultipleObjectsReturned: # log something here binary_file_attachment = None Actually, though, this code should not be in this file. The diff viewer should remain ignorant of the other apps (attachments and reviews). It's also going to increase the cache size quite a bit by caching the file attachment along with the metadata. The templates, though, are customizable, and so it can access such things. I'd suggest we do something there. Right now, we're just showing a path, and that can be reached by providing some template tag that does the query, given the filediff's ID, but we should really decide what's being shown later. Whatever that is will end up doing the above query instead, and rendering something (a review UI, probably) using it.
-
-
-
template tags should start at indentation level 0, and instead the command should be indented inside the {% ... %}. Same with the others in this file.
-
Template variables should not have spaces around the variable name. {{file.binary_file_attachment.file}}
-
I don't think we want this. Let's fall back to what we had before. There's too many legitimate review requests that exist, and we don't want to show errors there. We also will probably have to set a size cap for uploading file attachments, and don't want to mislead users.
- Change Summary:
-
+ Modified comments and format based on review - Reverted changes to diffutils for returning binary file attachment along with the file, instead: + Added the query for FileAttachment as a template tag in difftags - Reverted changes to diff_file_fragment that could affect existing review requests Please see updated Descriptions and Testing Done sections for detailed information.
- Description:
-
Completed:
~ Add foreign key association between FileAttachment and FileDiff.
* This links file attachments with particular revisions, thus sets the ground for
inline file attachments. The diffviewer will use this association to look up the
matching FileAttachment upon encountering a binary file that can't be displayed.
* Affected files:
+ /reviewboard/attachments/models.py
+ /reviewboard/attachments/evolutions/init.py
+ /reviewboard/attachments/evolutions/associate_file_attachments_with_filediff.py~ Add foreign key association between FileAttachment and FileDiff.
+ + This links file attachments with particular revisions, thus sets the ground for
+ inline file attachments. The diffviewer will use this association to look up the
+ matching FileAttachment upon encountering a binary file that can't be displayed.
+ * Affected files:
+ + /reviewboard/attachments/models.py
+ + /reviewboard/attachments/evolutions/__init__.py
+ + /reviewboard/attachments/evolutions/associate_file_attachments_with_filediff.py
+ + + + + + + Modify get_file_attachments to exclude file attachments associated with a FileDiff.
+ + BaseReviewRequestDetails.get_file_attachments() now return solely the
+ file attachments associated with only the review request and not binary
+ file attachments associated with specific revision (filediff). This is
+ so that inline binary file attachments won't appear in review request
+ file attachment box.
+ * Affected files:
+ + /reviewboard/reviews/models.py
+ ~ Modify BaseReviewRequestDetails.get_file_attachments() to return solely the
file attachments associated with only the review request and not binary
file attachments associated with specific revision (filediff).
* This prevents binary files that should be displayed inline from appearing else where.
* Affected files:
+ /reviewboard/reviews/models.py~ [NEW: reverted] Add binary_file_attachment to the return object of get_diff_files().
+ + This allows binary file attachments to be passed to the templates where
+ they can be displayed inline.
+ * Affected files:
+ + /reviewboard/diffviewer/diffutils.py
+ ~ Add binary_file_attachment to the return object of get_diff_files().
* This allows binary file attachments to be passed to the templates where
they can be displayed inline.
* Affected files:
+ /reviewboard/diffviewer/diffutils.py~ [NEW] Add get_binary_file_attachment_for template tag in difftags.py, and display
basic FileAttachment information inline in the diff_file_fragment template.+ + This template tag will query for the FileAttachment based on the provided file,
+ which contains a filediff, and set the retrieved binary file attachment to a
+ variable whose name is provided as an argument to this tag. If no matching
+ FileAttachment is found or if there is more than one FileAttachment associated
+ with one FileDiff, None is returned, and an error is logged in the latter case.
+ * Affected files:
+ + reviewboard/diffviewer/templatetags/difftags.py
+ + reviewboard/templates/diffviewer/diff_file_fragment.html
+ TODOs:
~ Modify diff_file_fragment.html to display the binary files inline.
Add a clean mechanism for registering a class that would know how to render a file attachment in the diff viewer.
It would be keyed off by a mimetype. This mechanism should also be extensible so that extensions can register themselves to handle particular mimetypes.
Handle cases where there are more than one or no binary file attachments found.
Upload binary files via post-review (huge item, will be broken down later)~ [NEW: DONE] Handle cases where there are more than one or no binary file attachments found.
+ + + + + + [NEW: Made Progress] Modify diff_file_fragment.html to display the binary files inline.
Add unit tests and possibly more manual test cases
Test cases when review_ui is available for a binary file attachment
Add a clean mechanism for registering a class that would know how to render a file attachment in the diff viewer.
It would be keyed off by a mimetype. This mechanism should also be extensible so that extensions can register themselves to handle particular mimetypes.
Upload binary files via post-review (huge item, will be broken down later) - Testing Done:
-
~ Manual testing.
~ Manually modified database records to associate a FileAttachment with a binary FileDiff:
+ + Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned - Diff:
-
Revision 2 (+79 -3)
- Screenshots:
-
WIP r2: no review_ui
-
This is looking pretty good. I'm not sure I understand your change description--can you rewrite it to be a concise summary of what you've done and what you have left to do?
-
- Change Summary:
-
Updated change description + Added a summary + Highlighted what has been done, is in_progress, and is next
- Description:
-
+ Summary:
+ + FileAttachment now has a foreign key that associate it with a FileDiff, which enables the
+ newly added get_binary_file_attachment template tag to query for the FileAttachment + associated with a FileDiff. FileAttachment associated with a FileDiff is filtered from + the get_file_attachments call so binary files that are suppose to be displayed inline will + not appear in the review request file attachment box as well. + + Currently the inline file attachments are displayed with the existing file attachment
+ UI (used in review_request_box.html) so I'm working on a better interface for displaying + the binary files inline. + + The next step after finalizing the UI and adding more tests on the way is to allow
+ reasonably sized binary files to be uploaded via post-review. + + + Completed:
Add foreign key association between FileAttachment and FileDiff.
This links file attachments with particular revisions, thus sets the ground for
inline file attachments. The diffviewer will use this association to look up the
matching FileAttachment upon encountering a binary file that can't be displayed.
* Affected files:
+ /reviewboard/attachments/models.py
+ /reviewboard/attachments/evolutions/__init__.py
+ /reviewboard/attachments/evolutions/associate_file_attachments_with_filediff.py
Modify get_file_attachments to exclude file attachments associated with a FileDiff.
BaseReviewRequestDetails.get_file_attachments() now return solely the
file attachments associated with only the review request and not binary
file attachments associated with specific revision (filediff). This is
so that inline binary file attachments won't appear in review request
file attachment box.
* Affected files:
+ /reviewboard/reviews/models.py
~ [NEW: reverted] Add binary_file_attachment to the return object of get_diff_files().
~ Add get_binary_file_attachment_for template tag in difftags.py, and display
basic FileAttachment information inline in the diff_file_fragment template.- - This allows binary file attachments to be passed to the templates where
- they can be displayed inline.
- * Affected files:
- + /reviewboard/diffviewer/diffutils.py
- - - - - - - [NEW] Add get_binary_file_attachment_for template tag in difftags.py, and display
basic FileAttachment information inline in the diff_file_fragment template.This template tag will query for the FileAttachment based on the provided file,
which contains a filediff, and set the retrieved binary file attachment to a
variable whose name is provided as an argument to this tag. If no matching
FileAttachment is found or if there is more than one FileAttachment associated
with one FileDiff, None is returned, and an error is logged in the latter case.
* Affected files:
+ reviewboard/diffviewer/templatetags/difftags.py
+ reviewboard/templates/diffviewer/diff_file_fragment.html
~ TODOs:
~ Upcoming:
~ [NEW: DONE] Handle cases where there are more than one or no binary file attachments found.
~ [Current] Modify diff_file_fragment.html to display the binary files inline.
+ + Make the template handle the following cases:
+ 1) It's a binary file and we have a review UI, in which case that should render it
+ 2) We have no review UI, but we have a thumbnail renderer, which should render it
+ 3) We have no thumbnail renderer or review UI
+ Make mock ups of how the inline file attachment should be display (ie. Where should
+ the thumbnail/download link/filename be in the tbody? How should it be displayed
+ when it's a new file and when it's comparing between 2 revisions of the binary file?)
+ and get feedback for the layout and usability.
+ * Affected files:
+ + reviewboard/templates/diffviewer/diff_file_fragment.html
+ ~ [NEW: Made Progress] Modify diff_file_fragment.html to display the binary files inline.
Add unit tests and possibly more manual test cases
Test cases when review_ui is available for a binary file attachment
Add a clean mechanism for registering a class that would know how to render a file attachment in the diff viewer.
It would be keyed off by a mimetype. This mechanism should also be extensible so that extensions can register themselves to handle particular mimetypes.
Upload binary files via post-review (huge item, will be broken down later)~ [Next] Add unit tests and possibly more manual test cases
Upload binary files via post-review (will be broken down later, probably git support first) - Branch:
-
masterinline-file-attachments
- Change Summary:
-
Changes: Add inline preview UI for binary files in diffviewer. Add action buttons (links) for downloading/commenting/reviewing the binary file when appropriate. Show thumbnail when available. Show previous version of the binary file side-by-side when interfilediff is available. Add an additional parameter to get_binary_file_attachment_for tag to enabling fetching for fileattachment associated with interfilediff. * Affected files: + reviewboard/diffviewer/templatetags/difftags.py + reviewboard/static/rb/css/diffviewer.less + reviewboard/templates/diffviewer/diff_file_fragment.html Problem: Sidebyside views using <td colspan="2"> are not aligning properly in Chrome (shown in the screenshots attached. There is a second attempting to use lists instead of table commented out in the template. With that approaching, I can make the thumbnails list like the actions links but can't make them span the whole width appropriately. I have tried width=50% for <li> but that's hard coded so won't very well if it's a newfile and importantly still doesn't align like the text diffs. (Please see screenshot) To Test: There's no way to upload a binary file attachment yet so to test this UI one must manually associate an uploaded fileattachment with a filediff in the database by making a filediff for that file and supplying the filediff_id to the fileattachment.
- Description:
-
Summary:
FileAttachment now has a foreign key that associate it with a FileDiff, which enables the
newly added get_binary_file_attachment template tag to query for the FileAttachment associated with a FileDiff. FileAttachment associated with a FileDiff is filtered from the get_file_attachments call so binary files that are suppose to be displayed inline will not appear in the review request file attachment box as well. Currently the inline file attachments are displayed with the existing file attachment
UI (used in review_request_box.html) so I'm working on a better interface for displaying the binary files inline. The next step after finalizing the UI and adding more tests on the way is to allow
reasonably sized binary files to be uploaded via post-review. Completed:
Add foreign key association between FileAttachment and FileDiff.
This links file attachments with particular revisions, thus sets the ground for
inline file attachments. The diffviewer will use this association to look up the
matching FileAttachment upon encountering a binary file that can't be displayed.
* Affected files:
+ /reviewboard/attachments/models.py
+ /reviewboard/attachments/evolutions/__init__.py
+ /reviewboard/attachments/evolutions/associate_file_attachments_with_filediff.py
Modify get_file_attachments to exclude file attachments associated with a FileDiff.
BaseReviewRequestDetails.get_file_attachments() now return solely the
file attachments associated with only the review request and not binary
file attachments associated with specific revision (filediff). This is
so that inline binary file attachments won't appear in review request
file attachment box.
* Affected files:
+ /reviewboard/reviews/models.py
Add get_binary_file_attachment_for template tag in difftags.py, and display
basic FileAttachment information inline in the diff_file_fragment template.This template tag will query for the FileAttachment based on the provided file,
which contains a filediff, and set the retrieved binary file attachment to a
variable whose name is provided as an argument to this tag. If no matching
FileAttachment is found or if there is more than one FileAttachment associated
with one FileDiff, None is returned, and an error is logged in the latter case.
* Affected files:
+ reviewboard/diffviewer/templatetags/difftags.py
+ reviewboard/templates/diffviewer/diff_file_fragment.html
Upcoming:
[Current] Modify diff_file_fragment.html to display the binary files inline.
~ Make the template handle the following cases:
~ 1) It's a binary file and we have a review UI, in which case that should render it
~ 2) We have no review UI, but we have a thumbnail renderer, which should render it
~ 3) We have no thumbnail renderer or review UI
~ Make mock ups of how the inline file attachment should be display (ie. Where should
~ the thumbnail/download link/filename be in the tbody? How should it be displayed
~ when it's a new file and when it's comparing between 2 revisions of the binary file?)
~ Add inline preview UI for binary files in diffviewer.
~ ~ Add action buttons (links) for downloading/commenting/reviewing the binary file when
~ appropriate. Show thumbnail when available. Show previous version of the binary
~ file side-by-side when interfilediff is available. Add an additional parameter to
~ get_binary_file_attachment_for tag to enabling fetching for fileattachment associated
~ with interfilediff.
- and get feedback for the layout and usability.
* Affected files:
+ + reviewboard/diffviewer/templatetags/difftags.py
+ + reviewboard/static/rb/css/diffviewer.less
+ reviewboard/templates/diffviewer/diff_file_fragment.html
[Next] Add unit tests and possibly more manual test cases
Upload binary files via post-review (will be broken down later, probably git support first) - Testing Done:
-
~ Manually modified database records to associate a FileAttachment with a binary FileDiff:
~ Manually modified database records to associate a FileAttachment with a binary FileDiff*:
~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed+ + - There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
the database by making a filediff for that file and supplying the filediff_id to the fileattachment.
- There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
- Branch:
-
inline-file-attachmentsmaster
- Diff:
-
Revision 3 (+252 -5)
- Screenshots:
-
not aligned properly in chromealigns properly in firefoxli width=50% not aligned properly
- Change Summary:
-
Added unit test for inline file attachment.
- Description:
-
Summary:
FileAttachment now has a foreign key that associate it with a FileDiff, which enables the
newly added get_binary_file_attachment template tag to query for the FileAttachment associated with a FileDiff. FileAttachment associated with a FileDiff is filtered from the get_file_attachments call so binary files that are suppose to be displayed inline will not appear in the review request file attachment box as well. Currently the inline file attachments are displayed with the existing file attachment
UI (used in review_request_box.html) so I'm working on a better interface for displaying the binary files inline. The next step after finalizing the UI and adding more tests on the way is to allow
reasonably sized binary files to be uploaded via post-review. Completed:
Add foreign key association between FileAttachment and FileDiff.
This links file attachments with particular revisions, thus sets the ground for
inline file attachments. The diffviewer will use this association to look up the
matching FileAttachment upon encountering a binary file that can't be displayed.
* Affected files:
+ /reviewboard/attachments/models.py
+ /reviewboard/attachments/evolutions/__init__.py
+ /reviewboard/attachments/evolutions/associate_file_attachments_with_filediff.py
Modify get_file_attachments to exclude file attachments associated with a FileDiff.
BaseReviewRequestDetails.get_file_attachments() now return solely the
file attachments associated with only the review request and not binary
file attachments associated with specific revision (filediff). This is
so that inline binary file attachments won't appear in review request
file attachment box.
* Affected files:
+ /reviewboard/reviews/models.py
Add get_binary_file_attachment_for template tag in difftags.py, and display
basic FileAttachment information inline in the diff_file_fragment template.This template tag will query for the FileAttachment based on the provided file,
which contains a filediff, and set the retrieved binary file attachment to a
variable whose name is provided as an argument to this tag. If no matching
FileAttachment is found or if there is more than one FileAttachment associated
with one FileDiff, None is returned, and an error is logged in the latter case.
* Affected files:
+ reviewboard/diffviewer/templatetags/difftags.py
+ reviewboard/templates/diffviewer/diff_file_fragment.html
+ + + Add a unit test case for inline binary file attachment
+ + Testing fileattachment and filediff association by:
+ 1.Testing the ability of Reviews.BaseReviewRequestDetails.get_file_attachments()
+ to filter out binary file attachments, associated with a filediff, from standard
+ file attachments, which are solely associated with a review request.
+ 2.Testing the ability get_binary_file_attachment_for assignment tag to fetch
+ binary_file_attachment from a file.
+ * Affected files:
+ + reviewboard/attachments/tests.py
+ + + + Upcoming:
~ [Current] Modify diff_file_fragment.html to display the binary files inline.
~ [Current:Blocked] Modify diff_file_fragment.html to display the binary files inline.
Add inline preview UI for binary files in diffviewer.
Add action buttons (links) for downloading/commenting/reviewing the binary file when
appropriate. Show thumbnail when available. Show previous version of the binary
file side-by-side when interfilediff is available. Add an additional parameter to
get_binary_file_attachment_for tag to enabling fetching for fileattachment associated
with interfilediff.
* Affected files:
+ reviewboard/diffviewer/templatetags/difftags.py
+ reviewboard/static/rb/css/diffviewer.less
+ reviewboard/templates/diffviewer/diff_file_fragment.html
~ [Next] Add unit tests and possibly more manual test cases
Upload binary files via post-review (will be broken down later, probably git support first)~ [Next] Upload binary files via post-review (will be broken down later, probably git support first)
- Testing Done:
-
Manually modified database records to associate a FileAttachment with a binary FileDiff*:
~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed
Made sure that if a FileAttachment is associated with a FileDiff, it will not be included in file-list in the review_request_box template- There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
the database by making a filediff for that file and supplying the filediff_id to the fileattachment.
+ + Unit tests:
+ + [Passing] ./reviewboard/manage.py test -- reviewboard.attachments.tests:BinaryFileAttachmentTests
- There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
- Diff:
-
Revision 4 (+329 -6)
-
So nothing stands out as being super wrong with the HTML (though I have changes I'd like to see made). Still, it's looking very wrong on Chrome. I wasn't sure which screenshot corresponded with which code. I'm guessing the "li width=50% not aligned" was the commented out code, which isn't what we want. The first block is more correct. Can you make the changes here, make sure the screenshots represent that new state of the world, and then if there are still problems, we'll go over them in person?
-
-
This should be in the next import group, since it's part of the project, and not in the 3rd party group.
-
-
-
This needs to convey some useful information we can use to track what went wrong. If we see this in logs, we won't have anything to go on.
-
-
-
Not totally thrilled with redefining all the action logic. We should standardize it (pull the common parts out of the review request and make them generally available), and then if we want it to be a different color or something, that's easy to override here.
-
-
-
-
I would expect this (and the equivalent on the right-hand side) to be on its own <tr>. Also, can you perhaps rewrite this to use elif? Like: {% if not interfile_binary_file_attachment %} "This is a binary file ..." {% elif interfile_binary_file_attachment.thumbnail %} {{...thumbnail}} {% else %} "No preview..." {% endif %}
-
I'm concerned about accessing thumbnail twice. This will currently cause a lot of logic to happen twice. Perhaps the thumbnail function should be modified to cache the last value.
-
-
-
-
Yeah I don't think this approach is correct. The prior code is more what I'd expect, but if it's causing issues on Chrome, we'll need to investigate further.
- Change Summary:
-
+ Improved code according to Christian's comments + Added more details error and debug messages for get_binary_file_attachment_for tag. + Extracted .actions and .actions-container to defs.less. And extended them in diffviewer.less to overwrite them with inline-file-attachment-action specific settings. + Aligned the file attachment icon in the header in diff_file_fragment.html; Put actions and thumbnail previews on two different rows; and updated control logic in it. + Cleaned up description. ! Please review the logic below (are these the behavior we want?): ~ an icon will be displayed for binary file in the header ~ if a binary file cannot be retrieved via a filediff then there won't be a 'Download' or 'Review' action, but there will be a 'Add Comment' action for it ~ if there is no review_ui for the binary file type there won't be a 'Review' action for it, just 'Download' and 'Add Comment' ~ if there is a review_ui for a file attachment retrieved via filediff there will be both 'Download' and 'Review' actions for it ~ if a older version of the binary file cannot be retrieved via a 'interfilediff' then there won't be a 'Download' action for it, vice versa TODOs: > make the actions-container exist even when the list of action is empty, to make it look consistent > center the text messages (please see fileattachment=none screenshot) > chrome column misaligned problem has been identified and currently being worked on
- Description:
-
~ Summary:
~ Add inline file attachment support.
~ FileAttachment now has a foreign key that associate it with a FileDiff, which enables the
~ newly added get_binary_file_attachment template tag to query for the FileAttachment ~ associated with a FileDiff. FileAttachment associated with a FileDiff is filtered from ~ the get_file_attachments call so binary files that are suppose to be displayed inline will ~ not appear in the review request file attachment box as well. ~ ~ Currently the inline file attachments are displayed with the existing file attachment
~ FileAttachment now has a foreign key that associates it with a FileDiff. FileAttachment associated
~ with a FileDiff is filtered from the get_file_attachments call so binary files that are suppose to ~ be displayed inline will not appear in the review request file attachment box as well. DiffViewer ~ template diff_file_fragment.html uses the get_binary_file_attachment_for assignment tag to fetch ~ the inline file attachments by querying for FileAttachments associated with the filediff or ~ interfilediff. Binary files uploaded with a diff will now be displayed inline, with thumbnail and ~ link to review UI if available. - UI (used in review_request_box.html) so I'm working on a better interface for displaying - the binary files inline. - - The next step after finalizing the UI and adding more tests on the way is to allow
- reasonably sized binary files to be uploaded via post-review. - - - - Completed:
- - - - - - Add foreign key association between FileAttachment and FileDiff.
- - This links file attachments with particular revisions, thus sets the ground for
- inline file attachments. The diffviewer will use this association to look up the
- matching FileAttachment upon encountering a binary file that can't be displayed.
- * Affected files:
- + /reviewboard/attachments/models.py
- + /reviewboard/attachments/evolutions/__init__.py
- + /reviewboard/attachments/evolutions/associate_file_attachments_with_filediff.py
- - - - - - - Modify get_file_attachments to exclude file attachments associated with a FileDiff.
- - BaseReviewRequestDetails.get_file_attachments() now return solely the
- file attachments associated with only the review request and not binary
- file attachments associated with specific revision (filediff). This is
- so that inline binary file attachments won't appear in review request
- file attachment box.
- * Affected files:
- + /reviewboard/reviews/models.py
- - - - - - - Add get_binary_file_attachment_for template tag in difftags.py, and display
basic FileAttachment information inline in the diff_file_fragment template.- - This template tag will query for the FileAttachment based on the provided file,
- which contains a filediff, and set the retrieved binary file attachment to a
- variable whose name is provided as an argument to this tag. If no matching
- FileAttachment is found or if there is more than one FileAttachment associated
- with one FileDiff, None is returned, and an error is logged in the latter case.
- * Affected files:
- + reviewboard/diffviewer/templatetags/difftags.py
- + reviewboard/templates/diffviewer/diff_file_fragment.html
- - - - - - - Add a unit test case for inline binary file attachment
- - Testing fileattachment and filediff association by:
- 1.Testing the ability of Reviews.BaseReviewRequestDetails.get_file_attachments()
- to filter out binary file attachments, associated with a filediff, from standard
- file attachments, which are solely associated with a review request.
- 2.Testing the ability get_binary_file_attachment_for assignment tag to fetch
- binary_file_attachment from a file.
- * Affected files:
- + reviewboard/attachments/tests.py
- - - - - Upcoming:
- - - - - - [Current:Blocked] Modify diff_file_fragment.html to display the binary files inline.
- - Add inline preview UI for binary files in diffviewer.
- - Add action buttons (links) for downloading/commenting/reviewing the binary file when
- appropriate. Show thumbnail when available. Show previous version of the binary
- file side-by-side when interfilediff is available. Add an additional parameter to
- get_binary_file_attachment_for tag to enabling fetching for fileattachment associated
- with interfilediff.
- * Affected files:
- + reviewboard/diffviewer/templatetags/difftags.py
- + reviewboard/static/rb/css/diffviewer.less
- + reviewboard/templates/diffviewer/diff_file_fragment.html
- - - - - - - [Next] Upload binary files via post-review (will be broken down later, probably git support first)
- Testing Done:
-
Manually modified database records to associate a FileAttachment with a binary FileDiff*:
~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed
Made sure that if a FileAttachment is associated with a FileDiff, it will not be included in file-list in the review_request_box template~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed
Made sure that if a FileAttachment is associated with a FileDiff, it will not be included in file-list in the review_request_box template
Make sure if the new binary file attachment can't be retrieve but the older revision of it can then the older revision is displayed on the right regardless- There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
the database by making a filediff for that file and supplying the filediff_id to the fileattachment.
Unit tests:
[Passing] ./reviewboard/manage.py test -- reviewboard.attachments.tests:BinaryFileAttachmentTests
- There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
- Diff:
-
Revision 5 (+389 -112)
- Screenshots:
-
fileattachment=none
-
It would be nice if you could remove old screenshots and just attach the ones corresponding to the current state of the feature. I don't see much to change here but Christian should probably take another look at the HTML.
-
Since you're just returning this immediately, you can do: try: return get_object_or_none(...) except MultipleObjectsReturned: logging.error(...) return None
- Change Summary:
-
- remove screenshots that are no longer applicable
- Screenshots:
-
not aligned properly in chromeWIP: passed associated binary file to templateli width=50% not aligned properlyWIP r2: no review_uialigns properly in firefox
- Change Summary:
-
+ Make inline file attachment UI's sidebyside cell aligned in Chrome by using two colgroups for inline file attachment UI instead of the 4 colgroups used by text diffs. + Fix css to avoid disappearing right border issue in Chrome. + Refactor get_binary_file_attachment_for tag according to David's suggestion. + Screenshots of how the UI looks like now in different scenarios ! Please review the logic below (are these the behavior we want?): ~ an icon will be displayed for binary file in the header ~ if a binary file cannot be retrieved via a filediff then there won't be a 'Download' or 'Review' action, but there will be a 'Add Comment' action for it (Should there be a Add Comment feature? If so, should it be similar to the ones implemented for file attachment already?) ~ if there is no review_ui for the binary file type there won't be a 'Review' action for it, just 'Download' and 'Add Comment' ~ if there is a review_ui for a file attachment retrieved via filediff there will be both 'Download' and 'Review' actions for it ~ if a older version of the binary file cannot be retrieved via a 'interfilediff' then there won't be a 'Download' action for it, vice versa
- Testing Done:
-
Manually modified database records to associate a FileAttachment with a binary FileDiff*:
~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed
Made sure that if a FileAttachment is associated with a FileDiff, it will not be included in file-list in the review_request_box template
Make sure if the new binary file attachment can't be retrieve but the older revision of it can then the older revision is displayed on the right regardless~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed
Made sure that if a FileAttachment is associated with a FileDiff, it will not be included in file-list in the review_request_box template
Make sure if the new binary file attachment can't be retrieve but the older revision of it can then the older revision is displayed on the right regardless
Make sure that the two horizontal table cells in sidebyside view have the same width.- There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
the database by making a filediff for that file and supplying the filediff_id to the fileattachment.
Unit tests:
[Passing] ./reviewboard/manage.py test -- reviewboard.attachments.tests:BinaryFileAttachmentTests
- There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
- Diff:
-
Revision 6 (+400 -113)
- Added Files:
- Change Summary:
-
Add commenting functions to inline file attachments with no review UI and address comments. + Hook up the necessary javascript to allow commenting on inline file attachments that does not have a review UI. + Cache thumbnail in mimetype_handler. + Refactor one checks to be using 'if not'. + s/binary_file_attachment/diff_file_attachment. + Fix css mixin definitions to work with the new version of less. Add two more previews 1. newfilediff-nofileattachment.png when there's no file attachment associated with the binary file diff 2. comments.png add comments when there's no Review UI for the mimetype
- Summary:
-
WIP: Inline File AttachmentsInline File Attachments
- Diff:
-
Revision 7 (+413 -120)
- Removed Files:
- Added Files:
- Screenshots:
-
fileattachment=none
-
This looks good to me. Because of the scope of the change, I'd like to have Christian take one last look at it before we push it. Nice work!
-
There's a series of mostly small things left, but the overall work looks good. Looking forward to this! Poke me as soon as you have a change up and I'll do another review.
-
Extra docs are always nice, but for unit tests, it really should be a one-liner. You can have the rest in comments.
-
We're using "fileattachment, "diff_fileattachment," "file_attachments," and "diff_file_attachment." It's a bit inconsistent. I'd prefer if we kept an underscore between "file" and "attachment" in all instances.
-
-
Should use underscores to separate words in variables when appropriate. This should be "file_diff_type".
-
This is a little awkwardly written. Can you change it to: "file_diff_type can be either 'filediff' or 'interfilediff'."
-
-
-
-
-
Mixins are neat and all, but my preference is to avoid them in cases like this. The code should be: .inline-actions-left, .inline-actions-right { // All the common stuff here. } And then have the .inline-actions-left and .inline-actions-right rules define their own specific stuff (like their own floats and 'a' rules). The reason is that, while it's neat to be able to include data like this in lesscss, in the end it's really just turning into even more CSS code the browser has to load in and keep separate, and it's more work to debug. It's equivalent to copy/paste.
-
Similarly, this shouldn't be a mixin, as it brings in a lot of code. Instead, the elements using the various "inline-actions-*" classes should be also specifying "actions" as a class. More reuse, less debugging and less output.
-
-
You'd have to test this, but I don't know that we need this here. Unless we're operating on elements right away, we don't have to worry about the DOM being ready.
-
Just to make sure, is this what you're expecting the logic to be: if (file.moved and file.num_changes == 0) or (file.newfile and not interfile_diff_file_attachment) ? Just want to be sure about the operator precedence.
-
-
-
-
- Change Summary:
-
+ Improve naming conventions: s/fileattachment/file_attachment; s/filedifftype/filediff_type + Improve comment readability - Remove mixins and update css rules to promote css rules reuse - Remove unnecessary colspan="1" declarations + Fix Bug by calling RB.setFileAttachmentComments after the diff_file_attachment null check + Preview image (newfilecorrupted.png) for scenarios where the new (revision) file can not be retrieved (eg. new file is corrupted or not uploaded correctly)
- Description:
-
Add inline file attachment support.
FileAttachment now has a foreign key that associates it with a FileDiff. FileAttachment associated
with a FileDiff is filtered from the get_file_attachments call so binary files that are suppose to be displayed inline will not appear in the review request file attachment box as well. DiffViewer template diff_file_fragment.html uses the get_binary_file_attachment_for assignment tag to fetch the inline file attachments by querying for FileAttachments associated with the filediff or ~ interfilediff. Binary files uploaded with a diff will now be displayed inline, with thumbnail and ~ link to review UI if available. ~ interfilediff. Binary files uploaded with a diff will now be displayed inline, with thumbnail, ~ download link and a link to MIME type specific review UI if available. If a review UI is not + available for the MIME type of the binary file, a 'Add Comment' option will be available to the + users with the same interface and workflow as the existing file attachments commenting system. - Testing Done:
-
~ Manually modified database records to associate a FileAttachment with a binary FileDiff*:
~ - There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
the database by making a filediff for that file and supplying the filediff_id to the fileattachment.
~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, url etc.)
Made sure "This is a binary file. The content cannot be displayed." when an associated FileAttachment is not found, to guarantee backward compatibility
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed
Made sure that if a FileAttachment is associated with a FileDiff, it will not be included in file-list in the review_request_box template
Make sure if the new binary file attachment can't be retrieve but the older revision of it can then the older revision is displayed on the right regardless
Make sure that the two horizontal table cells in sidebyside view have the same width.~ Passing Manual tests:
~ - There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
the database by making a filediff for that file and supplying the filediff_id to the fileattachment.
~ Made sure filediff_id column is added to FileAttachment, and can be used to query for a FileAttachment when given a filediff
Made sure the basic file information is displayed inline (file name, file-icon, download link)
Made sure "This is a binary file. The content cannot be displayed." when the query for FileAttachment returns None
Made sure when more than one FileAttachment are associated with one FileDiff, an error is logged and None is returned
Made sure get_binary_file_attachment will query and return the correct filediff or interfilediff when available
Made sure when a review_ui exist for the file type of the binary file a link is available to the review_ui
Made sure if the fileattachment for the binary file is found, a link to download the file is shown
Made sure if a thumbnail is available for the fileattachment, it is displayed
Made sure that if a FileAttachment is associated with a FileDiff, it will not be included in file-list in the review_request_box template
Made sure if the new binary file attachment can't be retrieve but the older revision of it can then the older revision is displayed on the right regardless
Made sure that the two horizontal table cells in sidebyside view have the same width
Made sure a "Add comment" option exist if review UI does not
Made sure "Add comment" function like existing file attachments container action+ + Passing Unit test(s):
+ + ./reviewboard/manage.py test -- reviewboard.attachments.tests:BinaryFileAttachmentTests
+ + ~ Unit tests:
~ !Failing Manual tests:
~ [Passing] ./reviewboard/manage.py test -- reviewboard.attachments.tests:BinaryFileAttachmentTests
~ Made sure there is no stale data: comments/reviews add to the file attachment will be reflected immediately
- There's no way to upload a binary file attachment yet so to test this UI, I have manually associate an uploaded fileattachment with a filediff in
- Diff:
-
Revision 8 (+410 -120)
- Added Files:
-
Looks quite good, but there's one thing I realized. Going into detail below.
-
So, something I realized is that this is going to introduce new performance degradation, since we'll be doing 1 SQL query per binary file, which can add up. This is something I've been working to reduce, and the good news is, we should be able to do it without a ton of trouble. The method we're using these days is to do computations of all the objects we need in review_detail or, in this case, diff, in reviews/views.py. We'd get the list of filediffs, the list of attachments, and precompute their associations in one go. The template can then access the proper attachment without even needing a template tag, simplifying the whole thing. The plan of attack would be: 1) Change your code for get_file_attachments to take a flag indicating whether binary file attachments should be included (include_diff_attachments bool). Default it to False. 2) Change the get_file_attachments call in the diff function to pass True to include_diff_attachments. 3) Iterate through the results and split the values into two: The file_attachments we currently pass, and a map of filediff IDs -> attachments. This would look like: file_attachments = [] diff_file_attachments = {} for file_attachment in review_request.get_file_attachments(True): filediff_id = getattr(file_attachment, 'filediff_id', getattr(file_attachment, 'interfilediff_id', None)) if filediff_id: diff_file_attachments[filediff_id] = file_attachment else: file_attachments.append(file_attachment) for file_attachment in review_request.get_inactive_file_attachments(True): # Same as above, except only for the diff_file_attachments map. (Something like that.) 4) Pass 'diff_file_attachments' to the context in render_to_response. 5) In the template, instead of the template tag, do: {{diff_file_attachments|getitem:filediff.pk}} Same with interfilediff.pk This should produce the same effect, but with fewer queries (just one new one for the inactive file attachments, in fact!), and no need for a new template tag. This may seem complicated, so please come to me with any questions.
- Change Summary:
-
+ Improve diff_file_fragment.html and diff_file_attachment test Renamed variables in template so make it more clear: s/diff_file_attachment/dest_diff_file_attachment s/inter_file_attachment/source_diff_file_attachment Fixed url bug caused by an empty context['review_request'] reference. Fix style problems in test and evolution. + New preview screenshot for when displaying multiple binary files across different revisions TODOs: * address stale data issue * after stale data issue rerun test and condense essential test cases into easily commitable form
- Diff:
-
Revision 9 (+409 -119)
- Added Files: