--
Ticket URL: <https://code.djangoproject.com/ticket/16470>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: jreschke (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:1>
* component: Internationalization => HTTP handling
* stage: Unreviewed => Accepted
Comment:
This is a very common problem for developers, and I think it's in the
realm of what Django should do. I guess it means adding a method to
`HttpResponse`.
If the implementation isn't completely obvious, please start a discussion
to django-developers to ensure consensus.
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:2>
Comment (by anonymous):
Mark had discussed this with me over twitter/email a couple days ago.
He's got an example implementation here:
https://github.com/mnot/sweet/blob/master/lib/index.js
I was thinking of trying to keep the existing API of dict key/value as
header/value pair, but having `__setitem__` do some special-casing on
Content-Disposition. This would allow do something sensible for all
existing code, and we could still add an extra method if people wanted
finder control over the fallback filename.
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:3>
Comment (by Clueless):
This seems to be special case of the encoding in
http://tools.ietf.org/html/rfc5987
Seems to me that whatever solution we come up with should generalize to
any header that allows RFC 5987-style encodings.
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:4>
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:5>
Comment (by Claude Paroz):
Now that we have a [https://docs.djangoproject.com/en/2.0/ref/request-
response/#fileresponse-objects FileResponse] subclass, what about adding a
parameter to this subclass which would then set the `Content-Disposition`
header appropriately? Would that satisfy most use cases?
The [https://docs.djangoproject.com/en/2.0/howto/outputting-pdf/ PDF
output example] could be then rewritten as:
{{{
import io
from reportlab.pdfgen import canvas
from django.http import FileResponse
def some_view(request):
# Create a file-like buffer to receive PDF data
buffer = io.BytesIO()
# Create the PDF object, using the buffer as its "file."
p = canvas.Canvas(buffer)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
p.drawString(100, 100, "Hello world.")
# Close the PDF object cleanly, and we're done.
p.showPage()
p.save()
return FileResponse(buffer, as_attachment=True,
filename="somefilename.pdf")
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:6>
* version: 1.3 => master
Comment:
Claudep I think that would make sense.
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:7>
Comment (by Claude Paroz):
[https://github.com/claudep/django/commit/59938909dc8856021e938720724bd17042112cc2
POC commit].
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:8>
* has_patch: 0 => 1
Comment:
Made a [https://github.com/django/django/pull/9839 PR] with my commit.
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:9>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:10>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"a177f854c34718e473bcd0a2dc6c4fd935c8e327" a177f854]:
{{{
#!CommitTicketReference repository=""
revision="a177f854c34718e473bcd0a2dc6c4fd935c8e327"
Fixed #16470 -- Allowed FileResponse to auto-set some Content headers.
Thanks Simon Charette, Jon Dufresne, and Tim Graham for the reviews.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:11>
Comment (by Claude Paroz <claude@…>):
In [changeset:"ee52044a278885bd9455dd59b1e16c5d5e2d68ce" ee52044a]:
{{{
#!CommitTicketReference repository=""
revision="ee52044a278885bd9455dd59b1e16c5d5e2d68ce"
Refs #16470 -- Fixed typo in a FileResponse test.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:12>
Comment (by Claude Paroz <claude@…>):
In [changeset:"231c595bde342e507091167387fba7ba1882b9c9" 231c595]:
{{{
#!CommitTicketReference repository=""
revision="231c595bde342e507091167387fba7ba1882b9c9"
[2.1.x] Refs #16470 -- Fixed typo in a FileResponse test.
Backport of ee52044a278885bd9455dd59b1e16c5d5e2d68ce from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16470#comment:13>