hotfix: collection.active_children

This commit is contained in:
SvyatoslavArtymovych 2023-06-01 15:59:44 +03:00
parent a4797e5ddb
commit 4cf5e2a2a2
6 changed files with 16 additions and 12 deletions

View File

@ -37,6 +37,10 @@ class Collection(BaseModel):
def active_sections(self): def active_sections(self):
return [section for section in self.sections if not section.is_deleted] return [section for section in self.sections if not section.is_deleted]
@property
def active_children(self):
return [child for child in self.children if not child.is_deleted]
@property @property
def book_id(self): def book_id(self):
return self.version.book_id return self.version.book_id

View File

@ -81,7 +81,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if access_to_create_section %} {% if access_to_create_section %}
{% if collection.children|length ==0 or collection.children|length ==0 and collection.is_leaf %} {% if collection.active_children|length ==0 or collection.active_children|length ==0 and collection.is_leaf %}
<li> <li>
<button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="_" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">New Section</button> <button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="_" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">New Section</button>
</li> </li>
@ -155,7 +155,7 @@
<p class=" text-sm mb-3">{% if book.about==None %}About text{% else %}{{book.about}}{% endif %}</p> <p class=" text-sm mb-3">{% if book.about==None %}About text{% else %}{{book.about}}{% endif %}</p>
{% for collection in book.versions[-1].children_collections if not collection.is_root and not collection.is_deleted %} {% for collection in book.versions[-1].children_collections if not collection.is_root and not collection.is_deleted %}
<p class="my-3 underline" id="collection-{{collection.label}}">#{{collection.label}}</p> <p class="my-3 underline" id="collection-{{collection.label}}">#{{collection.label}}</p>
{% if not collection.is_leaf and not collection.children %} {% if not collection.is_leaf and not collection.active_children %}
<p class="ml-3 my-3 italic text-sm">Collection is empty</p> <p class="ml-3 my-3 italic text-sm">Collection is empty</p>
{% endif %} {% endif %}
{{recursive_render("book/components/sub_collection_preview_content.html",collection,book)|safe}} {{recursive_render("book/components/sub_collection_preview_content.html",collection,book)|safe}}

View File

@ -1,14 +1,14 @@
{% if not collection.is_leaf %} {% if not collection.is_leaf %}
<!-- if collection has sub_collection make for loop for it --> <!-- if collection has sub_collection make for loop for it -->
{% for sub_collection in collection.children if not sub_collection.is_deleted%} {% for sub_collection in collection.active_children if not sub_collection.is_deleted%}
<p class="my-3" id="collection-{{sub_collection.label}}"> <p class="my-3" id="collection-{{sub_collection.label}}">
##{{sub_collection.label}} ##{{sub_collection.label}}
</p> </p>
{% if not sub_collection.active_sections and not sub_collection.children %} {% if not sub_collection.active_sections and not sub_collection.active_children %}
<p class="ml-3 my-3 italic text-sm">This sub collection is empty</p> <p class="ml-3 my-3 italic text-sm">This sub collection is empty</p>
{% endif %} {% endif %}
<!-- prettier-ignore --> <!-- prettier-ignore -->
{% if sub_collection.children %} {% if sub_collection.active_children %}
{{recursive_render("book/components/sub_collection_preview_content.html",sub_collection,book)|safe}} {{recursive_render("book/components/sub_collection_preview_content.html",sub_collection,book)|safe}}
{% else %} {% else %}
<!-- prettier-ignore --> <!-- prettier-ignore -->

View File

@ -3,7 +3,7 @@
<!-- if collection has sub_collection make for loop for it --> <!-- if collection has sub_collection make for loop for it -->
<!-- Nested accordion --> <!-- Nested accordion -->
<!-- prettier-ignore --> <!-- prettier-ignore -->
{% for sub_collection in collection.children if not sub_collection.is_deleted%} {% for sub_collection in collection.active_children if not sub_collection.is_deleted%}
<div id="accordion-nested-collapse" data-accordion="open"> <div id="accordion-nested-collapse" data-accordion="open">
<!-- prettier-ignore --> <!-- prettier-ignore -->
<div class="flex items-center justify-start w-full font-medium text-left text-gray-500 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-800 dark:text-gray-400"> <div class="flex items-center justify-start w-full font-medium text-left text-gray-500 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-800 dark:text-gray-400">
@ -38,11 +38,11 @@
{% if access_to_create_collections or access_to_update_collections or access_to_create_section %} {% if access_to_create_collections or access_to_update_collections or access_to_create_section %}
<ul class="py-2 text-sm text-gray-700 dark:text-gray-200"> <ul class="py-2 text-sm text-gray-700 dark:text-gray-200">
{% if access_to_create_section and sub_collection.is_leaf and not sub_collection.children %} {% if access_to_create_section and sub_collection.is_leaf and not sub_collection.active_children %}
<li> <li>
<button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Section </button> <button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Section </button>
</li> </li>
{% elif not sub_collection.is_leaf and not sub_collection.children %} {% elif not sub_collection.is_leaf and not sub_collection.active_children %}
{% if access_to_create_section %} {% if access_to_create_section %}
<li> <li>
<button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Section </button> <button type="button" id="callAddSectionModal" data-modal-target="add-section-modal" data-modal-toggle="add-section-modal" data-collection-id="{{collection.id}}" data-sub-collection-id="{{sub_collection.id}}" class="w-full block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"> New Section </button>
@ -92,7 +92,7 @@
</div> </div>
<!-- prettier-ignore --> <!-- prettier-ignore -->
<div id="accordion-nested-collapse-body-{{sub_collection.parent.id}}-{{sub_collection.id}}" class="hidden" aria-labelledby="accordion-nested-collapse-heading-{{sub_collection.id}}"> <div id="accordion-nested-collapse-body-{{sub_collection.parent.id}}-{{sub_collection.id}}" class="hidden" aria-labelledby="accordion-nested-collapse-heading-{{sub_collection.id}}">
{% if sub_collection.children %} {% if sub_collection.active_children %}
{{recursive_render("book/components/sub_collection_tab_content.html",sub_collection,book)|safe}} {{recursive_render("book/components/sub_collection_tab_content.html",sub_collection,book)|safe}}
{% else %} {% else %}
<div class="ml-6"> <div class="ml-6">

View File

@ -34,7 +34,7 @@
<span class="text-center dark:text-gray-300">{{ collection.label }}</span> <span class="text-center dark:text-gray-300">{{ collection.label }}</span>
</div> </div>
{% for sub_collection in collection.children %} {% for sub_collection in collection.active_children %}
<ul class="ml-4"> <ul class="ml-4">
<li> <li>
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">

View File

@ -188,8 +188,8 @@ def collection_delete(book_id: int, collection_id: int):
collection: m.Collection = db.session.get(m.Collection, collection_id) collection: m.Collection = db.session.get(m.Collection, collection_id)
collection.is_deleted = True collection.is_deleted = True
if collection.children: if collection.active_children:
for child in collection.children: for child in collection.active_children:
child: m.Collection child: m.Collection
delete_nested_collection_entities(child) delete_nested_collection_entities(child)
log(log.INFO, "Delete subcollection [%s]", collection.id) log(log.INFO, "Delete subcollection [%s]", collection.id)