open-law/app/controllers/delete_nested_book_entities.py

72 lines
2.3 KiB
Python
Raw Normal View History

2023-05-15 14:55:36 +00:00
from app import models as m
from app.logger import log
2023-05-15 15:09:03 +00:00
def delete_nested_book_entities(book: m.Book):
for version in book.versions:
version: m.BookVersion
version.is_deleted = True
log(log.INFO, "Delete version [%s]", version.id)
version.save(False)
delete_nested_version_entities(version)
def delete_nested_version_entities(book_version: m.BookVersion):
root_collection: m.Collection = book_version.root_collection
root_collection.is_deleted = True
log(log.INFO, "Delete root collection [%s]", root_collection.id)
root_collection.save(False)
for collection in root_collection.children:
collection: m.Collection
collection.is_deleted = True
log(log.INFO, "Delete collection [%s]", collection.id)
collection.save(False)
delete_nested_collection_entities(collection)
2023-05-15 14:55:36 +00:00
def delete_nested_collection_entities(collection: m.Collection):
2023-05-26 14:12:57 +00:00
for sub_collection in collection.children:
2023-06-13 07:20:21 +00:00
collection.is_deleted = True
collection.save(False)
sub_collection.is_deleted = True
sub_collection.save(False)
2023-05-26 14:12:57 +00:00
delete_nested_collection_entities(sub_collection)
2023-05-15 14:55:36 +00:00
for section in collection.sections:
section: m.Section
section.is_deleted = True
log(log.INFO, "Delete section [%s]", section.id)
section.save(False)
delete_nested_section_entities(section)
def delete_nested_section_entities(section: m.Section):
for interpretation in section.interpretations:
interpretation: m.Interpretation
interpretation.is_deleted = True
log(log.INFO, "Delete interpretation [%s]", interpretation.id)
interpretation.save(False)
delete_nested_interpretation_entities(interpretation)
def delete_nested_interpretation_entities(interpretation: m.Interpretation):
for comment in interpretation.comments:
comment: m.Comment
comment.is_deleted = True
log(log.INFO, "Delete comment [%s]", comment.id)
comment.save(False)
delete_nested_comment_entities(comment)
def delete_nested_comment_entities(comment: m.Comment):
for child in comment.children:
child: m.Comment
child.is_deleted = True
log(log.INFO, "Delete sub comment [%s]", comment.id)
child.save(False)