Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export ReadThrough in the csv export #3189

Merged
merged 11 commits into from
Jan 12, 2024
4 changes: 2 additions & 2 deletions bookwyrm/tests/views/preferences/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_export_file(self, *_):
# pylint: disable=line-too-long
self.assertEqual(
export.content,
b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,rating,review_name,review_cw,review_content\r\nTest Book,,"
b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content\r\nTest Book,,"
+ self.book.remote_id.encode("utf-8")
+ b",,,,,beep,,,,,,123456789X,9781234567890,,,,,\r\n",
+ b",,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,\r\n",
)
21 changes: 20 additions & 1 deletion bookwyrm/views/preferences/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from bookwyrm.models.bookwyrm_export_job import BookwyrmExportJob
from bookwyrm.settings import PAGE_LENGTH

# pylint: disable=no-self-use
# pylint: disable=no-self-use,too-many-locals
@method_decorator(login_required, name="dispatch")
class Export(View):
"""Let users export data"""
Expand Down Expand Up @@ -54,6 +54,7 @@ def post(self, request):
fields = (
["title", "author_text"]
+ deduplication_fields
+ ["start_date", "finish_date", "stopped_date"]
+ ["rating", "review_name", "review_cw", "review_content"]
)
writer.writerow(fields)
Expand All @@ -70,6 +71,24 @@ def post(self, request):

book.rating = review_rating.rating if review_rating else None

readthrough = (
models.ReadThrough.objects.filter(user=request.user, book=book)
.order_by("-start_date", "-finish_date")
.first()
)
if readthrough:
ccamara marked this conversation as resolved.
Show resolved Hide resolved
book.start_date = (
readthrough.start_date.date() if readthrough.start_date else None
)
book.finish_date = (
readthrough.finish_date.date() if readthrough.finish_date else None
)
book.stopped_date = (
readthrough.stopped_date.date()
if readthrough.stopped_date
else None
)

review = (
models.Review.objects.filter(
user=request.user, book=book, content__isnull=False
Expand Down
Loading