fix collection note error

This commit is contained in:
Your Name 2023-01-08 22:10:48 -05:00
parent d4dd40ccac
commit afd058f640
8 changed files with 17 additions and 7 deletions

View file

@ -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(

View file

@ -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)

View file

@ -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"]}')

View file

@ -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:

View file

@ -128,7 +128,7 @@
<li class="entity-marks__mark">
<p class="entity-marks__mark-content" hx-target="this" hx-swap="innerHTML">
{{ collection_member.note }}
{% if collection_member.note %} {{ collection_member.note }} {% endif %}
{% if collection_edit %}
<a class="action-icon" hx-get="{% url 'journal:collection_update_item_note' collection.uuid item.uuid %}"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M19,20H5a1,1,0,0,0,0,2H19a1,1,0,0,0,0-2Z"/><path d="M5,18h.09l4.17-.38a2,2,0,0,0,1.21-.57l9-9a1.92,1.92,0,0,0-.07-2.71h0L16.66,2.6A2,2,0,0,0,14,2.53l-9,9a2,2,0,0,0-.57,1.21L4,16.91a1,1,0,0,0,.29.8A1,1,0,0,0,5,18ZM15.27,4,18,6.73,16,8.68,13.32,6Zm-8.9,8.91L12,7.32l2.7,2.7-5.6,5.6-3,.28Z"/></g></svg></a>
{% endif %}

View file

@ -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):

View file

@ -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)

View file

@ -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)