aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views/views.py
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-04-15 15:07:19 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-04-16 09:10:35 +0200
commit7c145da932191effab00f585664980d2e591b3df (patch)
tree4664a8f2432b974272ec70183342edbece8565bc /pyaggr3g470r/views/views.py
parentNo bad default 'No title' for feed creation (diff)
downloadnewspipe-7c145da932191effab00f585664980d2e591b3df.tar.gz
newspipe-7c145da932191effab00f585664980d2e591b3df.tar.bz2
newspipe-7c145da932191effab00f585664980d2e591b3df.zip
redoing full text search
using SQL LIKE condition using main home design for displaying results
Diffstat (limited to 'pyaggr3g470r/views/views.py')
-rw-r--r--pyaggr3g470r/views/views.py92
1 files changed, 43 insertions, 49 deletions
diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py
index d0c06da0..83012d7c 100644
--- a/pyaggr3g470r/views/views.py
+++ b/pyaggr3g470r/views/views.py
@@ -235,13 +235,8 @@ def signup():
return render_template('signup.html', form=form)
-@app.route('/')
-@login_required
-def home(favorites=False):
- """
- Home page for connected users. Displays by default unread articles.
- """
- head_title = gettext('Favorites') if favorites else ''
+
+def render_home(filters={}, head_title='', page_to_render='home', **kwargs):
feed_contr = FeedController(g.user.id)
arti_contr = ArticleController(g.user.id)
feeds = {feed.id: feed.title for feed in feed_contr.read()}
@@ -250,14 +245,12 @@ def home(favorites=False):
in_error = {feed.id: feed.error_count for feed in
feed_contr.read(error_count__gt=2)}
- filter_ = request.args.get('filter_', 'all' if favorites else 'unread')
+ filter_ = request.args.get('filter_',
+ 'unread' if page_to_render == 'home' else 'all')
sort_ = request.args.get('sort_', 'date')
feed_id = int(request.args.get('feed', 0))
limit = request.args.get('limit', 1000)
- filters = {}
- if favorites:
- filters['like'] = True
if filter_ != 'all':
filters['readed'] = filter_ == 'read'
if feed_id:
@@ -271,12 +264,18 @@ def home(favorites=False):
limit = int(limit)
articles = articles.limit(limit)
- def gen_url(filter_=filter_, sort_=sort_, limit=limit, feed=feed_id):
- return url_for('favorites' if favorites else 'home',
- filter_=filter_, sort_=sort_, limit=limit, feed=feed)
+ def gen_url(filter_=filter_, sort_=sort_, limit=limit, feed=feed_id,
+ **kwargs):
+ if page_to_render == 'search':
+ kwargs['query'] = request.args.get('query', '')
+ kwargs['search_title'] = request.args.get('search_title', 'on')
+ kwargs['search_content'] = request.args.get('searc_content', 'off')
+ return url_for(page_to_render, filter_=filter_, sort_=sort_,
+ limit=limit, feed=feed, **kwargs)
articles = list(articles)
- if not articles and not favorites and feed_id:
+ if (page_to_render == 'home' and feed_id or page_to_render == 'search') \
+ and not articles:
return redirect(gen_url(filter_='all'))
if sort_ == "feed":
@@ -285,13 +284,40 @@ def home(favorites=False):
return render_template('home.html', gen_url=gen_url, feed_id=feed_id,
filter_=filter_, limit=limit, feeds=feeds,
unread=unread, articles=articles, in_error=in_error,
- head_title=head_title, favorites=favorites)
+ head_title=head_title, **kwargs)
+
+
+@app.route('/')
+@login_required
+def home():
+ "Home page for connected users. Displays by default unread articles."
+ return render_home()
@app.route('/favorites')
@login_required
def favorites():
- return home(favorites=True)
+ return render_home({'like': True}, gettext('Favorites'), 'favorites')
+
+
+@app.route('/search', methods=['GET'])
+@login_required
+def search():
+ "Search articles corresponding to the query."
+ if 'query' not in request.args:
+ flash(gettext("No text to search were provided."), "warning")
+ return render_home()
+ query = request.args['query']
+ filters = {}
+ search_title = request.args.get('search_title')
+ search_content = request.args.get('search_content')
+ if search_title == 'on':
+ filters['title__like'] = "%%%s%%" % query
+ if search_content == 'on':
+ filters['content__like'] = "%%%s%%" % query
+ return render_home(filters, "%s %s" % (gettext('Search:'), query),
+ 'search', search_query=query, search_title=search_title,
+ search_content=search_content)
@app.route('/fetch', methods=['GET'])
@@ -472,38 +498,6 @@ def export_opml():
response.headers['Content-Disposition'] = 'attachment; filename=feeds.opml'
return response
-@app.route('/search', methods=['GET'])
-@login_required
-def search():
- """
- Search articles corresponding to the query.
- """
- if conf.ON_HEROKU:
- flash(gettext("Full text search is not yet implemented for Heroku."), "warning")
- return redirect(url_for('home'))
- user = User.query.filter(User.id == g.user.id).first()
-
- search_result, result = [], []
- nb_articles = 0
-
- query = request.args.get('query', None)
- if query is not None:
- try:
- search_result, nb_articles = fastsearch.search(user.id, query)
- except Exception as e:
- flash(gettext('An error occured') + ' (%s).' % e, 'danger')
- light_feed = namedtuple('Feed', ['id', 'title', 'articles'], verbose=False, rename=False)
- for feed_id in search_result:
- for feed in user.feeds:
- if feed.id == feed_id:
- articles = []
- for article_id in search_result[feed_id]:
- current_article = Article.query.filter(Article.user_id == g.user.id, Article.id == article_id).first()
- articles.append(current_article)
- articles = sorted(articles, key=lambda t: t.date, reverse=True)
- result.append(light_feed(feed.id, feed.title, articles))
- break
- return render_template('search.html', feeds=result, nb_articles=nb_articles, query=query)
@app.route('/management', methods=['GET', 'POST'])
@login_required
bgstack15