- eveai_app adapted to handle removal of complex rewrite rules in nginx.conf, which cannot be achieved in Ingress
This commit is contained in:
@@ -74,7 +74,7 @@ def catalog():
|
||||
flash('Catalog successfully added!', 'success')
|
||||
current_app.logger.info(f'Catalog {new_catalog.name} successfully added for tenant {tenant_id}!')
|
||||
# Enable step 2 of creation of catalog - add configuration of the catalog (dependent on type)
|
||||
return redirect(prefixed_url_for('document_bp.catalog', catalog_id=new_catalog.id))
|
||||
return redirect(prefixed_url_for('document_bp.catalog', catalog_id=new_catalog.id, for_redirect=True))
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
flash(f'Failed to add catalog. Error: {e}', 'danger')
|
||||
@@ -97,7 +97,7 @@ def catalogs():
|
||||
def handle_catalog_selection():
|
||||
action = request.form['action']
|
||||
if action == 'create_catalog':
|
||||
return redirect(prefixed_url_for('document_bp.catalog'))
|
||||
return redirect(prefixed_url_for('document_bp.catalog', for_redirect=True))
|
||||
catalog_identification = request.form.get('selected_row')
|
||||
catalog_id = ast.literal_eval(catalog_identification).get('value')
|
||||
catalog = Catalog.query.get_or_404(catalog_id)
|
||||
@@ -108,9 +108,9 @@ def handle_catalog_selection():
|
||||
session['catalog_name'] = catalog.name
|
||||
session['catalog'] = catalog.to_dict()
|
||||
elif action == 'edit_catalog':
|
||||
return redirect(prefixed_url_for('document_bp.edit_catalog', catalog_id=catalog_id))
|
||||
return redirect(prefixed_url_for('document_bp.edit_catalog', catalog_id=catalog_id, for_redirect=True))
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
return redirect(prefixed_url_for('document_bp.catalogs', for_redirect=True))
|
||||
|
||||
|
||||
@document_bp.route('/catalog/<int:catalog_id>', methods=['GET', 'POST'])
|
||||
@@ -136,7 +136,7 @@ def edit_catalog(catalog_id):
|
||||
flash(f'Failed to update catalog. Error: {e}', 'danger')
|
||||
current_app.logger.error(f'Failed to update catalog {catalog_id} for tenant {tenant_id}. Error: {str(e)}')
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
return redirect(prefixed_url_for('document_bp.catalogs', for_redirect=True))
|
||||
else:
|
||||
form_validation_failed(request, form)
|
||||
|
||||
@@ -166,7 +166,7 @@ def processor():
|
||||
flash('Processor successfully added!', 'success')
|
||||
current_app.logger.info(f'Processor {new_processor.name} successfully added for tenant {tenant_id}!')
|
||||
# Enable step 2 of creation of retriever - add configuration of the retriever (dependent on type)
|
||||
return redirect(prefixed_url_for('document_bp.edit_processor', processor_id=new_processor.id))
|
||||
return redirect(prefixed_url_for('document_bp.edit_processor', processor_id=new_processor.id, for_redirect=True))
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
flash(f'Failed to add processor. Error: {e}', 'danger')
|
||||
@@ -215,7 +215,7 @@ def edit_processor(processor_id):
|
||||
current_app.logger.error(f'Failed to update processor {processor_id}. Error: {str(e)}')
|
||||
return render_template('document/edit_processor.html', form=form, processor_id=processor_id)
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.processors'))
|
||||
return redirect(prefixed_url_for('document_bp.processors', for_redirect=True))
|
||||
else:
|
||||
form_validation_failed(request, form)
|
||||
|
||||
@@ -228,7 +228,7 @@ def processors():
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if not catalog_id:
|
||||
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
return redirect(prefixed_url_for('document_bp.catalogs', for_redirect=True))
|
||||
|
||||
# Get configuration and render the list view
|
||||
config = get_processors_list_view(catalog_id)
|
||||
@@ -240,14 +240,14 @@ def processors():
|
||||
def handle_processor_selection():
|
||||
action = request.form['action']
|
||||
if action == 'create_processor':
|
||||
return redirect(prefixed_url_for('document_bp.processor'))
|
||||
return redirect(prefixed_url_for('document_bp.processor', for_redirect=True))
|
||||
processor_identification = request.form.get('selected_row')
|
||||
processor_id = ast.literal_eval(processor_identification).get('value')
|
||||
|
||||
if action == 'edit_processor':
|
||||
return redirect(prefixed_url_for('document_bp.edit_processor', processor_id=processor_id))
|
||||
return redirect(prefixed_url_for('document_bp.edit_processor', processor_id=processor_id, for_redirect=True))
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.processors'))
|
||||
return redirect(prefixed_url_for('document_bp.processors', for_redirect=True))
|
||||
|
||||
|
||||
# Retriever Management ----------------------------------------------------------------------------
|
||||
@@ -272,7 +272,7 @@ def retriever():
|
||||
flash('Retriever successfully added!', 'success')
|
||||
current_app.logger.info(f'Catalog {new_retriever.name} successfully added for tenant {tenant_id}!')
|
||||
# Enable step 2 of creation of retriever - add configuration of the retriever (dependent on type)
|
||||
return redirect(prefixed_url_for('document_bp.edit_retriever', retriever_id=new_retriever.id))
|
||||
return redirect(prefixed_url_for('document_bp.edit_retriever', retriever_id=new_retriever.id, for_redirect=True))
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
flash(f'Failed to add retriever. Error: {e}', 'danger')
|
||||
@@ -315,7 +315,7 @@ def edit_retriever(retriever_id):
|
||||
current_app.logger.error(f'Failed to update retriever {retriever_id}. Error: {str(e)}')
|
||||
return render_template('document/edit_retriever.html', form=form, retriever_id=retriever_id)
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.retrievers'))
|
||||
return redirect(prefixed_url_for('document_bp.retrievers', for_redirect=True))
|
||||
else:
|
||||
form_validation_failed(request, form)
|
||||
|
||||
@@ -328,7 +328,7 @@ def retrievers():
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if not catalog_id:
|
||||
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
return redirect(prefixed_url_for('document_bp.catalogs', for_redirect=True))
|
||||
|
||||
# Get configuration and render the list view
|
||||
config = get_retrievers_list_view(catalog_id)
|
||||
@@ -340,14 +340,14 @@ def retrievers():
|
||||
def handle_retriever_selection():
|
||||
action = request.form['action']
|
||||
if action == 'create_retriever':
|
||||
return redirect(prefixed_url_for('document_bp.retriever'))
|
||||
return redirect(prefixed_url_for('document_bp.retriever', for_redirect=True))
|
||||
retriever_identification = request.form.get('selected_row')
|
||||
retriever_id = ast.literal_eval(retriever_identification).get('value')
|
||||
|
||||
if action == 'edit_retriever':
|
||||
return redirect(prefixed_url_for('document_bp.edit_retriever', retriever_id=retriever_id))
|
||||
return redirect(prefixed_url_for('document_bp.edit_retriever', retriever_id=retriever_id, for_redirect=True))
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.retrievers'))
|
||||
return redirect(prefixed_url_for('document_bp.retrievers', for_redirect=True))
|
||||
|
||||
|
||||
# Document Management -----------------------------------------------------------------------------
|
||||
@@ -358,7 +358,7 @@ def add_document():
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if catalog_id is None:
|
||||
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
return redirect(prefixed_url_for('document_bp.catalogs', for_redirect=True))
|
||||
|
||||
catalog = Catalog.query.get_or_404(catalog_id)
|
||||
if catalog.configuration and len(catalog.configuration) > 0:
|
||||
@@ -392,7 +392,7 @@ def add_document():
|
||||
|
||||
flash(f'Processing on document {new_doc.name}, version {new_doc_vers.id} started. Task ID: {task_id}.',
|
||||
'success')
|
||||
return redirect(prefixed_url_for('document_bp.documents_processing'))
|
||||
return redirect(prefixed_url_for('document_bp.documents_processing', for_redirect=True))
|
||||
|
||||
except EveAIException as e:
|
||||
flash(str(e), 'danger')
|
||||
@@ -411,7 +411,7 @@ def add_url():
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if catalog_id is None:
|
||||
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
return redirect(prefixed_url_for('document_bp.catalogs', for_redirect=True))
|
||||
|
||||
catalog = Catalog.query.get_or_404(catalog_id)
|
||||
if catalog.configuration and len(catalog.configuration) > 0:
|
||||
@@ -451,7 +451,7 @@ def add_url():
|
||||
|
||||
flash(f'Processing on document {new_doc.name}, version {new_doc_vers.id} started. Task ID: {task_id}.',
|
||||
'success')
|
||||
return redirect(prefixed_url_for('document_bp.documents_processing'))
|
||||
return redirect(prefixed_url_for('document_bp.documents_processing', for_redirect=True))
|
||||
|
||||
except EveAIException as e:
|
||||
current_app.logger.error(f"Error adding document: {str(e)}")
|
||||
@@ -472,7 +472,7 @@ def documents():
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if not catalog_id:
|
||||
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
return redirect(prefixed_url_for('document_bp.catalogs', for_redirect=True))
|
||||
|
||||
config = get_documents_list_view(catalog_id)
|
||||
return render_list_view('list_view.html', **config)
|
||||
@@ -484,7 +484,7 @@ def documents_processing():
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if not catalog_id:
|
||||
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
return redirect(prefixed_url_for('document_bp.catalogs', for_redirect=True))
|
||||
|
||||
config = get_documents_processing_list_view(catalog_id)
|
||||
return render_list_view('list_view.html', **config)
|
||||
@@ -502,16 +502,16 @@ def handle_document_selection():
|
||||
doc_id = ast.literal_eval(document_identification).get('value')
|
||||
except (ValueError, AttributeError):
|
||||
flash('Invalid document selection.', 'danger')
|
||||
return redirect(prefixed_url_for('document_bp.documents'))
|
||||
return redirect(prefixed_url_for('document_bp.documents', for_redirect=True))
|
||||
|
||||
action = request.form['action']
|
||||
|
||||
match action:
|
||||
case 'edit_document':
|
||||
return redirect(prefixed_url_for('document_bp.edit_document', document_id=doc_id))
|
||||
return redirect(prefixed_url_for('document_bp.edit_document', document_id=doc_id, for_redirect=True))
|
||||
case 'refresh':
|
||||
refresh_document_view(doc_id)
|
||||
return redirect(prefixed_url_for('document_bp.documents', document_id=doc_id))
|
||||
return redirect(prefixed_url_for('document_bp.documents', document_id=doc_id, for_redirect=True))
|
||||
case 're_process':
|
||||
document = Document.query.get_or_404(doc_id)
|
||||
doc_vers_id = document.latest_version.id
|
||||
@@ -520,14 +520,14 @@ def handle_document_selection():
|
||||
document = Document.query.get_or_404(doc_id)
|
||||
doc_vers_id = document.latest_version.id
|
||||
return redirect(prefixed_url_for('document_bp.view_document_version_markdown',
|
||||
document_version_id=doc_vers_id))
|
||||
document_version_id=doc_vers_id, for_redirect=True))
|
||||
case 'edit_document_version':
|
||||
document = Document.query.get_or_404(doc_id)
|
||||
doc_vers_id = document.latest_version.id
|
||||
return redirect(prefixed_url_for('document_bp.edit_document_version', document_version_id=doc_vers_id))
|
||||
return redirect(prefixed_url_for('document_bp.edit_document_version', document_version_id=doc_vers_id, for_redirect=True))
|
||||
|
||||
# Add more conditions for other actions
|
||||
return redirect(prefixed_url_for('document_bp.documents'))
|
||||
return redirect(prefixed_url_for('document_bp.documents', for_redirect=True))
|
||||
|
||||
|
||||
@document_bp.route('/edit_document/<int:document_id>', methods=['GET', 'POST'])
|
||||
@@ -562,7 +562,7 @@ def edit_document(document_id):
|
||||
)
|
||||
if updated_doc:
|
||||
flash(f'Document {updated_doc.id} updated successfully', 'success')
|
||||
return redirect(prefixed_url_for('document_bp.documents'))
|
||||
return redirect(prefixed_url_for('document_bp.documents', for_redirect=True))
|
||||
else:
|
||||
flash(f'Error updating document: {error}', 'danger')
|
||||
else:
|
||||
@@ -600,7 +600,7 @@ def edit_document_version(document_version_id):
|
||||
)
|
||||
if updated_version:
|
||||
flash(f'Document Version {updated_version.id} updated successfully', 'success')
|
||||
return redirect(prefixed_url_for('document_bp.documents', document_id=updated_version.doc_id))
|
||||
return redirect(prefixed_url_for('document_bp.documents', document_id=updated_version.doc_id, for_redirect=True))
|
||||
else:
|
||||
flash(f'Error updating document version: {error}', 'danger')
|
||||
else:
|
||||
@@ -644,7 +644,7 @@ def view_document_version_markdown(document_version_id):
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Error retrieving markdown for document version {document_version_id}: {str(e)}")
|
||||
flash(f"Error retrieving processed document: {str(e)}", "danger")
|
||||
return redirect(prefixed_url_for('document_bp.document_versions'))
|
||||
return redirect(prefixed_url_for('document_bp.document_versions', for_redirect=True))
|
||||
|
||||
|
||||
# Utilities ---------------------------------------------------------------------------------------
|
||||
@@ -667,7 +667,7 @@ def handle_library_selection():
|
||||
case 'refresh_all_documents':
|
||||
refresh_all_documents()
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.library_operations'))
|
||||
return redirect(prefixed_url_for('document_bp.library_operations', for_redirect=True))
|
||||
|
||||
|
||||
def create_default_rag_library():
|
||||
@@ -675,7 +675,7 @@ def create_default_rag_library():
|
||||
catalogs = Catalog.query.all()
|
||||
if catalogs:
|
||||
flash("Default RAG Library can only be created if no catalogs are defined!", 'danger')
|
||||
return redirect(prefixed_url_for('document_bp.library_operations'))
|
||||
return redirect(prefixed_url_for('document_bp.library_operations', for_redirect=True))
|
||||
|
||||
timestamp = dt.now(tz=tz.utc)
|
||||
try:
|
||||
@@ -749,7 +749,7 @@ def create_default_rag_library():
|
||||
current_app.logger.error(f'Failed to create Default RAG Library'
|
||||
f'for tenant {session['tenant']['id']}. Error: {str(e)}')
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.library_operations'))
|
||||
return redirect(prefixed_url_for('document_bp.library_operations', for_redirect=True))
|
||||
|
||||
|
||||
def refresh_all_documents():
|
||||
@@ -763,7 +763,7 @@ def refresh_document_view(document_id):
|
||||
flash(f'Document refreshed. New version: {new_version.id}. Task ID: {result}', 'success')
|
||||
else:
|
||||
flash(f'Error refreshing document: {result}', 'danger')
|
||||
return redirect(prefixed_url_for('document_bp.documents'))
|
||||
return redirect(prefixed_url_for('document_bp.documents', for_redirect=True))
|
||||
|
||||
|
||||
def re_embed_latest_versions():
|
||||
@@ -785,7 +785,7 @@ def process_version(version_id):
|
||||
|
||||
flash(f'Processing for document version {version_id} retriggered successfully...', 'success')
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.documents'))
|
||||
return redirect(prefixed_url_for('document_bp.documents', for_redirect=True))
|
||||
|
||||
|
||||
def set_logging_information(obj, timestamp):
|
||||
|
||||
Reference in New Issue
Block a user