From 7a2ce8e650b5f611eb065c544da672fbca7ccd50 Mon Sep 17 00:00:00 2001 From: rucki Date: Sun, 30 Aug 2026 19:27:32 +0200 Subject: [PATCH] Add nested collection management --- .../templates/core/_collection_toc_items.html | 11 +++++++++ core/templates/core/collection_detail.html | 2 +- core/templates/core/collection_manage.html | 24 +++++++++---------- core/tests.py | 12 ++++++++++ core/views.py | 14 ++++++----- 5 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 core/templates/core/_collection_toc_items.html diff --git a/core/templates/core/_collection_toc_items.html b/core/templates/core/_collection_toc_items.html new file mode 100644 index 0000000..70e9177 --- /dev/null +++ b/core/templates/core/_collection_toc_items.html @@ -0,0 +1,11 @@ +{% load markdown_extras %} +{% for section in sections %} +
  • + {% if section.item %}{{ section.title|default:section.item.content|markdown_title|truncatechars:90 }}{% else %}{{ section.title|default:section.sub_collection.title|truncatechars:90 }}{% endif %} + {% if section.sub_collection and section.sub_collection.sections.all %} +
      + {% include 'core/_collection_toc_items.html' with sections=section.sub_collection.sections.all %} +
    + {% endif %} +
  • +{% endfor %} diff --git a/core/templates/core/collection_detail.html b/core/templates/core/collection_detail.html index 55db04a..9f98366 100644 --- a/core/templates/core/collection_detail.html +++ b/core/templates/core/collection_detail.html @@ -22,7 +22,7 @@ {% if sections or tag_items %} {% endif %} diff --git a/core/templates/core/collection_manage.html b/core/templates/core/collection_manage.html index 0aee12f..13e2c25 100644 --- a/core/templates/core/collection_manage.html +++ b/core/templates/core/collection_manage.html @@ -2,23 +2,23 @@ {% load i18n markdown_extras %} {% block content %}
    {% trans "Collections are currently available on desktop only." %}
    -
    +
    - ← {% trans "View collection" %} + ← {% trans "View collection" %}

    {{ collection.title }}

    {% if collection.team %}{{ collection.team.name }}{% else %}{{ collection.get_visibility_display }}{% endif %} {% for tag in collection.filter_tags.all %}#{{ tag.name }}{% endfor %}
    - {% if can_edit %}
    {% trans "Collection settings" %}{% if can_delete %}
    {% csrf_token %}
    {% endif %}
    {% endif %} + {% if can_edit %}
    {% trans "Collection settings" %}{% if can_delete %}
    {% csrf_token %}
    {% endif %}
    {% endif %}
    {% if collection.description %}
    {{ collection.description|markdown }}
    {% endif %} {% if sections %} - +
    {% trans "Contents" %}
      {% include 'core/_collection_toc_items.html' with sections=sections %}
    {% endif %} {% if pending_item %} @@ -35,20 +35,20 @@
    {% endif %} -
    +
    {% for section in sections %}

    {% if section.item %}{{ section.title|default:section.item.content|markdown_title|truncatechars:100 }}{% else %}{{ section.title|default:section.sub_collection.title|truncatechars:100 }}{% endif %}

    - +
    {% if section.item %}
    {{ section.item|item_markdown }}
    {% if section.item.comment %}
    {{ section.item.comment|markdown }}
    {% endif %}{% else %}
    {% trans "Nested collection" %}: {{ section.sub_collection.title }}
    {% endif %} {% if can_edit %}
    -
    {% csrf_token %}
    -
    {% csrf_token %}
    -
    {% csrf_token %}
    -
    {% csrf_token %}
    +
    {% csrf_token %}
    +
    {% csrf_token %}
    +
    {% csrf_token %}
    +
    {% csrf_token %}
    {% endif %}
    {% empty %}
    {% trans "This collection has no sections yet." %}
    {% endfor %} @@ -60,11 +60,11 @@

    {% trans "Notes" %}

    - {% for item in candidates %}
    {{ item.content|truncatechars:180 }}
    #{{ item.id }} · {{ item.get_visibility_display }}{% if item.team %} · {{ item.team.name }}{% endif %}
    {% csrf_token %}
    {% empty %}
    {% trans "No matching notes." %}
    {% endfor %} + {% for item in candidates %}
    {{ item.content|truncatechars:180 }}
    #{{ item.id }} · {{ item.get_visibility_display }}{% if item.team %} · {{ item.team.name }}{% endif %}
    {% csrf_token %}
    {% empty %}
    {% trans "No matching notes." %}
    {% endfor %}

    {% trans "Collections" %}

    - {% for candidate in collection_candidates %}
    {{ candidate.title }}
    #{{ candidate.id }} · {{ candidate.get_visibility_display }}{% if candidate.team %} · {{ candidate.team.name }}{% endif %}
    {% csrf_token %}
    {% empty %}
    {% trans "No matching collections." %}
    {% endfor %} + {% for candidate in collection_candidates %}
    {{ candidate.title }}
    #{{ candidate.id }} · {{ candidate.get_visibility_display }}{% if candidate.team %} · {{ candidate.team.name }}{% endif %}
    {% csrf_token %}
    {% empty %}
    {% trans "No matching collections." %}
    {% endfor %}
    {% endif %} diff --git a/core/tests.py b/core/tests.py index 7323c80..f04a054 100644 --- a/core/tests.py +++ b/core/tests.py @@ -337,10 +337,22 @@ class CollectionTests(TestCase): CollectionSection.objects.create(collection=collection, item=note, position=0) manage_url = reverse('collection_manage', args=[collection.id]) response = self.client.get(manage_url) + self.assertContains(response, 'id="collection-manage"') + self.assertContains(response, 'hx-boost="true"') + self.assertContains(response, 'hx-swap="outerHTML show:none"') self.assertContains(response, f'{reverse("item_editor", args=[note.id])}?next={manage_url}') self.assertContains(response, '>Section## Section