From afd058f64006c4fae5c9b6b5e2b411cfd84ce969 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 8 Jan 2023 22:10:48 -0500 Subject: [PATCH] fix collection note error --- catalog/common/models.py | 3 +++ catalog/models.py | 3 +++ journal/importers/goodreads.py | 4 +--- journal/models.py | 4 ++++ journal/templates/list_item_base.html | 2 +- journal/tests.py | 4 +++- journal/views.py | 2 +- legacy/management/commands/migrate_journal.py | 2 +- 8 files changed, 17 insertions(+), 7 deletions(-) diff --git a/catalog/common/models.py b/catalog/common/models.py index c9e7614d..4ee7aabb 100644 --- a/catalog/common/models.py +++ b/catalog/common/models.py @@ -338,6 +338,9 @@ class Item(SoftDeleteMixin, PolymorphicModel): """Subclass should override this""" pass + def skip_index(self): + return False + class ItemLookupId(models.Model): item = models.ForeignKey( diff --git a/catalog/models.py b/catalog/models.py index cac6107d..a390e743 100644 --- a/catalog/models.py +++ b/catalog/models.py @@ -84,3 +84,6 @@ def init_catalog_search_models(): Indexer.update_model_indexable(TVSeason) Indexer.update_model_indexable(Album) Indexer.update_model_indexable(Game) + Indexer.update_model_indexable(Podcast) + Indexer.update_model_indexable(Performance) + # Indexer.update_model_indexable(CatalogCollection) diff --git a/journal/importers/goodreads.py b/journal/importers/goodreads.py index 61a5829a..bc5cb8a7 100644 --- a/journal/importers/goodreads.py +++ b/journal/importers/goodreads.py @@ -60,9 +60,7 @@ class GoodreadsImporter: owner=user, ) for book in shelf["books"]: - collection.append_item( - book["book"], metadata={"note": book["review"]} - ) + collection.append_item(book["book"], note=book["review"]) total += 1 collection.save() msg.success(user, f'成功从Goodreads导入包含{total}本书的收藏单{shelf["title"]}。') diff --git a/journal/models.py b/journal/models.py index b0645ab1..d62afe13 100644 --- a/journal/models.py +++ b/journal/models.py @@ -361,6 +361,10 @@ class List(Piece): return self.members.filter(item=item).first() def append_item(self, item, **params): + """ + named metadata fields should be specified directly, not in metadata dict! + e.g. collection.append_item(item, note="abc") works, but collection.append_item(item, metadata={"note":"abc"}) doesn't + """ if item is None or self.get_member_for_item(item): return None else: diff --git a/journal/templates/list_item_base.html b/journal/templates/list_item_base.html index 336a6da3..b326eb13 100644 --- a/journal/templates/list_item_base.html +++ b/journal/templates/list_item_base.html @@ -128,7 +128,7 @@
  • - {{ collection_member.note }} + {% if collection_member.note %} {{ collection_member.note }} {% endif %} {% if collection_edit %} {% endif %} diff --git a/journal/tests.py b/journal/tests.py index 31e55c2f..39c74649 100644 --- a/journal/tests.py +++ b/journal/tests.py @@ -18,7 +18,7 @@ class CollectionTest(TestCase): member1 = collection.append_item(self.book1) member1.note = "my notes" member1.save() - collection.append_item(self.book2) + collection.append_item(self.book2, note="test") self.assertEqual(list(collection.ordered_items), [self.book1, self.book2]) collection.move_up_item(self.book1) self.assertEqual(list(collection.ordered_items), [self.book1, self.book2]) @@ -26,6 +26,8 @@ class CollectionTest(TestCase): self.assertEqual(list(collection.ordered_items), [self.book2, self.book1]) member1 = collection.get_member_for_item(self.book1) self.assertEqual(member1.note, "my notes") + member2 = collection.get_member_for_item(self.book2) + self.assertEqual(member2.note, "test") class ShelfTest(TestCase): diff --git a/journal/views.py b/journal/views.py index 242b32f9..0cc9583b 100644 --- a/journal/views.py +++ b/journal/views.py @@ -206,7 +206,7 @@ def collection_append_item(request, collection_uuid): url = request.POST.get("url") note = request.POST.get("note") item = Item.get_by_url(url) - collection.append_item(item, metadata={"note": note}) + collection.append_item(item, note=note) collection.save() return collection_retrieve_items(request, collection_uuid, True) diff --git a/legacy/management/commands/migrate_journal.py b/legacy/management/commands/migrate_journal.py index 181dde0c..603c57d0 100644 --- a/legacy/management/commands/migrate_journal.py +++ b/legacy/management/commands/migrate_journal.py @@ -155,7 +155,7 @@ class Command(BaseCommand): if old_id: item_link = LinkModel.objects.get(old_id=old_id) item = Item.objects.get(uid=item_link.new_uid) - c.append_item(item, metadata={"note": citem.comment}) + c.append_item(item, note=citem.comment) else: print(f"{c.owner} {c.id} {c.title} {citem.item} were skipped") CollectionLink.objects.create(old_id=entity.id, new_uid=c.uid)