fix tar types notification docstring

This commit is contained in:
Hugh Rundle 2023-10-23 20:43:49 +11:00
parent b8fc5c9b7a
commit ddec2dbaa9
No known key found for this signature in database
GPG key ID: A7E35779918253F9
2 changed files with 8 additions and 6 deletions

View file

@ -255,7 +255,7 @@ def notify_user_on_user_import_complete(
def notify_user_on_user_export_complete(
sender, instance, *args, update_fields=None, **kwargs
):
"""we imported your user details! aren't you proud of us"""
"""we exported your user details! aren't you proud of us"""
update_fields = update_fields or []
if not instance.complete or "complete" not in update_fields:
print("RETURNING", instance.status)

View file

@ -1,7 +1,7 @@
"""manage tar files for user exports"""
import io
import tarfile
from typing import Any
from typing import Any, Optional
from uuid import uuid4
from django.core.files import File
@ -16,7 +16,9 @@ class BookwyrmTarFile(tarfile.TarFile):
info.size = len(data)
self.addfile(info, fileobj=buffer)
def add_image(self, image: Any, filename: str = None, directory: Any = "") -> None:
def add_image(
self, image: Any, filename: Optional[str] = None, directory: Any = ""
) -> None:
"""
Add an image to the tar archive
:param str filename: overrides the file name set by image
@ -35,12 +37,12 @@ class BookwyrmTarFile(tarfile.TarFile):
def read(self, filename: str) -> Any:
"""read data from the tar"""
with self.extractfile(filename) as reader:
if reader := self.extractfile(filename):
return reader.read()
def write_image_to_file(self, filename: str, file_field: Any) -> None:
"""add an image to the tar"""
extension = filename.rsplit(".")[-1]
with self.extractfile(filename) as reader:
if buf := self.extractfile(filename):
filename = f"{str(uuid4())}.{extension}"
file_field.save(filename, File(reader))
file_field.save(filename, File(buf))