Merge pull request #3088 from hughrun/user-migration

User migration fixes
This commit is contained in:
Hugh Rundle 2023-11-06 16:06:39 +11:00 committed by GitHub
commit 15b7b7eaa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 505 deletions

View file

@ -123,33 +123,23 @@ def json_export(user): # pylint: disable=too-many-locals, too-many-statements
book["authors"] = list(edition.first().authors.all().values())
# readthroughs
book_readthroughs = (
ReadThrough.objects.filter(user=user, book=book["id"])
.distinct()
.values()
ReadThrough.objects.filter(user=user, book=book["id"]).distinct().values()
)
book["readthroughs"] = list(book_readthroughs)
# shelves
shelf_books = ShelfBook.objects.filter(
user=user, book=book["id"]
).distinct()
shelves_from_books = Shelf.objects.filter(
shelfbook__in=shelf_books, user=user
)
shelf_books = ShelfBook.objects.filter(user=user, book=book["id"]).distinct()
shelves_from_books = Shelf.objects.filter(shelfbook__in=shelf_books, user=user)
book["shelves"] = list(shelves_from_books.values())
book["shelf_books"] = {}
for shelf in shelves_from_books:
shelf_contents = ShelfBook.objects.filter(
user=user, shelf=shelf
).distinct()
shelf_contents = ShelfBook.objects.filter(user=user, shelf=shelf).distinct()
book["shelf_books"][shelf.identifier] = list(shelf_contents.values())
# book lists
book_lists = List.objects.filter(
books__in=[book["id"]], user=user
).distinct()
book_lists = List.objects.filter(books__in=[book["id"]], user=user).distinct()
book["lists"] = list(book_lists.values())
book["list_items"] = {}
for blist in book_lists:
@ -180,9 +170,7 @@ def json_export(user): # pylint: disable=too-many-locals, too-many-statements
# follows
follows = UserFollows.objects.filter(user_subject=user).distinct()
following = User.objects.filter(
userfollows_user_object__in=follows
).distinct()
following = User.objects.filter(userfollows_user_object__in=follows).distinct()
follows = [f.remote_id for f in following]
# blocks
@ -207,8 +195,8 @@ def get_books_for_user(user):
"""Get all the books and editions related to a user
:returns: tuple of editions, books
"""
all_books = Edition.viewer_aware_objects(user)
editions = all_books.filter(
editions = Edition.objects.filter(
Q(shelves__user=user)
| Q(readthrough__user=user)
| Q(review__user=user)

View file

@ -38,9 +38,32 @@
<label class="label" for="id_archive_file">{% trans "Data file:" %}</label>
{{ import_form.archive_file }}
</div>
<div>
<p class="block"> {% trans "Importing this file will overwrite any data you currently have saved." %}</p>
<p class="block">{% trans "Deselect any data you do not wish to include in your import. Books will always be imported" %}</p>
<div class="content">
{% blocktrans trimmed %}
<p class="block">Deselect any checkboxes for data you do not wish to include in your import.</p>
<p class="block">Importing this file will not delete any data but <strong>will overwrite the following information</strong>:</p>
<ul>
<li>Profile</li>
<ul>
<li>name</li>
<li>summary</li>
<li>avatar</li>
</ul>
<li>Settings</li>
<ul>
<li>whether manual approval is required for other users to follow your account</li>
<li>whether following/followers are shown on your profile</li>
<li>whether your reading goal is shown on your profile</li>
<li>whether you see user follow suggestions</li>
<li>whether your account is suggested to others</li>
<li>your timezone</li>
<li>your default post privacy setting</li>
</ul>
<li>Reading goals for all years listed in the import file</li>
</ul>
<p class="block">All other imported data will be <strong>added if it does not already exist</strong>. For example, if you have an existing list with the same name as an imported list, the existing list settings will not change, any new list items will be added, and no existing list items will be deleted.</p>
{% endblocktrans %}
</div>
</div>

View file

@ -9,16 +9,16 @@
{% block panel %}
<div class="block content">
<p class="notification">
{% trans "Your exported archive file will include all user data for import into another Bookwyrm server" %}
</p>
{% if next_available %}
<p class="notification is-warning">
{% blocktrans %}
{% blocktrans trimmed %}
You will be able to create a new export file at {{ next_available }}
{% endblocktrans %}
</p>
{% else %}
<p class="notification">
{% trans "Your exported archive file will include all user data for import into another Bookwyrm server" %}
</p>
<form name="export" method="POST" href="{% url 'prefs-user-export' %}">
{% csrf_token %}
<button type="submit" class="button">

View file

@ -1,452 +0,0 @@
{
"user": {
"username": "rat@www.example.com",
"name": "Rat",
"summary": "I love to make soup in Paris and eat pizza in New York",
"manually_approves_followers": true,
"hide_follows": true,
"show_goal": false,
"show_suggested_users": false,
"discoverable": false,
"preferred_timezone": "Australia/Adelaide",
"default_post_privacy": "followers"
},
"goals": [
{
"goal": 12,
"year": 2023,
"privacy": "followers"
}
],
"books": [
{
"id": 4880,
"created_date": "2023-08-14T02:03:12.509Z",
"updated_date": "2023-08-14T02:04:51.602Z",
"remote_id": "https://www.example.com/book/4880",
"origin_id": "https://bookwyrm.social/book/9389",
"openlibrary_key": "OL680025M",
"inventaire_id": "isbn:9780300070163",
"librarything_key": null,
"goodreads_key": null,
"bnf_id": null,
"viaf": null,
"wikidata": null,
"asin": null,
"aasin": null,
"isfdb": null,
"search_vector": "'c':16C 'certain':6B 'condit':12B 'fail':14B 'human':11B 'improv':9B 'james':15C 'like':2A 'scheme':7B 'scott':17C 'see':1A 'state':4A",
"last_edited_by_id": 243,
"connector_id": null,
"title": "Seeing Like a State",
"sort_title": "seeing like a state",
"subtitle": "how certain schemes to improve the human condition have failed",
"description": "<p>Examines how (sometimes quasi-) authoritarian high-modernist planning fails to deliver the goods, be they increased resources for the state or a better life for the people.</p>",
"languages": [
"English"
],
"series": "",
"series_number": "",
"subjects": [],
"subject_places": [],
"cover": "covers/d273d638-191d-4ebf-b213-3c60dbf010fe.jpeg",
"preview_image": "",
"first_published_date": null,
"published_date": "1998-03-30T00:00:00Z",
"edition": {
"id": 4880,
"created_date": "2023-08-14T02:03:12.509Z",
"updated_date": "2023-08-14T02:04:51.602Z",
"remote_id": "https://www.example.com/book/4880",
"origin_id": "https://bookwyrm.social/book/9389",
"openlibrary_key": "OL680025M",
"inventaire_id": "isbn:9780300070163",
"librarything_key": null,
"goodreads_key": null,
"bnf_id": null,
"viaf": null,
"wikidata": null,
"asin": null,
"aasin": null,
"isfdb": null,
"search_vector": "'c':16C 'certain':6B 'condit':12B 'fail':14B 'human':11B 'improv':9B 'james':15C 'like':2A 'scheme':7B 'scott':17C 'see':1A 'state':4A",
"last_edited_by_id": 243,
"connector_id": null,
"title": "Seeing Like a State",
"sort_title": "seeing like a state",
"subtitle": "how certain schemes to improve the human condition have failed",
"description": "<p>Examines how (sometimes quasi-) authoritarian high-modernist planning fails to deliver the goods, be they increased resources for the state or a better life for the people.</p>",
"languages": [
"English"
],
"series": "",
"series_number": "",
"subjects": [],
"subject_places": [],
"cover": "covers/d273d638-191d-4ebf-b213-3c60dbf010fe.jpeg",
"preview_image": "",
"first_published_date": null,
"published_date": "1998-03-30T00:00:00Z",
"book_ptr_id": 4880,
"isbn_10": "0300070160",
"isbn_13": "9780300070163",
"oclc_number": "",
"pages": 445,
"physical_format": "",
"physical_format_detail": "",
"publishers": [],
"parent_work_id": 4877,
"edition_rank": 8
},
"authors": [
{
"id": 1189,
"created_date": "2023-08-14T02:03:11.578Z",
"updated_date": "2023-08-14T02:03:11.578Z",
"remote_id": "https://www.example.com/author/1189",
"origin_id": "https://bookwyrm.social/author/1110",
"openlibrary_key": "OL4398216A",
"inventaire_id": "wd:Q3025403",
"librarything_key": "scottjamesc",
"goodreads_key": "11958",
"bnf_id": "120602158",
"viaf": "47858502",
"wikidata": "Q3025403",
"asin": "B001H9W1D2",
"aasin": null,
"search_vector": null,
"last_edited_by_id": 62,
"wikipedia_link": "https://en.wikipedia.org/wiki/James_C._Scott",
"isni": "0000000108973024",
"gutenberg_id": null,
"isfdb": null,
"website": "",
"born": "1934-12-01T23:00:00Z",
"died": null,
"name": "James C. Scott",
"aliases": [
"James Campbell Scott",
"\u30b8\u30a7\u30fc\u30e0\u30ba\u30fbC. \u30b9\u30b3\u30c3\u30c8",
"\u30b8\u30a7\u30fc\u30e0\u30ba\u30fbC\u30fb\u30b9\u30b3\u30c3\u30c8",
"\u062c\u06cc\u0645\u0632 \u0633\u06cc. \u0627\u0633\u06a9\u0627\u062a",
"Jim Scott",
"\u062c\u064a\u0645\u0633 \u0633\u0643\u0648\u062a",
"James C. Scott",
"\u0414\u0436\u0435\u0439\u043c\u0441 \u0421\u043a\u043e\u0442\u0442",
"\u30b8\u30a7\u30fc\u30e0\u30b9\u30fbC \u30b9\u30b3\u30c3\u30c8",
"James Cameron Scott"
],
"bio": "<p>American political scientist and anthropologist</p>"
}
],
"readthroughs": [
{
"id": 1,
"created_date": "2023-08-14T04:00:27.544Z",
"updated_date": "2023-08-14T04:00:27.546Z",
"remote_id": "https://www.example.com/user/rat/readthrough/1",
"user_id": 1,
"book_id": 4880,
"progress": null,
"progress_mode": "PG",
"start_date": "2018-01-01T00:00:00Z",
"finish_date": "2023-08-13T00:00:00Z",
"stopped_date": null,
"is_active": false
}
],
"shelves": [
{
"id": 3,
"created_date": "2023-08-13T05:02:16.554Z",
"updated_date": "2023-08-13T05:02:16.554Z",
"remote_id": "https://www.example.com/user/rat/books/read",
"name": "Read",
"identifier": "read",
"description": null,
"user_id": 1,
"editable": false,
"privacy": "public"
},
{
"id": 1,
"created_date": "2023-08-13T05:02:16.551Z",
"updated_date": "2023-08-13T05:02:16.552Z",
"remote_id": "https://www.example.com/user/rat/books/to-read",
"name": "To Read",
"identifier": "to-read",
"description": null,
"user_id": 1,
"editable": false,
"privacy": "public"
}
],
"shelf_books": {
"read": [
{
"id": 1,
"created_date": "2023-08-14T02:51:09.005Z",
"updated_date": "2023-08-14T02:51:09.015Z",
"remote_id": "https://www.example.com/user/rat/shelfbook/1",
"book_id": 4880,
"shelf_id": 3,
"shelved_date": "2023-08-13T03:52:49.196Z",
"user_id": 1
}
],
"to-read": [
{
"id": 2,
"created_date": "2023-08-14T04:00:27.558Z",
"updated_date": "2023-08-14T04:00:27.564Z",
"remote_id": "https://www.example.com/user/rat/shelfbook/2",
"book_id": 4880,
"shelf_id": 1,
"shelved_date": "2023-08-13T03:51:13.175Z",
"user_id": 1
}
]
},
"lists": [
{
"id": 2,
"created_date": "2023-08-14T04:00:27.585Z",
"updated_date": "2023-08-14T04:02:54.826Z",
"remote_id": "https://www.example.com/list/2",
"name": "my list of books",
"user_id": 1,
"description": "Here is a description of my list",
"privacy": "followers",
"curation": "closed",
"group_id": null,
"embed_key": "6759a53e-3581-4685-b77a-7de765c03480"
}
],
"list_items": {
"my list of books": [
{
"id": 1,
"created_date": "2023-08-14T04:02:54.806Z",
"updated_date": "2023-08-14T04:02:54.808Z",
"remote_id": "https://www.example.com/user/rat/listitem/1",
"book_id": 4880,
"book_list_id": 2,
"user_id": 1,
"notes": "It's fun.",
"approved": true,
"order": 1
}
]
},
"reviews": [
{
"id": 1082,
"created_date": "2023-08-14T04:09:18.354Z",
"updated_date": "2023-08-14T04:09:18.382Z",
"remote_id": "https://www.example.com/user/rat/review/1082",
"user_id": 1,
"content": "<p>I like it</p>",
"raw_content": "I like it",
"local": true,
"content_warning": "Here's a spoiler alert",
"privacy": "followers",
"sensitive": true,
"published_date": "2023-08-14T04:09:18.343Z",
"edited_date": null,
"deleted": false,
"deleted_date": null,
"reply_parent_id": null,
"thread_id": 1082,
"ready": true,
"status_ptr_id": 1082,
"book_id": 4880,
"reading_status": null,
"name": "great book",
"rating": "5.00"
}
],
"comments": [],
"quotes": []
},
{
"id": 6190,
"created_date": "2023-08-14T04:48:02.034Z",
"updated_date": "2023-08-14T04:48:02.174Z",
"remote_id": "https://www.example.com/book/6190",
"origin_id": "https://bookrastinating.com/book/330127",
"openlibrary_key": null,
"inventaire_id": "isbn:9780062975645",
"librarything_key": null,
"goodreads_key": null,
"bnf_id": null,
"viaf": null,
"wikidata": null,
"asin": null,
"aasin": null,
"isfdb": null,
"search_vector": "'indigen':4A 'sand':1A 'save':7A 'talk':2A 'think':5A 'tyson':10C 'world':9A 'yunkaporta':11C",
"last_edited_by_id": null,
"connector_id": null,
"title": "Sand Talk: How Indigenous Thinking Can Save the World",
"sort_title": null,
"subtitle": null,
"description": null,
"languages": [
"English"
],
"series": "",
"series_number": "",
"subjects": [],
"subject_places": [],
"cover": "covers/6a553a08-2641-42a1-baa4-960df9edbbfc.jpeg",
"preview_image": "",
"first_published_date": null,
"published_date": "2020-11-26T00:00:00Z",
"edition": {
"id": 4265,
"created_date": "2023-08-24T10:18:16.563Z",
"updated_date": "2023-08-24T10:18:16.649Z",
"remote_id": "https://www.example.com/book/4265",
"origin_id": "https://bookwyrm.social/book/65189",
"openlibrary_key": "OL28216445M",
"inventaire_id": null,
"librarything_key": "",
"goodreads_key": null,
"bnf_id": null,
"viaf": null,
"wikidata": null,
"asin": null,
"aasin": null,
"isfdb": null,
"search_vector": "'indigen':4B 'sand':1A 'save':7B 'talk':2A 'think':5B 'tyson':10C 'world':9B 'yunkaporta':11C",
"last_edited_by_id": 241,
"connector_id": null,
"title": "Sand Talk",
"sort_title": null,
"subtitle": "How Indigenous Thinking Can Save the World",
"description": "<p>As an indigenous person, Tyson Yunkaporta looks at global systems from a unique perspective, one tied to the natural and spiritual world. In considering how contemporary life diverges from the pattern of creation, he raises important questions. How does this affect us? How can we do things differently?</p>\n<p>In this thoughtful, culturally rich, mind-expanding book, he provides answers. Yunkaporta\u2019s writing process begins with images. Honoring indigenous traditions, he makes carvings of what he wants to say, channeling his thoughts through symbols and diagrams rather than words. He yarns with people, looking for ways to connect images and stories with place and relationship to create a coherent world view, and he uses sand talk, the Aboriginal custom of drawing images on the ground to convey knowledge. </p>\n<p>In Sand Talk, he provides a new model for our everyday lives. Rich in ideas and inspiration, it explains how lines and symbols and shapes can help us make sense of the world. It\u2019s about how we learn and how we remember. It\u2019s about talking to everyone and listening carefully. It\u2019s about finding different ways to look at things.</p>\n<p>Most of all it\u2019s about a very special way of thinking, of learning to see from a native perspective, one that is spiritually and physically tied to the earth around us, and how it can save our world.</p>\n<p>Sand Talk include 22 black-and-white illustrations that add depth to the text.</p>",
"languages": [],
"series": "",
"series_number": "",
"subjects": [],
"subject_places": [],
"cover": "covers/70d90f7d-8b81-431d-9b00-ca2656b06ca0.jpeg",
"preview_image": "",
"first_published_date": null,
"published_date": "2020-05-12T00:00:00Z",
"book_ptr_id": 4265,
"isbn_10": "",
"isbn_13": "",
"oclc_number": "",
"pages": 256,
"physical_format": "",
"physical_format_detail": "hardcover",
"publishers": [
"HarperOne"
],
"parent_work_id": 4263,
"edition_rank": 5
},
"authors": [
{
"id": 1390,
"created_date": "2023-08-14T04:48:00.433Z",
"updated_date": "2023-08-14T04:48:00.436Z",
"remote_id": "https://www.example.com/author/1390",
"origin_id": "https://bookrastinating.com/author/52150",
"openlibrary_key": null,
"inventaire_id": null,
"librarything_key": null,
"goodreads_key": null,
"bnf_id": null,
"viaf": null,
"wikidata": null,
"asin": null,
"aasin": null,
"search_vector": null,
"last_edited_by_id": null,
"wikipedia_link": "",
"isni": null,
"gutenberg_id": null,
"isfdb": null,
"website": "",
"born": null,
"died": null,
"name": "Tyson Yunkaporta",
"aliases": [],
"bio": null
}
],
"readthroughs": [],
"shelves": [],
"shelf_books": {},
"lists": [],
"list_items": {},
"reviews": [],
"comments": [
{
"id": 1083,
"created_date": "2023-08-14T04:48:18.753Z",
"updated_date": "2023-08-14T04:48:18.769Z",
"remote_id": "https://www.example.com/user/rat/comment/1083",
"user_id": 1,
"content": "<p>this is a comment about an amazing book</p>",
"raw_content": "this is a comment about an amazing book",
"local": true,
"content_warning": null,
"privacy": "followers",
"sensitive": false,
"published_date": "2023-08-14T04:48:18.746Z",
"edited_date": null,
"deleted": false,
"deleted_date": null,
"reply_parent_id": null,
"thread_id": 1083,
"ready": true,
"status_ptr_id": 1083,
"book_id": 6190,
"reading_status": null,
"progress": null,
"progress_mode": "PG"
}
],
"quotes": [
{
"id": 1084,
"created_date": "2023-08-14T04:48:50.216Z",
"updated_date": "2023-08-14T04:48:50.234Z",
"remote_id": "https://www.example.com/user/rat/quotation/1084",
"user_id": 1,
"content": "<p>not actually from this book lol</p>",
"raw_content": "not actually from this book lol",
"local": true,
"content_warning": "spoiler ahead!",
"privacy": "followers",
"sensitive": true,
"published_date": "2023-08-14T04:48:50.207Z",
"edited_date": null,
"deleted": false,
"deleted_date": null,
"reply_parent_id": null,
"thread_id": 1084,
"ready": true,
"status_ptr_id": 1084,
"book_id": 6190,
"reading_status": null,
"quote": "<p>To be or not to be</p>",
"raw_quote": "To be or not to be",
"position": 1,
"endposition": null,
"position_mode": "PG"
}
]
}
],
"saved_lists": [
"https://local.lists/9999"
],
"follows": [
"https://your.domain.here/user/rat"
],
"blocked_users": ["https://your.domain.here/user/badger"]
}

View file

@ -1,26 +0,0 @@
{
"user": {
"username": "hugh@example.com",
"name": "Hugh",
"summary": "just a test account",
"manually_approves_followers": false,
"hide_follows": false,
"show_goal": true,
"show_suggested_users": true,
"discoverable": true,
"preferred_timezone": "Australia/Broken_Hill",
"default_post_privacy": "public",
"avatar": ""
},
"goals": [
{
"goal": 12,
"year": 2023,
"privacy": "public"
}
],
"books": [],
"saved_lists": [],
"follows": [],
"blocked_users": []
}