show comments from related books
This commit is contained in:
parent
012e557410
commit
c5e0dd5432
6 changed files with 31 additions and 26 deletions
|
@ -198,15 +198,14 @@ class Edition(Item):
|
|||
if work and work not in self.works.all():
|
||||
self.works.add(work)
|
||||
|
||||
def get_related_books(self):
|
||||
@property
|
||||
def sibling_items(self):
|
||||
works = list(self.works.all())
|
||||
return (
|
||||
Edition.objects.filter(works__in=works)
|
||||
.distinct()
|
||||
.exclude(pk=self.pk)
|
||||
.exclude(is_deleted=True)
|
||||
.exclude(merged_to_item__isnull=False)
|
||||
.order_by("title")
|
||||
)
|
||||
|
||||
def has_related_books(self):
|
||||
|
@ -275,16 +274,17 @@ class Work(Item):
|
|||
return [(i.value, i.label) for i in id_types]
|
||||
|
||||
def merge_to(self, to_item):
|
||||
super().merge_to(to_item)
|
||||
for edition in self.editions.all():
|
||||
to_item.editions.add(edition)
|
||||
self.editions.clear()
|
||||
if (
|
||||
to_item
|
||||
and self.title != to_item.title
|
||||
and self.title not in to_item.other_title
|
||||
):
|
||||
to_item.other_title += [self.title]
|
||||
super().merge_to(to_item)
|
||||
for edition in self.editions.all():
|
||||
to_item.editions.add(edition)
|
||||
self.editions.clear()
|
||||
to_item.save()
|
||||
|
||||
def delete(self, using=None, soft=True, *args, **kwargs):
|
||||
if soft:
|
||||
|
|
|
@ -350,6 +350,14 @@ class Item(SoftDeleteMixin, PolymorphicModel):
|
|||
def parent_uuid(self):
|
||||
return self.parent_item.uuid if self.parent_item else None
|
||||
|
||||
@property
|
||||
def sibling_items(self):
|
||||
return Item.objects.none()
|
||||
|
||||
@property
|
||||
def sibling_item_ids(self):
|
||||
return list(self.sibling_items.values_list("id", flat=True))
|
||||
|
||||
@classmethod
|
||||
def get_ap_object_type(cls):
|
||||
return cls.__name__
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
_sidebar_auto_collapse(mm);
|
||||
});
|
||||
</script>
|
||||
{% with related_books=item.get_related_books %}
|
||||
{% with related_books=item.sibling_items %}
|
||||
{% if related_books.count > 0 %}
|
||||
<section>
|
||||
<details class="auto-collapse" open>
|
||||
|
|
|
@ -64,21 +64,6 @@
|
|||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="work-tip" style="display:none;">
|
||||
{% if item.class_name == 'work' %}
|
||||
<div _="init hide .item-mark-buttons then hide .item-mark-icon then show .work-tip end">
|
||||
<details open>
|
||||
<summary>{% trans '本著作包含以下图书版本' %}</summary>
|
||||
{% for b in item.editions.all %}
|
||||
<div>
|
||||
<a href="{{ b.url }}">{{ b.title }}</a>
|
||||
<small>({{ b.pub_house | default:'' }} {{ b.pub_year | default:'' }})</small>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</details>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tv-tip" style="display:none;">
|
||||
这是全剧条目,以下是可标记的单季
|
||||
{% if item.class_name == 'tvshow' %}
|
||||
|
|
|
@ -30,6 +30,18 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block left_sidebar %}{% endblock %}
|
||||
{% block left_sidebar %}
|
||||
<div _="init hide .item-mark-buttons then hide .item-mark-icon end">
|
||||
<details open>
|
||||
<summary>{% trans '本著作包含以下图书版本' %}</summary>
|
||||
{% for b in item.editions.all %}
|
||||
<div>
|
||||
<a href="{{ b.url }}">{{ b.title }}</a>
|
||||
<small>({{ b.pub_house | default:'' }} {{ b.pub_year | default:'' }})</small>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</details>
|
||||
</div>
|
||||
{% endblock %}
|
||||
<!-- class specific sidebar -->
|
||||
{% block sidebar %}{% endblock %}
|
||||
|
|
|
@ -194,7 +194,7 @@ def comments(request, item_path, item_uuid):
|
|||
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
|
||||
if not item:
|
||||
raise Http404()
|
||||
ids = item.child_item_ids + [item.id]
|
||||
ids = item.child_item_ids + [item.id] + item.sibling_item_ids
|
||||
queryset = Comment.objects.filter(item_id__in=ids).order_by("-created_time")
|
||||
queryset = queryset.filter(q_piece_visible_to_user(request.user))
|
||||
before_time = request.GET.get("last")
|
||||
|
@ -240,7 +240,7 @@ def reviews(request, item_path, item_uuid):
|
|||
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
|
||||
if not item:
|
||||
raise Http404()
|
||||
ids = item.child_item_ids + [item.id]
|
||||
ids = item.child_item_ids + [item.id] + item.sibling_item_ids
|
||||
queryset = Review.objects.filter(item_id__in=ids).order_by("-created_time")
|
||||
queryset = queryset.filter(q_piece_visible_to_user(request.user))
|
||||
before_time = request.GET.get("last")
|
||||
|
|
Loading…
Add table
Reference in a new issue