improvements
This commit is contained in:
@@ -15,14 +15,8 @@ def index():
|
||||
# Get folders for the current authenticated user
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
|
||||
# Separate folders by type
|
||||
tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy']
|
||||
destination_folders = [folder for folder in folders if folder.folder_type == 'destination']
|
||||
|
||||
return render_template('index.html',
|
||||
folders=folders,
|
||||
tidy_folders=tidy_folders,
|
||||
destination_folders=destination_folders)
|
||||
folders=folders)
|
||||
|
||||
@main.route('/api/folders/new', methods=['GET'])
|
||||
@login_required
|
||||
@@ -82,16 +76,9 @@ def add_folder():
|
||||
# Get updated list of folders for the current user
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
|
||||
# Get updated lists of folders by type
|
||||
tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy']
|
||||
destination_folders = [folder for folder in folders if folder.folder_type == 'destination']
|
||||
|
||||
# Return both sections
|
||||
tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders)
|
||||
destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders)
|
||||
|
||||
response = make_response(tidy_section + destination_section)
|
||||
response = make_response(render_template('partials/folders_list.html', folders=folders))
|
||||
response.headers['HX-Trigger'] = 'close-modal'
|
||||
response.headers["HX-Target"] = 'folder-list'
|
||||
response.status_code = 201
|
||||
return response
|
||||
|
||||
@@ -102,13 +89,6 @@ def add_folder():
|
||||
# Return error in modal
|
||||
errors = {'general': 'An unexpected error occurred. Please try again.'}
|
||||
# Get updated lists of folders by type for error fallback
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy']
|
||||
destination_folders = [folder for folder in folders if folder.folder_type == 'destination']
|
||||
|
||||
# Return both sections as fallback
|
||||
tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders)
|
||||
destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders)
|
||||
|
||||
response = make_response(render_template('partials/folder_modal.html', errors=errors, name=name, rule_text=rule_text, priority=priority))
|
||||
response.headers['HX-Retarget'] = '#folder-modal'
|
||||
@@ -134,18 +114,8 @@ def delete_folder(folder_id):
|
||||
db.session.delete(folder)
|
||||
db.session.commit()
|
||||
|
||||
# Get updated list of folders for the current user
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
|
||||
# Get updated lists of folders by type
|
||||
tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy']
|
||||
destination_folders = [folder for folder in folders if folder.folder_type == 'destination']
|
||||
|
||||
# Return both sections
|
||||
tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders)
|
||||
destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders)
|
||||
|
||||
return tidy_section + destination_section
|
||||
return render_template('partials/folders_list.html', folders=folders)
|
||||
|
||||
except Exception as e:
|
||||
# Print unhandled exceptions to the console as required
|
||||
@@ -153,14 +123,8 @@ def delete_folder(folder_id):
|
||||
db.session.rollback()
|
||||
# Return the folders list unchanged
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy']
|
||||
destination_folders = [folder for folder in folders if folder.folder_type == 'destination']
|
||||
|
||||
# Return both sections
|
||||
tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders)
|
||||
destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders)
|
||||
|
||||
return tidy_section + destination_section
|
||||
return render_template('partials/folders_list.html', folders=folders)
|
||||
|
||||
@main.route('/api/folders/<folder_id>/toggle', methods=['PUT'])
|
||||
@login_required
|
||||
@@ -245,15 +209,6 @@ def update_folder(folder_id):
|
||||
|
||||
# If there are validation errors, return the modal with errors
|
||||
if errors:
|
||||
# Get updated lists of folders by type for error fallback
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy']
|
||||
destination_folders = [folder for folder in folders if folder.folder_type == 'destination']
|
||||
|
||||
# Return both sections as fallback
|
||||
tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders)
|
||||
destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders)
|
||||
|
||||
response = make_response(render_template('partials/folder_modal.html', folder=folder, errors=errors, name=name, rule_text=rule_text, priority=priority))
|
||||
response.headers['HX-Retarget'] = '#folder-modal'
|
||||
response.headers['HX-Reswap'] = 'outerHTML'
|
||||
@@ -275,15 +230,9 @@ def update_folder(folder_id):
|
||||
# Get updated list of folders for the current user
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
|
||||
# Get updated lists of folders by type
|
||||
tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy']
|
||||
destination_folders = [folder for folder in folders if folder.folder_type == 'destination']
|
||||
|
||||
# Return both sections
|
||||
tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders)
|
||||
destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders)
|
||||
|
||||
response = make_response(tidy_section + destination_section)
|
||||
section = render_template('partials/folders_list.html', folders=folders)
|
||||
response = make_response(section)
|
||||
response.headers['HX-Trigger'] = 'close-modal'
|
||||
return response
|
||||
|
||||
@@ -422,7 +371,6 @@ def sync_imap_folders():
|
||||
|
||||
# Process each unique folder
|
||||
synced_count = 0
|
||||
print("HELLOOO")
|
||||
processed_emails_service = ProcessedEmailsService(current_user)
|
||||
|
||||
for imap_folder in unique_folders:
|
||||
@@ -474,14 +422,8 @@ def sync_imap_folders():
|
||||
|
||||
# Get updated list of folders
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy']
|
||||
destination_folders = [folder for folder in folders if folder.folder_type == 'destination']
|
||||
|
||||
# Return both sections
|
||||
tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders)
|
||||
destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders)
|
||||
|
||||
return tidy_section + destination_section
|
||||
return render_template('partials/folders_list.html', folders=folders)
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("Error syncing IMAP folders: %s", e)
|
||||
@@ -511,11 +453,14 @@ def get_folders():
|
||||
# Get all folders
|
||||
folders = Folder.query.filter_by(user_id=current_user.id).all()
|
||||
|
||||
# Check if we need to return a specific section
|
||||
if folder_type == 'tidy':
|
||||
return render_template('partials/folders_to_tidy_section.html', tidy_folders=folders)
|
||||
response = make_response(render_template('partials/folders_to_tidy_section.html', folders=folders))
|
||||
response["HX-Retarget"] = "#folders-to-tidy"
|
||||
return response
|
||||
elif folder_type == 'destination':
|
||||
return render_template('partials/destination_folders_section.html', destination_folders=folders)
|
||||
response = make_response(render_template('partials/destination_folders_section.html', folders=folders))
|
||||
response["HX-Retarget"] = "#destination-folders"
|
||||
return response
|
||||
else:
|
||||
return render_template('partials/folders_list.html', folders=folders)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user