From db8c686dd35df0126ee770455651d99d15458c82 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Wed, 3 Jan 2024 15:43:15 +0100 Subject: [PATCH 01/10] Include book Readtrhough in the csv export --- bookwyrm/views/preferences/export.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index f54d97ccb..c691e2f50 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -54,6 +54,7 @@ class Export(View): fields = ( ["title", "author_text"] + deduplication_fields + + ["start_date", "finish_date", "stopped_date"] + ["rating", "review_name", "review_cw", "review_content"] ) writer.writerow(fields) @@ -70,6 +71,18 @@ class Export(View): book.rating = review_rating.rating if review_rating else None + readthrough = ( + models.ReadThrough.objects.filter( + user=request.user, book=book + ) + .order_by("-finish_date") + .first() + ) + if readthrough: + book.start_date = readthrough.start_date + book.finish_date = readthrough.finish_date + book.stopped_date = readthrough.stopped_date + review = ( models.Review.objects.filter( user=request.user, book=book, content__isnull=False From 766a2163ddc745afe0ecc4871f38d37235cb2cb9 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Wed, 3 Jan 2024 20:41:31 +0100 Subject: [PATCH 02/10] Code formatting --- bookwyrm/views/preferences/export.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index c691e2f50..5a3b0fd8e 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -72,9 +72,7 @@ class Export(View): book.rating = review_rating.rating if review_rating else None readthrough = ( - models.ReadThrough.objects.filter( - user=request.user, book=book - ) + models.ReadThrough.objects.filter(user=request.user, book=book) .order_by("-finish_date") .first() ) From ae5950f1871f2ac168c810a0a6bc98c7b5e37474 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:03:07 +0100 Subject: [PATCH 03/10] Add readthrough fields to text_export.py --- bookwyrm/tests/views/preferences/test_export.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 4f498f589..d633ae952 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -66,7 +66,7 @@ class ExportViews(TestCase): # 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", ) From 9acb5f66fee9e64f43c703f1dd631146f35a7724 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:26:44 +0100 Subject: [PATCH 04/10] Convert DateTime to date --- bookwyrm/views/preferences/export.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index 5a3b0fd8e..4353cf259 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -77,9 +77,9 @@ class Export(View): .first() ) if readthrough: - book.start_date = readthrough.start_date - book.finish_date = readthrough.finish_date - book.stopped_date = readthrough.stopped_date + book.start_date = readthrough.start_date.date() if readthrough.start_date else "" + book.finish_date = readthrough.finish_date.date() if readthrough.finish_date else "" + book.stopped_date = readthrough.stopped_date.date() if readthrough.stopped_date else "" review = ( models.Review.objects.filter( From 51cb70d34423afb65653947bff15a90a8fc3278e Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:27:17 +0100 Subject: [PATCH 05/10] Change readhtrough order --- bookwyrm/views/preferences/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index 4353cf259..c8badbc8c 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -73,7 +73,7 @@ class Export(View): readthrough = ( models.ReadThrough.objects.filter(user=request.user, book=book) - .order_by("-finish_date") + .order_by("-start_date","-finish_date") .first() ) if readthrough: From 30c9ec9611530ee8d98eaef8fc046c5e514d9f28 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:28:17 +0100 Subject: [PATCH 06/10] Prevent lint error See @hughrun 's explanation https://github.com/bookwyrm-social/bookwyrm/pull/3189#issuecomment-1876145423 --- bookwyrm/tests/views/preferences/test_export.py | 4 +++- bookwyrm/views/preferences/export.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index d633ae952..2ef0f96fb 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -38,6 +38,8 @@ class ExportViews(TestCase): parent_work=self.work, isbn_13="9781234567890", bnf_id="beep", + start_date="2023-01-04", + finish_date="2024-01-04" ) def setUp(self): @@ -68,5 +70,5 @@ class ExportViews(TestCase): 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,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,,,2023-01-04,2024-01-04,,,,\r\n", ) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index c8badbc8c..2450a427d 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -103,7 +103,7 @@ class Export(View): ) -# pylint: disable=no-self-use +# pylint: disable=no-self-use,too-many-locals @method_decorator(login_required, name="dispatch") class ExportUser(View): """Let users export user data to import into another Bookwyrm instance""" From ebcc81dd73b295141a16407fded008d3c0abb85d Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:33:26 +0100 Subject: [PATCH 07/10] Revert changes to default book These changes were introduced by mistake in my previous commit. --- bookwyrm/tests/views/preferences/test_export.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 2ef0f96fb..74201ddad 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -37,9 +37,7 @@ class ExportViews(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, isbn_13="9781234567890", - bnf_id="beep", - start_date="2023-01-04", - finish_date="2024-01-04" + bnf_id="beep" ) def setUp(self): @@ -70,5 +68,5 @@ class ExportViews(TestCase): 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,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,,,2023-01-04,2024-01-04,,,,\r\n", + + b",,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,\r\n", ) From c2622a510cd40eb3883eae4d01ccf2095754aa3b Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:40:40 +0100 Subject: [PATCH 08/10] Change else statement to None vs "" --- bookwyrm/views/preferences/export.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index 2450a427d..a6d51e24a 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -77,9 +77,9 @@ class Export(View): .first() ) if readthrough: - book.start_date = readthrough.start_date.date() if readthrough.start_date else "" - book.finish_date = readthrough.finish_date.date() if readthrough.finish_date else "" - book.stopped_date = readthrough.stopped_date.date() if readthrough.stopped_date else "" + 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( From 93cab480d6a7cc1d8897d8a0a765c6ce9f5301a4 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Sat, 6 Jan 2024 09:50:14 +0100 Subject: [PATCH 09/10] Code format --- bookwyrm/tests/views/preferences/test_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 74201ddad..d633ae952 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -37,7 +37,7 @@ class ExportViews(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, isbn_13="9781234567890", - bnf_id="beep" + bnf_id="beep", ) def setUp(self): From ce18d343e8de7a40b2da17fae0ebff1c065eda9f Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Sat, 6 Jan 2024 09:53:22 +0100 Subject: [PATCH 10/10] Fix pylint error and code format --- bookwyrm/views/preferences/export.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index a6d51e24a..3443be461 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -17,7 +17,7 @@ from bookwyrm import models 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""" @@ -73,13 +73,21 @@ class Export(View): readthrough = ( models.ReadThrough.objects.filter(user=request.user, book=book) - .order_by("-start_date","-finish_date") + .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 + 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( @@ -103,7 +111,7 @@ class Export(View): ) -# pylint: disable=no-self-use,too-many-locals +# pylint: disable=no-self-use @method_decorator(login_required, name="dispatch") class ExportUser(View): """Let users export user data to import into another Bookwyrm instance"""