mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-04-25 19:54:07 +00:00
Adds helper function for loading editions
This commit is contained in:
parent
e11e1cc560
commit
d8aadb4587
4 changed files with 14 additions and 8 deletions
|
@ -8,6 +8,14 @@ from fedireads import models, settings
|
||||||
from fedireads.tasks import app
|
from fedireads.tasks import app
|
||||||
|
|
||||||
|
|
||||||
|
def get_edition(book_id):
|
||||||
|
''' look up a book in the db and return an edition '''
|
||||||
|
book = models.Book.objects.select_subclasses().get(id=book_id)
|
||||||
|
if isinstance(book, models.Work):
|
||||||
|
book = book.default_edition
|
||||||
|
return book
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_book(remote_id):
|
def get_or_create_book(remote_id):
|
||||||
''' pull up a book record by whatever means possible '''
|
''' pull up a book record by whatever means possible '''
|
||||||
book = get_by_absolute_id(remote_id, models.Book)
|
book = get_by_absolute_id(remote_id, models.Book)
|
||||||
|
|
|
@ -263,7 +263,7 @@ def handle_comment(user, book, content):
|
||||||
def handle_status(user, book_id, \
|
def handle_status(user, book_id, \
|
||||||
builder, fr_serializer, ap_serializer, *args):
|
builder, fr_serializer, ap_serializer, *args):
|
||||||
''' generic handler for statuses '''
|
''' generic handler for statuses '''
|
||||||
book = models.Book.objects.get(id=book_id)
|
book = models.Edition.objects.get(id=book_id)
|
||||||
status = builder(user, book, *args)
|
status = builder(user, book, *args)
|
||||||
|
|
||||||
activity = fr_serializer(status)
|
activity = fr_serializer(status)
|
||||||
|
|
|
@ -9,11 +9,11 @@ from django.http import HttpResponseBadRequest, HttpResponseNotFound
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
|
||||||
|
from fedireads import books_manager
|
||||||
from fedireads import forms, models, outgoing
|
from fedireads import forms, models, outgoing
|
||||||
from fedireads import goodreads_import
|
from fedireads import goodreads_import
|
||||||
from fedireads.settings import DOMAIN
|
from fedireads.settings import DOMAIN
|
||||||
from fedireads.views import get_user_from_username
|
from fedireads.views import get_user_from_username
|
||||||
from fedireads.books_manager import get_or_create_book
|
|
||||||
|
|
||||||
|
|
||||||
def user_login(request):
|
def user_login(request):
|
||||||
|
@ -118,7 +118,7 @@ def edit_profile(request):
|
||||||
def resolve_book(request):
|
def resolve_book(request):
|
||||||
''' figure out the local path to a book from a remote_id '''
|
''' figure out the local path to a book from a remote_id '''
|
||||||
remote_id = request.POST.get('remote_id')
|
remote_id = request.POST.get('remote_id')
|
||||||
book = get_or_create_book(remote_id)
|
book = books_manager.get_or_create_book(remote_id)
|
||||||
return redirect('/book/%d' % book.id)
|
return redirect('/book/%d' % book.id)
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ def upload_cover(request, book_id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
book = models.Edition.objects.get(id=book_id)
|
book = models.Edition.objects.get(id=book_id)
|
||||||
except models.Book.DoesNotExist:
|
except models.Edition.DoesNotExist:
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
form = forms.CoverForm(request.POST, request.FILES, instance=book)
|
form = forms.CoverForm(request.POST, request.FILES, instance=book)
|
||||||
|
@ -169,9 +169,7 @@ def upload_cover(request, book_id):
|
||||||
@login_required
|
@login_required
|
||||||
def shelve(request):
|
def shelve(request):
|
||||||
''' put a on a user's shelf '''
|
''' put a on a user's shelf '''
|
||||||
book = models.Book.objects.select_subclasses().get(id=request.POST['book'])
|
book = books_manager.get_edition(request.POST['book'])
|
||||||
if isinstance(book, models.Work):
|
|
||||||
book = book.default_edition
|
|
||||||
|
|
||||||
desired_shelf = models.Shelf.objects.filter(
|
desired_shelf = models.Shelf.objects.filter(
|
||||||
identifier=request.POST['shelf'],
|
identifier=request.POST['shelf'],
|
||||||
|
|
|
@ -469,7 +469,7 @@ def book_page(request, book_id, tab='friends'):
|
||||||
@login_required
|
@login_required
|
||||||
def edit_book_page(request, book_id):
|
def edit_book_page(request, book_id):
|
||||||
''' info about a book '''
|
''' info about a book '''
|
||||||
book = models.Book.objects.get(id=book_id)
|
book = books_manager.get_edition(book_id)
|
||||||
if not book.description:
|
if not book.description:
|
||||||
book.description = book.parent_work.description
|
book.description = book.parent_work.description
|
||||||
data = {
|
data = {
|
||||||
|
|
Loading…
Reference in a new issue