diff --git a/saythanks/core.py b/saythanks/core.py index 265e9d9..8bf04f6 100644 --- a/saythanks/core.py +++ b/saythanks/core.py @@ -98,10 +98,9 @@ def index(): auth_domain=auth_domain) -@app.route('/inbox') +@app.route('/inbox', methods=['POST', 'GET']) @requires_auth def inbox(): - # Auth0 stored account information. profile = session['profile'] @@ -110,11 +109,17 @@ def inbox(): is_enabled = storage.Inbox.is_enabled(inbox_db.slug) is_email_enabled = storage.Inbox.is_email_enabled(inbox_db.slug) - # Send over the list of all given notes for the user. + if request.method == "GET": + # Send over the list of all given notes for the user. + return render_template('inbox.htm.j2', + user=profile, notes=inbox_db.notes, + inbox=inbox_db, is_enabled=is_enabled, + is_email_enabled=is_email_enabled) + search_str = request.form['search_str'] return render_template('inbox.htm.j2', - user=profile, notes=inbox_db.notes, - inbox=inbox_db, is_enabled=is_enabled, - is_email_enabled=is_email_enabled) + user=profile, notes=inbox_db.search_notes(search_str), + is_email_enabled=is_email_enabled) + @app.route('/inbox/export/<format>') @@ -346,3 +351,4 @@ def callback_handling(): # Using nickname by default, can be changed manually later if needed. storage.Inbox.store(nickname, userid, email) return redirect(url_for('inbox')) + \ No newline at end of file diff --git a/saythanks/storage.py b/saythanks/storage.py index e4d9f33..2cba171 100644 --- a/saythanks/storage.py +++ b/saythanks/storage.py @@ -208,6 +208,20 @@ def notes(self): for n in r ] return notes[::-1] + + def search_notes(self, search_str): + """Returns a list of notes, queried by search string "param" """ + q = sqlalchemy.text("""SELECT * from notes where ( body LIKE '%' || :param || '%' or byline LIKE '%' || :param || '%' ) and inboxes_auth_id = :auth_id""") + r = conn.execute(q, param=search_str, auth_id=self.auth_id).fetchall() + + notes = [ + Note.from_inbox( + self.slug, + n["body"], n["byline"], n["archived"], n["uuid"], n["timestamp"] + ) + for n in r + ] + return notes[::-1] def export(self, file_format): q = sqlalchemy.text("SELECT * from notes where inboxes_auth_id = :auth_id and archived = 'f'") diff --git a/saythanks/templates/inbox.htm.j2 b/saythanks/templates/inbox.htm.j2 index a830cf2..f67df0a 100644 --- a/saythanks/templates/inbox.htm.j2 +++ b/saythanks/templates/inbox.htm.j2 @@ -72,7 +72,10 @@ <h3>Notes of Thankfulness:</h3> </p> - +<form action="/inbox" method="POST"> + <input type="text" style="font-size:14px" size=28 placeholder="Search by message body or byline" name="search_str"> + <button style="font-size:10px" type="submit">Search</button> +</form> <table> <thead> <tr>