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

Signal/event once file has been downloaded? #200

Closed
devidw opened this issue Sep 8, 2022 · 2 comments
Closed

Signal/event once file has been downloaded? #200

devidw opened this issue Sep 8, 2022 · 2 comments

Comments

@devidw
Copy link
Contributor

devidw commented Sep 8, 2022

When applications want to indicate to users whether they have seen/downloaded a document or not, this would probably happen with the help of a boolean has_been_downloaded model field on the corresponding model.

To actually turn this field true once a document has been downloaded, it would be really helpful if the package could send a signal, offer a hook, that gets triggered, when a document was shipped successfully.

I guess this could be implemented with some custom code in a custom view that wraps one of the package views.

DRF example:

    @action(detail=True)
    def download(self, request, pk):
        document = self.get_object()

        # When the owner downloads the document, we want to update the
        # has_been_downloaded field correspondingly
        if document.has_been_downloaded is False:
            document.has_been_downloaded = True
            document.save()

        return ObjectDownloadView.as_view(
            model=Document,
        )(request, pk=pk)

But this would always happen before the actual download code runs and therefore, when the download somehow fails, data would wrongly be changed in the model.

@devidw devidw changed the title Signal event once file has been downloaded? Signal/event once file has been downloaded? Sep 8, 2022
@sevdog
Copy link

sevdog commented Aug 11, 2023

When the whole download process is handled by django you can use the request-finished.

However if the download is handled by the reverse proxy (Apache or Nginx or other) there is no way to handle it in django since the process is not handled by the application server.

@devidw
Copy link
Contributor Author

devidw commented Sep 23, 2023

I see, thanks @sevdog

@devidw devidw closed this as completed Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants