Skip to content

Commit

Permalink
Use hasattr to check if any of required attribute is present
Browse files Browse the repository at this point in the history
  • Loading branch information
sevdog committed Jul 27, 2023
1 parent 338e171 commit bd90c1f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions django_downloadview/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ def is_download_response(self, response):
whose file attribute have either an URL or a file name.
"""
if super(RealDownloadMiddleware, self).is_download_response(response):
try:
return response.file.url or response.file.name
except AttributeError:
return False
else:
return True
return False
return (
super().is_download_response(response)
and (hasattr(response.file, 'url') or hasattr(response.file, 'name'))
)


class DownloadDispatcher:
Expand Down

0 comments on commit bd90c1f

Please sign in to comment.