Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to not trigger a download #81

Merged
merged 2 commits into from
Mar 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions demo/demoproject/object/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@
deserialized_basename_view = ObjectDownloadView.as_view(
model=Document,
basename_field='basename')

#: Serve ``file`` attribute of ``Document`` model, inline rather than as attachment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flake8 reports: "line too long (83 > 79 characters)".
See https://travis-ci.org/benoitbryon/django-downloadview/jobs/18602404#L49

What about #: Serve ``file`` attribute of ``Document`` model, inline (not as attachment).
Or span the comment on 2 lines :)

inline_file_view = ObjectDownloadView.as_view(
model=Document,
attachment=False)
12 changes: 12 additions & 0 deletions docs/views/object.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ Then here is the code to serve "another_file" instead of the default "file":
:language: python
:lines: 1-5, 10-12

***********************************************
Serving a file inline rather than as a download
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "attachment" more pertinent than "download" here?

***********************************************

If you would prefer to serve a file as an element of an exsting page
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: s/exsting/existing/

rather than triggering a download, you can use :attr:`ObjectDownloadView.attachment` to specify
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use :attr:~django_downloadview.views.base.DownloadMixin.attachment instead of `:attr:`ObjectDownloadView.attachment: attachment is inherited from DownloadMixin.

that the HTTP Response object should not have the attachment attribute.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps additional explanation about inline/attachment could be useful:

  • "attachment": user is prompted to "save the file as ...".
  • "inline": file contents are displayed inside the browser.

Of course, behaviour may change depending on browsers and their configuration.


.. literalinclude:: /../demo/demoproject/object/views.py
:language: python
:lines: 1-5, 20-23

**********************************
Mapping file attributes to model's
**********************************
Expand Down