wip
This commit is contained in:
parent
17885b005c
commit
f5c8e9ee23
4 changed files with 756 additions and 44 deletions
|
@ -296,28 +296,49 @@ def delete_category(category_id):
|
|||
if category.is_root:
|
||||
return jsonify({'error': 'Cannot delete root category'}), 400
|
||||
|
||||
# Get target category for documents if specified
|
||||
new_category_id = request.args.get('new_category_id')
|
||||
if new_category_id:
|
||||
new_category = Category.query.filter_by(id=new_category_id, user_id=current_user.id).first()
|
||||
if new_category:
|
||||
# Reassign documents
|
||||
for doc in category.documents:
|
||||
doc.category_id = new_category.id
|
||||
else:
|
||||
# Move documents to no category
|
||||
# Check if we should preserve contents
|
||||
preserve_contents = request.args.get('preserve_contents', 'false').lower() == 'true'
|
||||
|
||||
# Find parent category or root
|
||||
parent_category = None
|
||||
if category.parent_id:
|
||||
parent_category = Category.query.filter_by(id=category.parent_id, user_id=current_user.id).first()
|
||||
|
||||
if not parent_category:
|
||||
# If no parent or parent not found, use root category
|
||||
parent_category = Category.query.filter_by(user_id=current_user.id, is_root=True).first()
|
||||
|
||||
if preserve_contents:
|
||||
# Move documents to parent category
|
||||
for doc in category.documents:
|
||||
doc.category_id = None
|
||||
|
||||
# Also handle child categories
|
||||
for child in category.children:
|
||||
if new_category_id:
|
||||
child.parent_id = new_category_id
|
||||
else:
|
||||
child.parent_id = None
|
||||
doc.category_id = parent_category.id
|
||||
|
||||
# Move child categories to parent
|
||||
for child in category.children:
|
||||
child.parent_id = parent_category.id
|
||||
else:
|
||||
# Delete all documents in this category
|
||||
for doc in category.documents:
|
||||
db.session.delete(doc)
|
||||
|
||||
# Recursively delete subcategories and their documents
|
||||
def delete_subcategories(parent):
|
||||
for child in parent.children:
|
||||
# Delete all documents in this subcategory
|
||||
for doc in child.documents:
|
||||
db.session.delete(doc)
|
||||
# Recursively delete subcategories
|
||||
delete_subcategories(child)
|
||||
# Delete the subcategory itself
|
||||
db.session.delete(child)
|
||||
|
||||
# Start recursive deletion
|
||||
delete_subcategories(category)
|
||||
|
||||
# Delete the category itself
|
||||
db.session.delete(category)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
@main.route('/api/search', methods=['GET'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue