diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2015-10-12 17:48:41 +0200 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2016-01-26 23:46:31 +0100 |
commit | 7cbbcb59f4c434fbd7e74e85c90e98fadd189b65 (patch) | |
tree | f979fd6300b8767c8bbca0a7ac5c3ee831df49df /src | |
parent | updating translations (diff) | |
download | newspipe-7cbbcb59f4c434fbd7e74e85c90e98fadd189b65.tar.gz newspipe-7cbbcb59f4c434fbd7e74e85c90e98fadd189b65.tar.bz2 newspipe-7cbbcb59f4c434fbd7e74e85c90e98fadd189b65.zip |
adding, improving UI to manage categories
Diffstat (limited to 'src')
-rw-r--r-- | src/web/controllers/abstract.py | 13 | ||||
-rw-r--r-- | src/web/controllers/article.py | 9 | ||||
-rw-r--r-- | src/web/controllers/feed.py | 8 | ||||
-rw-r--r-- | src/web/forms.py | 7 | ||||
-rw-r--r-- | src/web/templates/feed_list.html | 2 | ||||
-rw-r--r-- | src/web/templates/feeds.html | 2 | ||||
-rw-r--r-- | src/web/views/feed.py | 1 |
7 files changed, 27 insertions, 15 deletions
diff --git a/src/web/controllers/abstract.py b/src/web/controllers/abstract.py index 99d92ff3..828e6a29 100644 --- a/src/web/controllers/abstract.py +++ b/src/web/controllers/abstract.py @@ -1,7 +1,7 @@ import logging from flask import g from bootstrap import db -from sqlalchemy import or_ +from sqlalchemy import or_, func from werkzeug.exceptions import Forbidden, NotFound logger = logging.getLogger(__name__) @@ -83,12 +83,12 @@ class AbstractController(object): return obj def create(self, **attrs): + if self._user_id_key is not None and self._user_id_key not in attrs: + attrs[self._user_id_key] = self.user_id assert self._user_id_key is None or self._user_id_key in attrs \ or self.user_id is None, \ "You must provide user_id one way or another" - if self._user_id_key is not None and self._user_id_key not in attrs: - attrs[self._user_id_key] = self.user_id obj = self._db_cls(**attrs) db.session.add(obj) db.session.commit() @@ -114,3 +114,10 @@ class AbstractController(object): return True return self.user_id is None \ or getattr(obj, self._user_id_key, None) == self.user_id + + def _count_by(self, elem_to_group_by, filters): + if self.user_id: + filters['user_id'] = self.user_id + return dict(db.session.query(elem_to_group_by, func.count('id')) + .filter(*self._to_filters(**filters)) + .group_by(elem_to_group_by).all()) diff --git a/src/web/controllers/article.py b/src/web/controllers/article.py index 72288a09..50e6757f 100644 --- a/src/web/controllers/article.py +++ b/src/web/controllers/article.py @@ -28,12 +28,11 @@ class ArticleController(AbstractController): continue yield id_ + def count_by_category(self, **filters): + return self._count_by(Article.category_id, filters) + def count_by_feed(self, **filters): - if self.user_id: - filters['user_id'] = self.user_id - return dict(db.session.query(Article.feed_id, func.count(Article.id)) - .filter(*self._to_filters(**filters)) - .group_by(Article.feed_id).all()) + return self._count_by(Article.feed_id, filters) def count_by_user_id(self, **filters): return dict(db.session.query(Article.user_id, func.count(Article.id)) diff --git a/src/web/controllers/feed.py b/src/web/controllers/feed.py index b76c4e42..31a1ec41 100644 --- a/src/web/controllers/feed.py +++ b/src/web/controllers/feed.py @@ -87,6 +87,9 @@ class FeedController(AbstractController): inactives.sort(key=lambda tup: tup[1], reverse=True) return inactives + def count_by_category(self, **filters): + return self._count_by(Feed.category_id, filters) + def _ensure_icon(self, attrs): if not attrs.get('icon_url'): return @@ -101,10 +104,9 @@ class FeedController(AbstractController): def update(self, filters, attrs): from .article import ArticleController self._ensure_icon(attrs) - result = super().update(filters, attrs) if 'category_id' in attrs: art_contr = ArticleController(self.user_id) for feed in self.read(**filters): art_contr.update({'feed_id': feed.id}, - {'category_id': feed.category_id}) - return result + {'category_id': attrs['category_id']}) + return super().update(filters, attrs) diff --git a/src/web/forms.py b/src/web/forms.py index f57b31d0..9dbf1b5f 100644 --- a/src/web/forms.py +++ b/src/web/forms.py @@ -38,6 +38,7 @@ from flask_wtf import RecaptchaField from web import utils from web.models import User + class SignupForm(Form): """ Sign up form (registration to jarr). @@ -63,6 +64,7 @@ class SignupForm(Form): validated = False return validated + class RedirectForm(Form): """ Secure back redirects with WTForms. @@ -80,6 +82,7 @@ class RedirectForm(Form): target = utils.get_redirect_target() return redirect(target or url_for(endpoint, **values)) + class SigninForm(RedirectForm): """ Sign in form (connection to jarr). @@ -179,9 +182,9 @@ class AddFeedForm(Form): for cat in categories] -class AddCategoryForm(Form): +class CategoryForm(Form): name = TextField(lazy_gettext("Name")) - submit = SubmitField(lazy_gettext("Sign up")) + submit = SubmitField(lazy_gettext("Submit")) class InformationMessageForm(Form): diff --git a/src/web/templates/feed_list.html b/src/web/templates/feed_list.html index 27815250..51561dee 100644 --- a/src/web/templates/feed_list.html +++ b/src/web/templates/feed_list.html @@ -1,4 +1,4 @@ -{% if feeds.all()| count == 0 %} +{% if feeds| count == 0 %} <h1>{{_("No feed")}}</h1> {% else %} <div class="table-responsive"> diff --git a/src/web/templates/feeds.html b/src/web/templates/feeds.html index 9ba16359..074957f7 100644 --- a/src/web/templates/feeds.html +++ b/src/web/templates/feeds.html @@ -1,7 +1,7 @@ {% extends "layout.html" %} {% block content %} <div class="container"> - <h1>{{ _('You are subscribed to') }} {{ feeds.count() }} {{ _('feeds') }} · {{ _('Add a') }} <a href="{{ url_for("feed.form") }}">{{ _('feed') }}</a></h1> + <h1>{{ _('You are subscribed to') }} {{ feeds|count }} {{ _('feeds') }} · {{ _('Add a') }} <a href="{{ url_for("feed.form") }}">{{ _('feed') }}</a></h1> {% include "feed_list.html" %} </div><!-- /.container --> {% endblock %} diff --git a/src/web/views/feed.py b/src/web/views/feed.py index 6569d1b7..e1c2fb55 100644 --- a/src/web/views/feed.py +++ b/src/web/views/feed.py @@ -14,6 +14,7 @@ from flask.ext.login import login_required import conf from web import utils +from web.lib.utils import redirect_url from web.lib.view_utils import etag_match from web.lib.feed_utils import construct_feed_from from web.forms import AddFeedForm |