From 17885b005c75429ec0885642bae8f472183b4593 Mon Sep 17 00:00:00 2001 From: pika Date: Thu, 17 Apr 2025 11:27:48 +0200 Subject: [PATCH] working preview.. for view --- app/routes.py | 40 +++ app/templates/category.html | 285 ++++++++----------- app/templates/category_documents.html | 379 ++++++++++++++++++++++++++ app/templates/document_view.html | 189 ++++++++----- 4 files changed, 652 insertions(+), 241 deletions(-) create mode 100644 app/templates/category_documents.html diff --git a/app/routes.py b/app/routes.py index c5ea0cc..c05f308 100644 --- a/app/routes.py +++ b/app/routes.py @@ -62,6 +62,39 @@ def view_category(category_id): category = Category.query.filter_by(id=category_id, user_id=current_user.id).first_or_404() return render_template('category.html', category=category) +@main.route('/category//all_documents') +@login_required +def category_all_documents(category_id): + """View all documents in a category, including those in subcategories""" + category = Category.query.filter_by(id=category_id, user_id=current_user.id).first_or_404() + + # Get all documents from this category + documents = [] + + # Add documents from the current category + for doc in category.documents: + documents.append(doc) + + # Helper function to recursively collect documents from subcategories + def collect_documents(cat): + docs = [] + for doc in cat.documents: + docs.append(doc) + + for child in cat.children: + docs.extend(collect_documents(child)) + + return docs + + # Collect documents from all subcategories + for subcategory in category.children: + documents.extend(collect_documents(subcategory)) + + # Sort by updated_date, with most recent first + documents.sort(key=lambda x: x.updated_date, reverse=True) + + return render_template('category_documents.html', category=category, documents=documents) + @main.route('/document/', methods=['GET']) @login_required def view_document(doc_id): @@ -198,6 +231,13 @@ def delete_document(doc_id): db.session.commit() return jsonify({'success': True}) +@main.route('/api/document/', methods=['GET']) +@login_required +def get_document(doc_id): + """Get a document by ID""" + document = Document.query.filter_by(id=doc_id, user_id=current_user.id).first_or_404() + return jsonify(document.to_dict()) + @main.route('/api/document/', methods=['PATCH']) @login_required def update_document(doc_id): diff --git a/app/templates/category.html b/app/templates/category.html index 088ee73..7be7bdd 100644 --- a/app/templates/category.html +++ b/app/templates/category.html @@ -13,9 +13,12 @@ New Subcategory - + + + All Documents + {% endblock %} {% block content %} @@ -85,14 +88,14 @@ {% endfor %} - @@ -102,12 +105,25 @@

Documents

- - - + + +
+
+ + +
+ + + +
-
+ +
{% if category.documents.count() > 0 %} {% for doc in category.documents %}
@@ -164,80 +180,59 @@
{% endif %}
-
-
- - -