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 /pyaggr3g470r | |
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 'pyaggr3g470r')
-rw-r--r-- | pyaggr3g470r/controllers/category.py | 6 | ||||
-rw-r--r-- | pyaggr3g470r/templates/categories.html | 36 | ||||
-rw-r--r-- | pyaggr3g470r/views/category.py | 36 |
3 files changed, 72 insertions, 6 deletions
diff --git a/pyaggr3g470r/controllers/category.py b/pyaggr3g470r/controllers/category.py index b6fc591c..a0f746e9 100644 --- a/pyaggr3g470r/controllers/category.py +++ b/pyaggr3g470r/controllers/category.py @@ -1,6 +1,12 @@ from .abstract import AbstractController from pyaggr3g470r.models import Category +from .feed import FeedController class CategoryController(AbstractController): _db_cls = Category + + def delete(self, obj_id): + FeedController(self.user_id).update({'category_id': obj_id}, + {'category_id': None}) + return super().delete(obj_id) diff --git a/pyaggr3g470r/templates/categories.html b/pyaggr3g470r/templates/categories.html new file mode 100644 index 00000000..a61cc4b2 --- /dev/null +++ b/pyaggr3g470r/templates/categories.html @@ -0,0 +1,36 @@ +{% extends "layout.html" %} +{% block content %} +<div class="container"> + <h1>{{ _("You have %(categories)d categories · Add a %(start_link)scategory%(end_link)s", categories=categories|count, start_link=("<a href='%s'>" % url_for("category.form"))|safe, end_link="</a>"|safe) }}</h1> + {% if categories|count == 0 %} + <h1>{{_("No category")}}</h1> + {% else %} + <div class="table-responsive"> + <table class="table table-striped"> + <thead> + <tr> + <th>#</th> + <th>{{ _('Name') }}</th> + <th>{{ _('Feeds') }}</th> + <th>{{ _('Articles') }}</th> + <th>{{ _('Actions') }}</th> + </tr> + </thead> + <tbody> + {% for category in categories|sort(attribute="name") %} + <tr> + <td>{{ loop.index }}</td> + <td>{{ category.name }}</td> + <td>{{ feeds_count.get(category.id, 0) }}</td> + <td>( {{ unread_article_count.get(category.id, 0) }} ) {{ article_count.get(category.id, 0) }}</td> + <td> + <a href="{{ url_for("category.form", category_id=category.id) }}"><i class="glyphicon glyphicon-edit" title='{{ _("Edit this category") }}'></i></a> + <a href="{{ url_for("category.delete", category_id=category.id) }}"><i class="glyphicon glyphicon-remove" title='{{ _("Delete this category") }}' onclick="return confirm('{{ _('You are going to delete this category.') }}');"></i></a> + </td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + {% endif %} +{% endblock %} diff --git a/pyaggr3g470r/views/category.py b/pyaggr3g470r/views/category.py index c5defb7f..027a800f 100644 --- a/pyaggr3g470r/views/category.py +++ b/pyaggr3g470r/views/category.py @@ -2,14 +2,29 @@ from flask import g, Blueprint, render_template, flash, redirect, url_for from flask.ext.babel import gettext from flask.ext.login import login_required -from pyaggr3g470r.forms import AddCategoryForm +from pyaggr3g470r.forms import CategoryForm +from pyaggr3g470r.lib.utils import redirect_url from pyaggr3g470r.lib.view_utils import etag_match -from pyaggr3g470r.controllers.category import CategoryController +from pyaggr3g470r.controllers \ + import ArticleController, FeedController, CategoryController categories_bp = Blueprint('categories', __name__, url_prefix='/categories') category_bp = Blueprint('category', __name__, url_prefix='/category') +@categories_bp.route('/', methods=['GET']) +@login_required +@etag_match +def list_(): + "Lists the subscribed feeds in a table." + art_contr = ArticleController(g.user.id) + return render_template('categories.html', + categories=list(CategoryController(g.user.id).read()), + feeds_count=FeedController(g.user.id).count_by_category(), + unread_article_count=art_contr.count_by_category(readed=False), + article_count=art_contr.count_by_category()) + + @category_bp.route('/create', methods=['GET']) @category_bp.route('/edit/<int:category_id>', methods=['GET']) @login_required @@ -19,7 +34,7 @@ def form(category_id=None): head_titles = [action] if category_id is None: return render_template('edit_category.html', action=action, - head_titles=head_titles, form=AddCategoryForm()) + head_titles=head_titles, form=CategoryForm()) category = CategoryController(g.user.id).get(id=category_id) action = gettext('Edit category') head_titles = [action] @@ -27,14 +42,23 @@ def form(category_id=None): head_titles.append(category.name) return render_template('edit_category.html', action=action, head_titles=head_titles, category=category, - form=AddCategoryForm(obj=category)) + form=CategoryForm(obj=category)) + + +@category_bp.route('/delete/<int:category_id>', methods=['GET']) +@login_required +def delete(category_id=None): + category = CategoryController(g.user.id).delete(category_id) + flash(gettext("Category %(category_name)s successfully deleted.", + category_name=category.name), 'success') + return redirect(redirect_url()) @category_bp.route('/create', methods=['POST']) -@category_bp.route('/edit/<int:cat_id>', methods=['POST']) +@category_bp.route('/edit/<int:category_id>', methods=['POST']) @login_required def process_form(category_id=None): - form = AddCategoryForm() + form = CategoryForm() cat_contr = CategoryController(g.user.id) if not form.validate(): |