From 297a77753bf9eddd944fd49799b6c1716dda2680 Mon Sep 17 00:00:00 2001 From: Daniel Grams Date: Sun, 19 Jul 2020 17:20:48 +0200 Subject: [PATCH] keyword search --- app.py | 16 ++++++++++++++-- templates/widget/read.html | 7 +++++++ translations/de/LC_MESSAGES/messages.mo | Bin 6817 -> 6851 bytes translations/de/LC_MESSAGES/messages.po | 8 ++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index e342803..f6e1864 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,7 @@ from flask_sqlalchemy import SQLAlchemy from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.orm import joinedload from sqlalchemy.sql import asc, func -from sqlalchemy import and_ +from sqlalchemy import and_, or_ from flask_security import Security, current_user, auth_required, roles_required, hash_password, SQLAlchemySessionUserDatastore from flask_security.utils import FsPermNeed from flask_babelex import Babel, gettext, lazy_gettext, format_datetime, to_user_timezone @@ -1477,6 +1477,7 @@ def widget(): date_to = date_set_end_of_day(today + relativedelta(days=7)) date_from_str = form_input_from_date(date_from) date_to_str = form_input_from_date(date_to) + keyword = '' if request.method == 'POST': date_from_str = request.form['date_from'] @@ -1484,10 +1485,21 @@ def widget(): date_from = form_input_to_date(date_from_str) date_to = form_input_to_date(date_to_str, 23, 59, 59) - dates = EventDate.query.filter(and_(EventDate.start >= date_from, EventDate.start < date_to)).order_by(EventDate.start).all() + if 'keyword' in request.form: + keyword = request.form['keyword'] + + date_filter = and_(EventDate.start >= date_from, EventDate.start < date_to) + + if keyword: + like_keyword = '%' + keyword + '%' + dates = EventDate.query.join(Event).filter(date_filter).filter(or_(Event.name.ilike(like_keyword), Event.description.ilike(like_keyword), Event.tags.ilike(like_keyword))).order_by(EventDate.start).all() + else: + dates = EventDate.query.join(Event).filter(date_filter).order_by(EventDate.start).all() + return render_template('widget/read.html', date_from_str=date_from_str, date_to_str=date_to_str, + keyword=keyword, dates=dates) if __name__ == '__main__': diff --git a/templates/widget/read.html b/templates/widget/read.html index 04f8a6b..71e63d0 100644 --- a/templates/widget/read.html +++ b/templates/widget/read.html @@ -23,6 +23,13 @@ +
+
+ {{ _('Keyword') }} +
+ +
+ diff --git a/translations/de/LC_MESSAGES/messages.mo b/translations/de/LC_MESSAGES/messages.mo index fab7c5fe7d8018a1e2f0ce586af78cd9aa689cb6..bac774b7317a72d627cab0ae36f7eb23ad2ffca1 100644 GIT binary patch delta 2233 zcmYM#ZD^KN7{Kwfe00veIOke(xpI5f9Epvs*3xVu`9X$dth5jMp^>GdU^?w(xp>0N z(TkA12sV2Y!l+2$DSJ^8+9E&1)QSpXt0)kX%nBo2MgPBC(8Im^cc1&d&vmYIo%1|< zwQaa9H(rr>KJnSk-)#PtXKeld8JL>V#WWwrnfNSL;Xa&dtikW&`2-d-ekvfUflI^cFpCDh3hlTsTp4aa6MhnB;fr`Fz8BBGKr43|FTo7K zY|lp9t+p9Ib#h_HJJ8Y%;AOZ6NirQmVx&*dN*%{?97B$DI_{qj3wf!G`;|zEQx@&l z!pZkL!cNS&Myuk+-DtZH4X_nC(oRkWdI_iCTj=vVx)dLWpN5|yM>-MhadgdpjQgk1 zJ@How^>=0kL^n_g`d~&_6Zf;|z)fgHnz0%epqsG^9iRt|vk`soeq^ll2-e|_a6fXS z6Q$JOl6*(Y4yVw~b2gj^3z)8ZpfIdQ6S@KIzZBi9x1fovMJstP8gBsIBU^DU?!hJ; z$#LO}zl8swfl9flb!dRL@OpIMCE+r3Gp#^!P3zDK+=tHmAvDe)a-<n?h za~1V>z-o4mfwE|aCN!Z|^oL_HUV+`{?j1w}?h5y!GkqJ4a}b@_A#^hyL6_>Aczza* ze?G?rRY`@sWl3t0jhq^y-Htx*z(sf)w%|^5&4RQ?7#xj7QlxbhsvLJt~ynAxdt($x9T+f5e J`R1y=%zuBTzk2`x delta 2205 zcmYM#4QQ2B7{Kx4^-lNgbZ#r#oKvSuEiAhjmr5cP!mJDlMp$ksMNKRzG7{fpeWL}X zXrPp7g(wlNCc#ic%%D#kPVE> zZ%KS!pbHK3Oth~<6L=N5(iRF6dk072`#25v-~>Do z&(C26M!qdOvy=enuxWSjqYu z;6gn3E6g#P?G@;NHRwt-;8oay9>OAen3kaLx1;Yph=fXyVhcVUZbh#2IfW~6w2Jk& zLq823nxDec;UK#AzlY^a+k{%t0JG3TdNZ2HUFZrfMdPhN&&Fdo9bdpU+=ssRT^2WI z&_I8NWjr-NQ#b`3_}XwbdWhyCxutv16y^57rOpN(`fCqnhl=IZa2mXfC>vcc5qHPPG4WEcg4r zDqdKNF5!B-9lOyP96<;E5lv(eU5Ozy&?U5A3Da`sqY3_!XVdFq%*)``}OWn0nUV zC9I{v0VkmY&O|1eW}|z!06AA_Nj&dF2Yw`cBHEut6I+k=dj;pj!S-cVuonelXX1xkcbUZRtYDBJd z6NT?(cgIaTI`b9iOkY9+zlkRFLDc(j67>`4KdmA37qW`NJ#It$7tsV3;tX7jQ*kZ2 jQadoUw)JGCEAu_)D=&`B7m9^BJ!fk=N_y_Ae=`3s`J}l< diff --git a/translations/de/LC_MESSAGES/messages.po b/translations/de/LC_MESSAGES/messages.po index 3a3a7d4..4c71821 100644 --- a/translations/de/LC_MESSAGES/messages.po +++ b/translations/de/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2020-07-19 15:53+0200\n" +"POT-Creation-Date: 2020-07-19 17:19+0200\n" "PO-Revision-Date: 2020-06-07 18:51+0200\n" "Last-Translator: FULL NAME \n" "Language: de\n" @@ -619,7 +619,11 @@ msgstr "Von" msgid "to" msgstr "bis" -#: templates/widget/read.html:26 +#: templates/widget/read.html:28 +msgid "Keyword" +msgstr "Stichwort" + +#: templates/widget/read.html:33 msgid "Find" msgstr "Finden"