diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 37864ef3..87a116e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: rev: v0.9.2 hooks: - id: ruff - args: [ --fix ] + args: [ "--fix" ] - id: ruff-format # - repo: https://github.com/pycqa/isort diff --git a/journal/apis/note.py b/journal/apis/note.py index 7efa1b84..b5c92f32 100644 --- a/journal/apis/note.py +++ b/journal/apis/note.py @@ -78,11 +78,11 @@ def add_note_for_item(request, item_uuid: str, n_in: NoteInSchema): response={200: NoteSchema, 401: Result, 403: Result, 404: Result}, tags=["note"], ) -def update_note(request, tag_uuid: str, n_in: NoteInSchema): +def update_note(request, note_uuid: str, n_in: NoteInSchema): """ Update a note. """ - note = Note.get_by_url_and_owner(tag_uuid, request.user.identity.pk) + note = Note.get_by_url_and_owner(note_uuid, request.user.identity.pk) if not note: return NOT_FOUND note.title = n_in.title @@ -101,11 +101,11 @@ def update_note(request, tag_uuid: str, n_in: NoteInSchema): response={200: Result, 401: Result, 403: Result, 404: Result}, tags=["note"], ) -def delete_note(request, tag_uuid: str): +def delete_note(request, note_uuid: str): """ Delete a note. """ - note = Note.get_by_url_and_owner(tag_uuid, request.user.identity.pk) + note = Note.get_by_url_and_owner(note_uuid, request.user.identity.pk) if not note: return NOT_FOUND note.delete() diff --git a/journal/models/itemlist.py b/journal/models/itemlist.py index 1f2654dc..9d697ae4 100644 --- a/journal/models/itemlist.py +++ b/journal/models/itemlist.py @@ -40,7 +40,7 @@ class List(Piece): @property def ordered_members(self): - return self.members.all().order_by("position") + return self.members.all().order_by("position", "item_id") @property def ordered_items(self): @@ -104,7 +104,7 @@ class List(Piece): i = ordered_member_ids.index(m.pk) if m.position != i + 1: m.position = i + 1 - m.save() + m.save(update_fields=["position"]) except ValueError: pass diff --git a/journal/templates/_list_item.html b/journal/templates/_list_item.html index 6bf8b373..27a2acf3 100644 --- a/journal/templates/_list_item.html +++ b/journal/templates/_list_item.html @@ -86,7 +86,7 @@ {% endif %} {% endif %} {% if collection_member %} -

+

{% if collection_edit %} {% endif %} {% if collection_member.note %}{{ collection_member.note }}{% endif %} -

+   +
{% endif %} {% endif %} diff --git a/journal/templates/collection.html b/journal/templates/collection.html index 36abc696..5145836e 100644 --- a/journal/templates/collection.html +++ b/journal/templates/collection.html @@ -111,7 +111,8 @@ {% endif %} {% endcomment %}
-
diff --git a/journal/templates/collection_edit.html b/journal/templates/collection_edit.html index c67051e8..a6b9fed1 100644 --- a/journal/templates/collection_edit.html +++ b/journal/templates/collection_edit.html @@ -43,9 +43,57 @@
{% trans "Items" %} -
+
+
+
+
+ {% csrf_token %} + + + +
+ +
+ {% csrf_token %} + + +
{% endif %}
diff --git a/journal/templates/collection_items.html b/journal/templates/collection_items.html index aa9d9fa2..f811eaf5 100644 --- a/journal/templates/collection_items.html +++ b/journal/templates/collection_items.html @@ -1,59 +1,18 @@ {% load thumb %} {% load i18n %} {% load l10n %} -
- {% for member in collection.ordered_members %} - {% include '_list_item.html' with item=member.item mark=None collection_member=member %} - {% empty %} +{% for member in members %} + {% include '_list_item.html' with item=member.item mark=None collection_member=member %} + {% if forloop.last %} +
+ {{ member.position }} +
+ {% endif %} +{% empty %} + {% if not request.GET.last_pos %} {% trans "nothing so far." %} - {% endfor %} -
-{% if collection_edit %} -
- {% csrf_token %} - - - -
- -
- {% csrf_token %} - - -
-{% endif %} + {% endif %} +{% endfor %} {% if msg %}{% endif %} diff --git a/journal/views/collection.py b/journal/views/collection.py index edd50a42..97921006 100644 --- a/journal/views/collection.py +++ b/journal/views/collection.py @@ -194,13 +194,18 @@ def collection_retrieve_items( collection = get_object_or_404(Collection, uid=get_uuid_or_404(collection_uuid)) if not collection.is_visible_to(request.user): raise PermissionDenied(_("Insufficient permission")) - form = CollectionForm(instance=collection) + members = collection.ordered_members + last_pos = int_(request.GET.get("last_pos")) + print("p", last_pos) + if last_pos: + last_member = int_(request.GET.get("last_member")) + members = members.filter(position__gte=last_pos).exclude(id=last_member) return render( request, "collection_items.html", { "collection": collection, - "form": form, + "members": members[:20], "collection_edit": edit or request.GET.get("edit"), "msg": msg, },