File attachment hotlinking view
Review Request #6217 — Created Aug. 12, 2014 and discarded
A view for file hotlinking based on a FileAttachment id. If the FileAttachment in question has a null file field, a 404 is returned.
- Manually requested existent and non-existent file attachments and observed expected behaviour.
Description | From | Last Updated |
---|---|---|
Should be one import line. |
chipx86 | |
'HttpResponse' imported but unused |
reviewbot | |
Two blank lines here. |
chipx86 | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
"file_download" is what I'd prefer. Can you also add a docstring explaining what this does? Make sure it's in the … |
chipx86 | |
That should just go in the function arguments. No need to pull it out of kwargs. In fact, you shouldn't … |
chipx86 | |
The 404 would be publicly-visible, so if we were showing a message, we'd want to localize, make sure it's in … |
chipx86 | |
Use pk= instead of id= when referencing primary keys. |
chipx86 | |
Col: 70 W291 trailing whitespace |
reviewbot | |
Col: 80 E501 line too long (86 > 79 characters) |
reviewbot | |
Should be "files/". Can you also use "file_attachment_id", so it's explicit? |
chipx86 | |
'HttpResponseNotFound' imported but unused |
reviewbot | |
'ObjectDoesNotExist' imported but unused |
reviewbot | |
Col: 50 W291 trailing whitespace |
reviewbot | |
Col: 56 W291 trailing whitespace |
reviewbot | |
Missing a trailing period. |
chipx86 | |
I'd prefer not including the particular URL in here, because if we decide to move it, it's likely that this … |
david | |
Remove this blank line. |
david | |
Should probably use file_attachment.get_absolute_url(). |
chipx86 | |
The second field in the tuple should be aligned with the first: (r'^file...', 'reviewboard.attachments...') |
david |
-
-
-
-
"file_download" is what I'd prefer.
Can you also add a docstring explaining what this does? Make sure it's in the following form:
"""One-line summary. Multi-line description. """
-
That should just go in the function arguments. No need to pull it out of kwargs.
In fact, you shouldn't have a kwargs here.
From the above changes, this would become:
def file_download(request, file_attachment_id):
-
The 404 would be publicly-visible, so if we were showing a message, we'd want to localize, make sure it's in sentence-casing, and be a bit more friendly with the error text.
Having custom text means that the default Review Board error page wouldn't be shown. So all around, we don't want to provide any of this. In fact, we don't want to return
HttpResponseNotFound
. Instead, raisingHttp404
will do the right thing.There's a shortcut for all this. It will query, and if not found, raise
Http404
.We can even simplify this further to ensure that we can only look up file attachments with file content. So, change all this to:
file_attachment = get_object_or_404(FileAttachment, pk=file_attachment_id, file__isnull=FalsE)
-
-
-
Tool: PEP8 Style Checker Processed Files: reviewboard/attachments/views.py reviewboard/urls.py Tool: Pyflakes Processed Files: reviewboard/attachments/views.py reviewboard/urls.py
-
-
-
-
-
Tool: Pyflakes Processed Files: reviewboard/attachments/views.py reviewboard/urls.py Tool: PEP8 Style Checker Processed Files: reviewboard/attachments/views.py reviewboard/urls.py
-
Tool: PEP8 Style Checker Processed Files: reviewboard/attachments/views.py reviewboard/urls.py Tool: Pyflakes Processed Files: reviewboard/attachments/views.py reviewboard/urls.py