aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/web/templates/home.html153
-rw-r--r--src/web/templates/home2.html22
-rw-r--r--src/web/views/views.py120
3 files changed, 27 insertions, 268 deletions
diff --git a/src/web/templates/home.html b/src/web/templates/home.html
index 6b136870..4389ae6f 100644
--- a/src/web/templates/home.html
+++ b/src/web/templates/home.html
@@ -1,131 +1,22 @@
-{% extends "layout.html" %}
-{% block content %}
-{% if feeds|count == 0 %}
- <div class="col-md-4 col-md-offset-4">
- <h1>{{ _("You don't have any feeds.") }}</h1>
- <h1><a href="{{ url_for("feed.form") }}">{{ _('Add some') }}</a>, {{ _('or') }} <a href="{{ url_for("user.management") }}">{{ _('upload an OPML file.') }}</a></h1>
- </div>
-{% else %}
-<div class="container-fluid">
- <div class="row row-offcanvas row-offcanvas-left">
- <div class="col-md-2 sidebar sidebar-offcanvas pre-scrollable affix hidden-sm hidden-xs" id="sidebar" role="navigation" data-spy="affix" style="max-height: 100%;">
- <ul class="nav nav-sidebar" data-offset-top="0" data-offset-bottom="0">
- <li><a href="{{ gen_url(feed_id=0) }}">
- {% if not feed_id %}<b>{% endif %}
- {{ _('All feeds') }} <span id="total-unread" class="badge pull-right">{{ articles.__len__() }}</span>
- {% if not feed_id %}</b>{% endif %}
- </a></li>
- {% for fid, nbunread in unread|dictsort(by='value')|reverse %}
- <li class="feed-menu"><a href="{{ gen_url(feed_id=fid) }}">
- {% if feed_id == fid %}<b>{% endif %}
- {% if in_error.get(fid, 0) > 0 %}
- <span style="background-color: {{ "red" if in_error[fid] > conf.DEFAULT_MAX_ERROR -1 else "orange" }} ;" class="badge pull-right" title="Some errors occured while trying to retrieve that feed.">{{ in_error[fid] }} {{ _("error") }}{% if in_error[fid] > 1 %}s{% endif %}</span>
- {% endif %}
- <span id="unread-{{ fid }}" class="badge pull-right">{{ nbunread }}</span>
- {{ feeds[fid]|safe }}
- {% if feed_id == fid %}</b>{% endif %}
- </a></li>
- <li class="feed-commands"><span>
- <a href="/feed/{{ fid }}"><i class="glyphicon glyphicon-info-sign" title="{{ _('Details') }}"></i></a>
- <a href="{{ url_for("feed.form", feed_id=fid) }}"><i class="glyphicon glyphicon-edit" title="{{ _('Edit this feed') }}"></i></a>
- <a href="{{ url_for("feed.delete", feed_id=fid) }}"><i class="glyphicon glyphicon-remove" title="{{ _('Delete this feed') }}" onclick="return confirm('{{ _('You are going to delete this feed.') }}');"></i></a>
- <a href="{{ url_for("feed.update", feed_id=fid, action="read") }}"><i class="glyphicon glyphicon-check" title="{{ _('Mark this feed as read') }}"></i></a>
- <a href="{{ url_for("feed.update", feed_id=fid, action="unread") }}"><i class="glyphicon glyphicon-unchecked" title="{{ _('Mark this feed as unread') }}"></i></a>
- </span></li>
- {% endfor %}
- {% for fid, ftitle in feeds|dictsort(case_sensitive=False, by='value') if not fid in unread %}
- <li class="feed-menu"><a href="{{ gen_url(feed_id=fid) }}">
- {% if in_error.get(fid, 0) > 0 %}
- <span style="background-color: {{ "red" if in_error[fid] > conf.DEFAULT_MAX_ERROR - 1 else "orange" }} ;" class="badge pull-right" title="Some errors occured while trying to retrieve that feed.">{{ in_error[fid] }} {{ _("error") }}{% if in_error[fid] > 1 %}s{% endif %}</span>
- {% endif %}
- {% if feed_id == fid %}<b>{% endif %}
- {{ ftitle|safe }}
- {% if feed_id == fid %}</b>{% endif %}
- </a></li>
- <li class="feed-commands"><span>
- <a href="{{ url_for("feed.feed", feed_id=fid) }}"><i class="glyphicon glyphicon-info-sign" title="{{ _('Details') }}"></i></a>
- <a href="{{ url_for("feed.form", feed_id=fid) }}"><i class="glyphicon glyphicon-edit" title="{{ _('Edit this feed') }}"></i></a>
- <a href="{{ url_for("feed.delete", feed_id=fid) }}"><i class="glyphicon glyphicon-remove" title="{{ _('Delete this feed') }}" onclick="return confirm('{{ _('You are going to delete this feed.') }}');"></i></a>
- <a href="{{ url_for("feed.update", feed_id=fid, action="read") }}"><i class="glyphicon glyphicon-check" title="{{ _('Mark this feed as read') }}"></i></a>
- <a href="{{ url_for("feed.update", feed_id=fid, action="unread") }}"><i class="glyphicon glyphicon-unchecked" title="{{ _('Mark this feed as unread') }}"></i></a>
- </span></li>
- {% endfor %}
- </ul>
- </div><!-- row -->
-
- {% with messages = get_flashed_messages(with_categories=true) %}
- {% if messages %}
- <div class="col-md-offset-2 col-md-10 main">
- {% block messages %}
- {{ super() }}
- {% endblock %}
- </div>
- {% endif %}
- {% endwith %}
- <div class="col-md-offset-2 col-md-10 main">
- <div id="filters" data-filter="{{ filter_ }}">
- <ul id="myTab" class="nav nav-tabs" role="tablist">
- <li id="tab-all"><a href="{{ gen_url(filter_='all') }}">{{ _('All') }}</a></li>
- <li id="tab-read"><a href="{{ gen_url(filter_='read') }}">{{ _('Read') }}</a></li>
- <li id="tab-unread"><a href="{{ gen_url(filter_='unread') }}">{{ _('Unread') }}</a></li>
- <li id="tab-nbdisplay" class="pull-right">
- <div id="nbdisplay">
- <a href="{{ gen_url(limit=10) }}" class="label {% if limit == 10 %}label-primary{% else %}label-info{% endif %}">{{ _(10) }}</a>
- <a href="{{ gen_url(limit=100) }}" class="label {% if limit == 100 %}label-primary{% else %}label-info{% endif %}">{{ _(100) }}</a>
- <a href="{{ gen_url(limit=1000) }}" class="label {% if limit == 1000 %}label-primary{% else %}label-info{% endif %}">{{ _(1000) }}</a>
- <a href="{{ gen_url(limit='all') }}" class="label {% if limit == 'all' %}label-primary{% else %}label-info{% endif %}">{{ _('All') }}</a>
- </div>
- </li>
- </div>
- {% if articles | count != 0%}
- <div class="table-responsive">
- <table class="table table-striped strict-table">
- <thead>
- <tr>
- <th></th>
- <th><a href="{{ gen_url(sort_='-feed' if sort_ == 'feed' else 'feed') }}">{{ _('Feed') }}</a></th>
- <th><a href="{{ gen_url(sort_='-article' if sort_ == 'article' else 'article') }}">{{ _('Article') }}</a></th>
- <th><a href="{{ gen_url(sort_='-date' if sort_ == 'date' else 'date') }}">{{ _('Date') }}</a></th>
- </tr>
- </thead>
- <tbody>
- {% for article in articles %}
- <tr data-article="{{ article.id }}" data-feed="{{ article.feed_id }}">
- <td>
- <a><i class="glyphicon glyphicon-remove delete" title="{{ _('Delete this article') }}"></i></a>
- {% if article.like %}
- <a><i class="glyphicon glyphicon-star like" title="{{ _('One of your favorites') }}"></i></a>
- {% else %}
- <a><i class="glyphicon glyphicon-star-empty like" title="{{ _('Click if you like this article') }}"></i></a>
- {% endif %}
- {% if article.readed %}
- <a><i class="glyphicon glyphicon-unchecked readed" title="{{ _('Mark this article as unread') }}"></i></a>
- {% else %}
- <a><i class="glyphicon glyphicon-check readed" title="{{ _('Mark this article as read') }}"></i></a>
- {% if filter_ == 'all' %}</b>{% endif %}
- {% endif %}
- </td>
- <td>
- <a class="open-article" href="{{ url_for("article.redirect_to_article", article_id=article.id)}}" target="_blank" title="{{article.link}}" alt="{{article.link}}">
- {% if article.source.icon_url %}
- <img src="{{ url_for('icon.icon', url=article.source.icon_url) }}" width="16px" />
- {% else %}
- <span class="glyphicon glyphicon-ban-circle" title='{{_("No icon found for this feed")}}' alt='{{_("No icon found for this feed")}}'></span>
- {% endif %}
- <span class="hidden-xs">{{ article.source.title|safe }}</span></a></td>
- <td {%if filter_ == 'all' and article.readed == False %}style='font-weight:bold'{% endif %}>
- <a href="{{ url_for("article.article", article_id=article.id) }}">{{ article.title|safe }}</a>
- </td>
- <td class="date">{{ article.date|datetime }}</a></td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- </div>
- {% endif %}
- </div><!-- row -->
- </div><!-- main -->
-</div><!-- container-fluid -->
-<style>.not-at-home {display: none};</style>
-{% endif %}
-{% endblock %}
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ {% block head %}
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta name="description" content="JARR is a web-based news aggregator." />
+ <meta name="author" content="" />
+ <title>JARR{% if head_titles %} - {{ ' - '.join(head_titles) }}{% endif %}</title>
+ <link rel="shortcut icon" href="{{ url_for("static", filename="img/favicon.png") }}" />
+ <!-- Bootstrap core CSS -->
+ <link href="{{ url_for("static", filename="css/bootstrap.min.css") }}" rel="stylesheet" media="screen" />
+ <!-- Add custom CSS here -->
+ <link href="{{ url_for("static", filename="css/customized-bootstrap.css") }}" rel="stylesheet" media="screen" />
+ <link href="{{ url_for("static", filename="css/one-page-app.css") }}" rel="stylesheet" media="screen" />
+ {% endblock %}
+ </head>
+ <body>
+ <section id="jarrapp" />
+ </body>
+ <script type="text/javascript" src="{{ url_for('static', filename = 'js/bundle.min.js') }}"></script>
+</html>
diff --git a/src/web/templates/home2.html b/src/web/templates/home2.html
deleted file mode 100644
index 4389ae6f..00000000
--- a/src/web/templates/home2.html
+++ /dev/null
@@ -1,22 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
- {% block head %}
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta name="description" content="JARR is a web-based news aggregator." />
- <meta name="author" content="" />
- <title>JARR{% if head_titles %} - {{ ' - '.join(head_titles) }}{% endif %}</title>
- <link rel="shortcut icon" href="{{ url_for("static", filename="img/favicon.png") }}" />
- <!-- Bootstrap core CSS -->
- <link href="{{ url_for("static", filename="css/bootstrap.min.css") }}" rel="stylesheet" media="screen" />
- <!-- Add custom CSS here -->
- <link href="{{ url_for("static", filename="css/customized-bootstrap.css") }}" rel="stylesheet" media="screen" />
- <link href="{{ url_for("static", filename="css/one-page-app.css") }}" rel="stylesheet" media="screen" />
- {% endblock %}
- </head>
- <body>
- <section id="jarrapp" />
- </body>
- <script type="text/javascript" src="{{ url_for('static', filename = 'js/bundle.min.js') }}"></script>
-</html>
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