Merge pull request #3057 from hughrun/user-migrate

once more into the linting breach!
This commit is contained in:
Hugh Rundle 2023-10-22 17:50:58 +11:00 committed by GitHub
commit d05cf8e59b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View file

@ -94,7 +94,8 @@ def json_export(user): # pylint: disable=too-many-locals, too-many-statements
# reading goals
reading_goals = models.AnnualGoal.objects.filter(user=user).distinct()
goals_list = []
# TODO: either error checking should be more sophisticated or maybe we don't need this try/except
# TODO: either error checking should be more sophisticated
# or maybe we don't need this try/except
try:
for goal in reading_goals:
goals_list.append(

View file

@ -10,6 +10,7 @@ def read_tar():
yield tar
@pytest.fixture
def write_tar():
archive_path = "/tmp/test.tar.gz"
with open(archive_path, "wb") as archive_file:

View file

@ -8,14 +8,14 @@ from django.core.files import File
class BookwyrmTarFile(tarfile.TarFile):
"""Create tar files for user exports"""
def write_bytes(self, data: bytes):
def write_bytes(self, data: bytes) -> None:
"""Add a file containing bytes to the archive"""
buffer = io.BytesIO(data)
info = tarfile.TarInfo("archive.json")
info.size = len(data)
self.addfile(info, fileobj=buffer)
def add_image(self, image, filename=None, directory=""):
def add_image(self, image: Any, filename: str = None, directory: Any = "") -> None:
"""
Add an image to the tar archive
:param str filename: overrides the file name set by image
@ -32,12 +32,12 @@ class BookwyrmTarFile(tarfile.TarFile):
self.addfile(info, fileobj=image)
def read(self, filename):
def read(self, filename: str) -> Any:
"""read data from the tar"""
with self.extractfile(filename) as reader:
return reader.read()
def write_image_to_file(self, filename, file_field):
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: