- Adding functionality for listing and editing assets
- Started adding functionality for creating a 'full_documents' list view.
This commit is contained in:
@@ -18,16 +18,16 @@ from common.utils.document_utils import create_document_stack, start_embedding_t
|
||||
edit_document, \
|
||||
edit_document_version, refresh_document, clean_url, is_file_type_supported_by_catalog
|
||||
from common.utils.dynamic_field_utils import create_default_config_from_type_config
|
||||
from common.utils.eveai_exceptions import EveAIInvalidLanguageException, EveAIUnsupportedFileType, \
|
||||
EveAIDoubleURLException, EveAIException
|
||||
from common.utils.eveai_exceptions import EveAIException
|
||||
from .document_forms import AddDocumentForm, AddURLForm, EditDocumentForm, EditDocumentVersionForm, \
|
||||
CatalogForm, EditCatalogForm, RetrieverForm, EditRetrieverForm, ProcessorForm, EditProcessorForm
|
||||
from common.utils.middleware import mw_before_request
|
||||
from common.utils.celery_utils import current_celery
|
||||
from common.utils.nginx_utils import prefixed_url_for
|
||||
from common.utils.view_assistants import form_validation_failed, prepare_table_for_macro
|
||||
from .document_list_view import DocumentListView
|
||||
from .document_version_list_view import DocumentVersionListView
|
||||
from eveai_app.views.list_views.document_list_view import DocumentListView
|
||||
from eveai_app.views.list_views.document_version_list_view import DocumentVersionListView
|
||||
from eveai_app.views.list_views.full_document_list_view import FullDocumentListView
|
||||
|
||||
document_bp = Blueprint('document_bp', __name__, url_prefix='/document')
|
||||
|
||||
@@ -499,6 +499,18 @@ def documents():
|
||||
return view.get()
|
||||
|
||||
|
||||
@document_bp.route('/full_documents', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def full_documents():
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if not catalog_id:
|
||||
flash('You need to set a Session Catalog before viewing Full Documents', 'warning')
|
||||
return redirect(prefixed_url_for('document_bp.catalogs'))
|
||||
|
||||
view = FullDocumentListView(Document, 'document/full_documents.html', per_page=10)
|
||||
return view.get()
|
||||
|
||||
|
||||
@document_bp.route('/handle_document_selection', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def handle_document_selection():
|
||||
@@ -665,6 +677,59 @@ def handle_document_version_selection():
|
||||
return redirect(prefixed_url_for('document_bp.document_versions', document_id=doc_vers.doc_id))
|
||||
|
||||
|
||||
@document_bp.route('/handle_full_document_selection', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def handle_full_document_selection():
|
||||
selected_row = request.form['selected_row']
|
||||
action = request.form['action']
|
||||
|
||||
try:
|
||||
# Parse the selected row to get document ID (first column) and version ID (fifth column)
|
||||
row_data = ast.literal_eval(selected_row)
|
||||
selected_doc_id = row_data.get('value')
|
||||
|
||||
# We need to retrieve the corresponding row data to get the version ID
|
||||
# This is a bit complex with the current structure, so we'll use a different approach
|
||||
if action in ['edit_document', 'document_versions', 'refresh_document']:
|
||||
# Actions that need document ID
|
||||
match action:
|
||||
case 'edit_document':
|
||||
return redirect(prefixed_url_for('document_bp.edit_document_view', document_id=selected_doc_id))
|
||||
case 'document_versions':
|
||||
return redirect(prefixed_url_for('document_bp.document_versions', document_id=selected_doc_id))
|
||||
case 'refresh_document':
|
||||
refresh_document_view(selected_doc_id)
|
||||
return redirect(prefixed_url_for('document_bp.full_documents'))
|
||||
else:
|
||||
# Actions that need version ID
|
||||
# We need to get the version ID from the selected row in the table
|
||||
# We'll extract it from the form data and the version ID is in the 5th cell (index 4)
|
||||
version_id_cell = int(request.form.get('version_id', 0))
|
||||
|
||||
# If we couldn't get a version ID, try to find the latest version for this document
|
||||
if not version_id_cell:
|
||||
doc_version = DocumentVersion.query.filter_by(doc_id=selected_doc_id).order_by(desc(DocumentVersion.id)).first()
|
||||
if doc_version:
|
||||
version_id_cell = doc_version.id
|
||||
else:
|
||||
flash('No document version found for this document.', 'error')
|
||||
return redirect(prefixed_url_for('document_bp.full_documents'))
|
||||
|
||||
match action:
|
||||
case 'edit_document_version':
|
||||
return redirect(prefixed_url_for('document_bp.edit_document_version_view', document_version_id=version_id_cell))
|
||||
case 'process_document_version':
|
||||
process_version(version_id_cell)
|
||||
return redirect(prefixed_url_for('document_bp.full_documents'))
|
||||
case 'view_document_version_markdown':
|
||||
return redirect(prefixed_url_for('document_bp.view_document_version_markdown', document_version_id=version_id_cell))
|
||||
except (ValueError, AttributeError, KeyError) as e:
|
||||
current_app.logger.error(f"Error processing full document selection: {str(e)}")
|
||||
flash('Invalid selection or action. Please try again.', 'error')
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.full_documents'))
|
||||
|
||||
|
||||
@document_bp.route('/library_operations', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def library_operations():
|
||||
|
||||
Reference in New Issue
Block a user