Merge pull request #746 from mouse-reeve/editions

Adds ability to reset default edition based on computer ranks
This commit is contained in:
Mouse Reeve 2021-03-15 15:31:20 -07:00 committed by GitHub
commit 4e45d5a2dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View file

@ -1,7 +1,7 @@
""" database schema for books and shelves """
import re
from django.db import models
from django.db import models, transaction
from model_utils.managers import InheritanceManager
from bookwyrm import activitypub
@ -148,6 +148,15 @@ class Work(OrderedCollectionPageMixin, Book):
""" in case the default edition is not set """
return self.default_edition or self.editions.order_by("-edition_rank").first()
@transaction.atomic()
def reset_default_edition(self):
""" sets a new default edition based on computed rank """
self.default_edition = None
# editions are re-ranked implicitly
self.save()
self.default_edition = self.get_default_edition()
self.save()
def to_edition_list(self, **kwargs):
""" an ordered collection of editions """
return self.to_ordered_collection(
@ -200,9 +209,13 @@ class Edition(Book):
activity_serializer = activitypub.Edition
name_field = "title"
def get_rank(self):
def get_rank(self, ignore_default=False):
""" calculate how complete the data is on this edition """
if self.parent_work and self.parent_work.default_edition == self:
if (
not ignore_default
and self.parent_work
and self.parent_work.default_edition == self
):
# default edition has the highest rank
return 20
rank = 0

View file

@ -6,7 +6,7 @@
{% block content %}
<div class="block">
<h1 class="title">{% blocktrans with path=work.local_path work_title=work.title %}Editions of <a href="{{ work_path }}">"{{ work_title }}"</a>{% endblocktrans %}</h1>
<h1 class="title">{% blocktrans with work_path=work.local_path work_title=work.title %}Editions of <a href="{{ work_path }}">"{{ work_title }}"</a>{% endblocktrans %}</h1>
{% include 'snippets/book_tiles.html' with books=editions %}
</div>