2023-09-05 22:35:26 +00:00
|
|
|
"""Import data from Bookwyrm export files"""
|
2023-10-23 10:30:17 +00:00
|
|
|
from django.http import QueryDict
|
|
|
|
|
|
|
|
from bookwyrm.models import User
|
2023-09-05 22:35:26 +00:00
|
|
|
from bookwyrm.models.bookwyrm_import_job import BookwyrmImportJob
|
|
|
|
|
|
|
|
|
|
|
|
class BookwyrmImporter:
|
2023-10-22 05:52:29 +00:00
|
|
|
"""Import a Bookwyrm User export file.
|
2023-09-05 22:35:26 +00:00
|
|
|
This is kind of a combination of an importer and a connector.
|
|
|
|
"""
|
|
|
|
|
2023-10-27 19:51:26 +00:00
|
|
|
# pylint: disable=no-self-use
|
2023-10-22 05:52:29 +00:00
|
|
|
def process_import(
|
2023-10-23 10:30:17 +00:00
|
|
|
self, user: User, archive_file: bytes, settings: QueryDict
|
2023-10-27 19:51:26 +00:00
|
|
|
) -> BookwyrmImportJob:
|
2023-09-05 22:35:26 +00:00
|
|
|
"""import user data from a Bookwyrm export file"""
|
|
|
|
|
|
|
|
required = [k for k in settings if settings.get(k) == "on"]
|
|
|
|
|
|
|
|
job = BookwyrmImportJob.objects.create(
|
|
|
|
user=user, archive_file=archive_file, required=required
|
|
|
|
)
|
|
|
|
return job
|