python: Reformat with Black, except quotes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:19:30 -08:00
committed by Tim Abbott
parent 5028c081cb
commit 11741543da
817 changed files with 44952 additions and 24860 deletions

View File

@@ -11,8 +11,10 @@ def user_attachments(user_profile: UserProfile) -> List[Dict[str, Any]]:
attachments = Attachment.objects.filter(owner=user_profile).prefetch_related('messages')
return [a.to_dict() for a in attachments]
def access_attachment_by_id(user_profile: UserProfile, attachment_id: int,
needs_owner: bool=False) -> Attachment:
def access_attachment_by_id(
user_profile: UserProfile, attachment_id: int, needs_owner: bool = False
) -> Attachment:
query = Attachment.objects.filter(id=attachment_id)
if needs_owner:
query = query.filter(owner=user_profile)
@@ -22,9 +24,12 @@ def access_attachment_by_id(user_profile: UserProfile, attachment_id: int,
raise JsonableError(_("Invalid attachment"))
return attachment
def remove_attachment(user_profile: UserProfile, attachment: Attachment) -> None:
try:
delete_message_image(attachment.path_id)
except Exception:
raise JsonableError(_("An error occurred while deleting the attachment. Please try again later."))
raise JsonableError(
_("An error occurred while deleting the attachment. Please try again later.")
)
attachment.delete()