-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent a 500 error when the image of a news article cannot be opened Fix assertion for pipeline test can_open_file templatetag condition changes
- Loading branch information
1 parent
d4244a2
commit 8f0779f
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django import template | ||
from sentry_sdk.api import capture_exception | ||
|
||
|
||
register = template.Library() | ||
|
||
|
||
@register.filter | ||
def can_open_file(file): | ||
if not file: | ||
return False | ||
try: | ||
with file.open(): | ||
return True | ||
except FileNotFoundError as e: | ||
capture_exception(e) | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters