aboutsummaryrefslogtreecommitdiff
path: root/src/web/views/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/views/views.py')
-rw-r--r--src/web/views/views.py120
1 files changed, 5 insertions, 115 deletions
diff --git a/src/web/views/views.py b/src/web/views/views.py
index 1aed912d..e09d2696 100644
--- a/src/web/views/views.py
+++ b/src/web/views/views.py
@@ -29,7 +29,6 @@ __license__ = "AGPLv3"
import os
import logging
import datetime
-from collections import OrderedDict
from bootstrap import application as app, db
from flask import render_template, request, flash, session, \
@@ -47,7 +46,7 @@ import conf
from web.lib.utils import redirect_url
from web import utils, notifications, export
from web.lib.view_utils import etag_match
-from web.models import User, Feed, Article, Role
+from web.models import User, Article, Role
from web.forms import SignupForm, SigninForm
from web.controllers import UserController, FeedController, \
@@ -234,10 +233,11 @@ from calendar import timegm
from flask import jsonify
-@app.route('/home2')
+@app.route('/')
@login_required
-def new_home():
- return render_template('home2.html')
+@etag_match
+def home():
+ return render_template('home.html')
@app.route('/menu')
@@ -337,116 +337,6 @@ def mark_all_as_read():
return articles
-@etag_match
-def render_home(filters=None, head_titles=None,
- page_to_render='home', **kwargs):
- if filters is None:
- filters = {}
- if head_titles is None:
- head_titles = []
- feed_contr = FeedController(g.user.id)
- arti_contr = ArticleController(g.user.id)
- feeds = {feed.id: feed.title for feed in feed_contr.read()}
-
- in_error = {feed.id: feed.error_count for feed in
- feed_contr.read(error_count__gt=2)}
-
- 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_id', 0))
- limit = request.args.get('limit', 1000)
-
- if filter_ != 'all':
- filters['readed'] = filter_ == 'read'
- if feed_id:
- filters['feed_id'] = feed_id
- head_titles.append(feed_contr.get(id=feed_id).title)
-
- sort_param = {"feed": Feed.title.desc(),
- "date": Article.date.desc(),
- "article": Article.title.desc(),
- "-feed": Feed.title.asc(),
- "-date": Article.date.asc(),
- "-article": Article.title.asc()
- }.get(sort_, Article.date.desc())
-
- articles = arti_contr.read(**filters).join(Article.source). \
- order_by(sort_param)
- if limit != 'all':
- limit = int(limit)
- articles = articles.limit(limit)
-
- def gen_url(filter_=filter_, sort_=sort_, limit=limit, feed_id=feed_id,
- **kwargs):
- o_kwargs = OrderedDict()
- for key in sorted(kwargs):
- o_kwargs[key] = kwargs[key]
- if page_to_render == 'search':
- o_kwargs['query'] = request.args.get('query', '')
- o_kwargs['search_title'] = request.args.get('search_title', 'off')
- o_kwargs['search_content'] = request.args.get(
- 'search_content', 'off')
- # if nor title and content are selected, selecting title
- if o_kwargs['search_title'] == o_kwargs['search_content'] == 'off':
- o_kwargs['search_title'] = 'on'
- o_kwargs['filter_'] = filter_
- o_kwargs['sort_'] = sort_
- o_kwargs['limit'] = limit
- o_kwargs['feed_id'] = feed_id
- return url_for(page_to_render, **o_kwargs)
-
- articles = list(articles)
- if (page_to_render == 'home' and feed_id or page_to_render == 'search') \
- and filter_ != 'all' and not articles:
- return redirect(gen_url(filter_='all'))
-
- return render_template('home.html', gen_url=gen_url,
- feed_id=feed_id, page_to_render=page_to_render,
- filter_=filter_, limit=limit, feeds=feeds,
- unread=arti_contr.count_by_feed(readed=False),
- articles=articles, in_error=in_error,
- head_titles=head_titles, sort_=sort_, **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 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', 'off')
- search_content = request.args.get('search_content', 'off')
- if search_title == 'on':
- filters['title__ilike'] = "%%%s%%" % query
- if search_content == 'on':
- filters['content__ilike'] = "%%%s%%" % query
- if len(filters) == 0:
- search_title = 'on'
- filters['title__ilike'] = "%%%s%%" % query
- if len(filters) > 1:
- filters = {"__or__": filters}
- 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'])
@app.route('/fetch/<int:feed_id>', methods=['GET'])
@login_required
bgstack15