abc
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, render_template, request, jsonify
|
||||
from flask import Blueprint, render_template, request, jsonify, make_response
|
||||
from app import db
|
||||
from app.models import Folder, User
|
||||
import uuid
|
||||
@@ -9,6 +9,13 @@ main = Blueprint('main', __name__)
|
||||
# For prototype, use a fixed user ID
|
||||
MOCK_USER_ID = '123e4567-e89b-12d3-a456-426614174000'
|
||||
|
||||
@main.route('/api/folders/new', methods=['GET'])
|
||||
def new_folder_modal():
|
||||
# Return the add folder modal
|
||||
response = make_response(render_template('partials/folder_modal.html'))
|
||||
response.headers['HX-Trigger'] = 'open-modal'
|
||||
return response
|
||||
|
||||
@main.route('/')
|
||||
def index():
|
||||
# Ensure the mock user exists
|
||||
@@ -50,7 +57,10 @@ def add_folder():
|
||||
folders = Folder.query.filter_by(user_id=MOCK_USER_ID).all()
|
||||
|
||||
# Return the updated folders list HTML
|
||||
return render_template('partials/folders_list.html', folders=folders)
|
||||
|
||||
response = make_response(render_template('partials/folders_list.html', folders=folders))
|
||||
response.headers['HX-Trigger'] = 'close-modal'
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Print unhandled exceptions to the console as required
|
||||
@@ -120,8 +130,9 @@ def update_folder(folder_id):
|
||||
# Get updated list of folders
|
||||
folders = Folder.query.filter_by(user_id=MOCK_USER_ID).all()
|
||||
|
||||
# Return the updated folders list HTML
|
||||
return render_template('partials/folders_list.html', folders=folders)
|
||||
response = make_response(render_template('partials/folders_list.html', folders=folders))
|
||||
response.headers['HX-Trigger'] = 'close-modal'
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Print unhandled exceptions to the console as required
|
||||
@@ -151,4 +162,24 @@ def get_folder(folder_id):
|
||||
except Exception as e:
|
||||
# Print unhandled exceptions to the console as required
|
||||
logging.exception("Error getting folder: %s", e)
|
||||
return jsonify({'error': 'Error retrieving folder'}), 500
|
||||
return jsonify({'error': 'Error retrieving folder'}), 500
|
||||
|
||||
|
||||
@main.route('/api/folders/<folder_id>/edit', methods=['GET'])
|
||||
def edit_folder_modal(folder_id):
|
||||
try:
|
||||
# Find the folder by ID
|
||||
folder = Folder.query.filter_by(id=folder_id, user_id=MOCK_USER_ID).first()
|
||||
|
||||
if not folder:
|
||||
return jsonify({'error': 'Folder not found'}), 404
|
||||
|
||||
# Return the edit folder modal with folder data
|
||||
response = make_response(render_template('partials/folder_modal.html', folder=folder))
|
||||
response.headers['HX-Trigger'] = 'open-modal'
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Print unhandled exceptions to the console as required
|
||||
logging.exception("Error getting folder for edit: %s", e)
|
||||
return jsonify({'error': 'Error retrieving folder'}), 500
|
||||
|
||||
Reference in New Issue
Block a user