Skip to content

Commit

Permalink
Merge pull request #3189 from ccamara/2965_export_readthrough
Browse files Browse the repository at this point in the history
Export ReadThrough in the csv export
  • Loading branch information
hughrun authored Jan 12, 2024
2 parents a4599d0 + 5d13bf8 commit b04ebe3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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:
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

0 comments on commit b04ebe3

Please sign in to comment.