mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-24 17:10:31 +00:00
Merge pull request #746 from mouse-reeve/editions
Adds ability to reset default edition based on computer ranks
This commit is contained in:
commit
4e45d5a2dc
2 changed files with 17 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
""" database schema for books and shelves """
|
""" database schema for books and shelves """
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models, transaction
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
|
@ -148,6 +148,15 @@ class Work(OrderedCollectionPageMixin, Book):
|
||||||
""" in case the default edition is not set """
|
""" in case the default edition is not set """
|
||||||
return self.default_edition or self.editions.order_by("-edition_rank").first()
|
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):
|
def to_edition_list(self, **kwargs):
|
||||||
""" an ordered collection of editions """
|
""" an ordered collection of editions """
|
||||||
return self.to_ordered_collection(
|
return self.to_ordered_collection(
|
||||||
|
@ -200,9 +209,13 @@ class Edition(Book):
|
||||||
activity_serializer = activitypub.Edition
|
activity_serializer = activitypub.Edition
|
||||||
name_field = "title"
|
name_field = "title"
|
||||||
|
|
||||||
def get_rank(self):
|
def get_rank(self, ignore_default=False):
|
||||||
""" calculate how complete the data is on this edition """
|
""" 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
|
# default edition has the highest rank
|
||||||
return 20
|
return 20
|
||||||
rank = 0
|
rank = 0
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="block">
|
<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 %}
|
{% include 'snippets/book_tiles.html' with books=editions %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue