From 542692751264dd40cade2fd4b801f24c0b9a159c Mon Sep 17 00:00:00 2001 From: mostaf_mansour Date: Mon, 13 Oct 2025 21:38:16 +0300 Subject: [PATCH 1/2] added new search feature --- instance/database.db | Bin 0 -> 16384 bytes website/auth.py | 2 +- website/static/index.js | 17 +++++++++++++++ website/templates/home.html | 40 +++++++++++++++++++++++++++++------- website/views.py | 34 +++++++++++++++++++++++++++--- 5 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 instance/database.db diff --git a/instance/database.db b/instance/database.db new file mode 100644 index 0000000000000000000000000000000000000000..a245f2b27afea5e40dc6b391da2fcc71deabbcc3 GIT binary patch literal 16384 zcmeI(J#W)M7zglk(i9RY7>1}ri@2ePM54tnv7Mw#LvceOOxgC$oeBb_QRykZCGZ#W71Cjam%D}looT@fkT_^j@d9R+TQNacDL1f zNOM_-g^cdkt&OL3t0+rRDV>BleG*-z)7&!Sz%<~K-q|(c(2mvIs#^#2xp_c~11A}` zxow%vMmvrbPllAJWp0|5+1@bsXdFvA=Ss6j!g2QXB>T7}uBmg`ANT)b_S|EG(OLT1 zaq@>O2;TV<=R$)!m;_;O%shUf>9Wam+s)msNsGx{O1aX5)cnF)K_G*%!;gYDqv+kf z$EKm5ocH2Xdvd%_M~~Xg_;HJ0@&$23q74NC5P$##AOHafKmY;|fB*y_0D-?CFuNnn zlg8}jqUQ%8bD77+fj^xXx?(8nui|xrRonLt`$NZ7YQbx!XnHMK?~tVB7tf5{%~1C| z|HJ;i(~*|@c3-o(#%)#Snqo+DS&?~#tJShot|&H>m|m_*x@5Sn>bTs{4MnjPgYgQp z?JCz#a>zyV62$K$+E5?>0SG_<0uX=z1Rwwb2tWV=5V)QKG~LKvx!RC?j=IQnVFWT9H*MS8B3+ zZ!SX?)vWhE`NPBcR;60gl%;escI;31h1RmZn#z#sui backend will show all notes + } else { + // fallback: reload base path without query string + window.location = window.location.pathname; + } + }); + } +}); + function deleteNote(noteId) { fetch("/delete-note", { method: "POST", diff --git a/website/templates/home.html b/website/templates/home.html index 0fc5c1d9..1799d631 100644 --- a/website/templates/home.html +++ b/website/templates/home.html @@ -1,16 +1,42 @@ {% extends "base.html" %} {% block title %}Home{% endblock %} {% block content %}

Notes

-
    - {% for note in user.notes %} -
  • - {{ note.data }} +
    +
    + + + + {% if query %} + Showing results for "{{ query }}" + {% endif %} +
    +
    +
    +
    +
    +
    + {% if notes %} {% for note in notes %} +
    +

    {{ note.data }}

    -
  • - {% endfor %} -
+ + {% endfor %} {% else %} +

No notes found.

+ {% endif %} +

diff --git a/website/views.py b/website/views.py index d17a938e..f109ece7 100644 --- a/website/views.py +++ b/website/views.py @@ -1,9 +1,10 @@ -from flask import Blueprint, render_template, request, flash, jsonify +from flask import Blueprint, render_template, request, flash, redirect, url_for +from .models import Note, User from flask_login import login_required, current_user -from .models import Note from . import db import json + views = Blueprint('views', __name__) @@ -20,8 +21,19 @@ def home(): db.session.add(new_note) #adding the note to the database db.session.commit() flash('Note added!', category='success') + return redirect(url_for('views.home')) + + # Search behavior: show all notes when q is empty, otherwise show filtered results + q = request.args.get('q', '').strip() + if q: + notes = Note.query.filter( + Note.user_id == current_user.id, + Note.data.ilike(f'%{q}%') + ).order_by(Note.id.desc()).all() + else: + notes = Note.query.filter_by(user_id=current_user.id).order_by(Note.id.desc()).all() - return render_template("home.html", user=current_user) + return render_template("home.html", user=current_user, notes=notes, query=q) @views.route('/delete-note', methods=['POST']) @@ -35,3 +47,19 @@ def delete_note(): db.session.commit() return jsonify({}) + +@views.route('/search') +@login_required +def search(): + q = request.args.get('q', '').strip() + if not q: + flash('Please enter a keyword to search.', category='info') + return redirect(url_for('views.home')) + + # case-insensitive partial match for the current user's notes + results = Note.query.filter( + Note.user_id == current_user.id, + Note.data.ilike(f'%{q}%') + ).order_by(Note.id.desc()).all() + + return render_template("home.html", user=current_user, notes=results, query=q) From 42a6c2e52d4ebec276e231e184009b0b2679afa5 Mon Sep 17 00:00:00 2001 From: mostaf_mansour Date: Mon, 13 Oct 2025 21:59:31 +0300 Subject: [PATCH 2/2] added new search feature --- instance/database.db | Bin 16384 -> 16384 bytes website/templates/home.html | 51 ++++++++++++++++++++---------------- website/views.py | 6 +++++ 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/instance/database.db b/instance/database.db index a245f2b27afea5e40dc6b391da2fcc71deabbcc3..b375a40633254791b3ccdc64900aab7aa9f3a0bb 100644 GIT binary patch delta 86 zcmZo@U~Fh$oFL68Fj2;tQD9@jLVaHTRSeAh*$n(W{Mr0ZHuD+G;b&oBV6d9J&R$0i p$WT)?=1eP1mSSaP5H#k@$}%!AGSxLS&^0txFto5THMBCa1OSwN6IcKM delta 86 zcmZo@U~Fh$oFL7}J5k1&k#}RlLVaEa1_l=XYzF>Y{HyqTHuD+G;b+lfVr7`T&R$1N qg^`s()tED_G&x%#w^AW5za-Vjz{phB&_LJFSi#W3%D}?P)C>TllN8bb diff --git a/website/templates/home.html b/website/templates/home.html index 1799d631..76759a50 100644 --- a/website/templates/home.html +++ b/website/templates/home.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% block title %}Home{% endblock %} {% block content %} -

Notes

+

Notes

Notes value="{{ query or '' }}" /> - - {% if query %} - Showing results for "{{ query }}" - {% endif %} + + + + {% if query %}Showing results for "{{ query }}"{% endif %}
-
-
-
-
- {% if notes %} {% for note in notes %} -
-

{{ note.data }}

+
+ +{% if notes %} +
    + {% for note in notes %} +
  • + {{ note.data }} -
- {% endfor %} {% else %} -

No notes found.

- {% endif %} -
+ + {% endfor %} + +{% else %} +

No notes found.

+{% endif %} + +

diff --git a/website/views.py b/website/views.py index f109ece7..b9831bfb 100644 --- a/website/views.py +++ b/website/views.py @@ -63,3 +63,9 @@ def search(): ).order_by(Note.id.desc()).all() return render_template("home.html", user=current_user, notes=results, query=q) + +@views.route('/clear-search') +@login_required +def clear_search(): + # Redirect to home with no query parameter, showing all notes + return redirect(url_for('views.home'))