mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-14 12:16:31 +00:00
Merge branch 'main' into production
This commit is contained in:
commit
ea672c74e2
2 changed files with 27 additions and 3 deletions
|
@ -3,6 +3,7 @@ from uuid import uuid4
|
||||||
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
from django.db import transaction
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
@ -114,5 +115,22 @@ class Connector(AbstractConnector):
|
||||||
|
|
||||||
|
|
||||||
def expand_book_data(self, book):
|
def expand_book_data(self, book):
|
||||||
# TODO
|
work = book
|
||||||
pass
|
# go from the edition to the work, if necessary
|
||||||
|
if isinstance(book, models.Edition):
|
||||||
|
work = book.parent_work
|
||||||
|
|
||||||
|
# it may be that we actually want to request this url
|
||||||
|
editions_url = '%s/editions?page=true' % work.remote_id
|
||||||
|
edition_options = get_data(editions_url)
|
||||||
|
for edition_data in edition_options['orderedItems']:
|
||||||
|
with transaction.atomic():
|
||||||
|
edition = self.create_book(
|
||||||
|
edition_data['id'],
|
||||||
|
edition_data,
|
||||||
|
models.Edition
|
||||||
|
)
|
||||||
|
edition.parent_work = work
|
||||||
|
edition.save()
|
||||||
|
if not edition.authors.exists() and work.authors.exists():
|
||||||
|
edition.authors.set(work.authors.all())
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
|
|
||||||
|
@ -149,7 +150,12 @@ class Work(OrderedCollectionPageMixin, Book):
|
||||||
@property
|
@property
|
||||||
def editions_path(self):
|
def editions_path(self):
|
||||||
''' it'd be nice to serialize the edition instead but, recursion '''
|
''' it'd be nice to serialize the edition instead but, recursion '''
|
||||||
return [e.remote_id for e in self.edition_set.all()]
|
default = self.default_edition
|
||||||
|
ed_list = [
|
||||||
|
e.local_id for e in self.edition_set.filter(~Q(id=default.id)).all()
|
||||||
|
]
|
||||||
|
return [default.local_id] + ed_list
|
||||||
|
|
||||||
|
|
||||||
def to_edition_list(self, **kwargs):
|
def to_edition_list(self, **kwargs):
|
||||||
''' activitypub serialization for this work's editions '''
|
''' activitypub serialization for this work's editions '''
|
||||||
|
|
Loading…
Reference in a new issue