aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
Diffstat (limited to 'src/web')
-rw-r--r--src/web/controllers/article.py2
-rw-r--r--src/web/controllers/feed.py9
-rw-r--r--src/web/forms.py9
-rw-r--r--src/web/templates/edit_feed.html8
-rw-r--r--src/web/templates/feed.html3
-rw-r--r--src/web/views/feed.py26
6 files changed, 47 insertions, 10 deletions
diff --git a/src/web/controllers/article.py b/src/web/controllers/article.py
index a8788f46..3d8d5c01 100644
--- a/src/web/controllers/article.py
+++ b/src/web/controllers/article.py
@@ -45,7 +45,7 @@ class ArticleController(AbstractController):
attrs.get('user_id', self.user_id)).get(id=attrs['feed_id'])
if 'user_id' in attrs:
assert feed.user_id == attrs['user_id'] or self.user_id is None
- attrs['user_id'] = feed.user_id
+ attrs['user_id'], attrs['category_id'] = feed.user_id, feed.category_id
# handling feed's filters
for filter_ in feed.filters or []:
diff --git a/src/web/controllers/feed.py b/src/web/controllers/feed.py
index 15be8663..3b05b294 100644
--- a/src/web/controllers/feed.py
+++ b/src/web/controllers/feed.py
@@ -66,5 +66,12 @@ class FeedController(AbstractController):
return super().create(**attrs)
def update(self, filters, attrs):
+ from .article import ArticleController
self._ensure_icon(attrs)
- return super().update(filters, 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
diff --git a/src/web/forms.py b/src/web/forms.py
index d901f260..f57b31d0 100644
--- a/src/web/forms.py
+++ b/src/web/forms.py
@@ -31,7 +31,7 @@ from flask import flash, url_for, redirect
from flask.ext.wtf import Form
from flask.ext.babel import lazy_gettext
from wtforms import TextField, TextAreaField, PasswordField, BooleanField, \
- SubmitField, IntegerField, validators, HiddenField
+ SubmitField, IntegerField, SelectField, validators, HiddenField
from flask.ext.wtf.html5 import EmailField
from flask_wtf import RecaptchaField
@@ -170,6 +170,13 @@ class AddFeedForm(Form):
site_link = TextField(lazy_gettext("Site link"), [validators.Optional()])
enabled = BooleanField(lazy_gettext("Check for updates"), default=True)
submit = SubmitField(lazy_gettext("Save"))
+ category_id = SelectField(lazy_gettext("Category of the feed"),
+ [validators.Optional()])
+
+ def set_category_choices(self, categories):
+ self.category_id.choices = [('0', 'No Category')]
+ self.category_id.choices += [(str(cat.id), cat.name)
+ for cat in categories]
class AddCategoryForm(Form):
diff --git a/src/web/templates/edit_feed.html b/src/web/templates/edit_feed.html
index 68da0d48..ab624f15 100644
--- a/src/web/templates/edit_feed.html
+++ b/src/web/templates/edit_feed.html
@@ -30,6 +30,14 @@
</div>
<div class="form-group">
+ <label for="{{ form.category_id.id }}" class="col-sm-3 control-label">{{ form.category_id.label }}</label>
+ <div class="col-sm-9">
+ {{ form.category_id(class_="form-control", placeholder=_('Optional')) }}
+ </div>
+ {% for error in form.category_id.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+ </div>
+
+ <div class="form-group">
<label for="{{ form.enabled.id }}" class="col-sm-3 control-label">{{ form.enabled.label }}</label>
<div class="col-sm-9">
<div class="checkbox">
diff --git a/src/web/templates/feed.html b/src/web/templates/feed.html
index 6705015a..7434a9ac 100644
--- a/src/web/templates/feed.html
+++ b/src/web/templates/feed.html
@@ -10,6 +10,9 @@
<div class="well">
<p>
{{ _('This feed contains') }} {{ feed.articles.all()|count }} <a href= "{{ url_for("home", feed_id=feed.id, filter_="all") }}">{{ _('articles') }}</a>.<br />
+ {% if category %}
+ {{ _('This feed is part of category %(category_name)s', category_name=category.name) }}<br />
+ {% endif %}
{{ _('Address of the feed') }}: <a href="{{ feed.link }}" target="_blank">{{ feed.link }}</a><br />
{% if feed.site_link != "" %}
{{ _('Address of the site') }}: <a href="{{ feed.site_link }}" target="_blank">{{ feed.site_link }}</a><br />
diff --git a/src/web/views/feed.py b/src/web/views/feed.py
index 2a9b2da8..68d8765a 100644
--- a/src/web/views/feed.py
+++ b/src/web/views/feed.py
@@ -17,7 +17,8 @@ from web import utils
from web.lib.view_utils import etag_match
from web.lib.feed_utils import construct_feed_from
from web.forms import AddFeedForm
-from web.controllers import FeedController, ArticleController
+from web.controllers import (CategoryController, FeedController,
+ ArticleController)
feeds_bp = Blueprint('feeds', __name__, url_prefix='/feeds')
feed_bp = Blueprint('feed', __name__, url_prefix='/feed')
@@ -42,6 +43,9 @@ def feed(feed_id=None):
"Presents detailed information about a feed."
feed = FeedController(g.user.id).get(id=feed_id)
word_size = 6
+ category = None
+ if feed.category_id:
+ category = CategoryController(g.user.id).get(id=feed.category_id)
articles = ArticleController(g.user.id) \
.read(feed_id=feed_id) \
.order_by(desc("Article.date")).all()
@@ -65,7 +69,7 @@ def feed(feed_id=None):
head_titles=[utils.clear_string(feed.title)],
feed=feed, tag_cloud=tag_cloud,
first_post_date=first_article,
- end_post_date=last_article,
+ end_post_date=last_article, category=category,
average=average, delta=delta, elapsed=elapsed)
@@ -149,18 +153,23 @@ def update(action, feed_id=None):
@etag_match
def form(feed_id=None):
action = gettext("Add a feed")
+ categories = CategoryController(g.user.id).read()
head_titles = [action]
if feed_id is None:
+ form = AddFeedForm()
+ form.set_category_choices(categories)
return render_template('edit_feed.html', action=action,
- head_titles=head_titles, form=AddFeedForm())
+ head_titles=head_titles, form=form)
feed = FeedController(g.user.id).get(id=feed_id)
+ form = AddFeedForm(obj=feed)
+ form.set_category_choices(categories)
action = gettext('Edit feed')
head_titles = [action]
if feed.title:
head_titles.append(feed.title)
return render_template('edit_feed.html', action=action,
- head_titles=head_titles,
- form=AddFeedForm(obj=feed), feed=feed)
+ head_titles=head_titles, categories=categories,
+ form=form, feed=feed)
@feed_bp.route('/create', methods=['POST'])
@@ -169,6 +178,7 @@ def form(feed_id=None):
def process_form(feed_id=None):
form = AddFeedForm()
feed_contr = FeedController(g.user.id)
+ form.set_category_choices(CategoryController(g.user.id).read())
if not form.validate():
return render_template('edit_feed.html', form=form)
@@ -179,7 +189,9 @@ def process_form(feed_id=None):
# Edit an existing feed
feed_attr = {'title': form.title.data, 'enabled': form.enabled.data,
'link': form.link.data, 'site_link': form.site_link.data,
- 'filters': []}
+ 'filters': [], 'category_id': form.category_id.data}
+ if not feed_attr['category_id']:
+ del feed_attr['category_id']
for filter_attr in ('type', 'pattern', 'action on', 'action'):
for i, value in enumerate(
@@ -195,7 +207,7 @@ def process_form(feed_id=None):
return redirect(url_for('feed.form', feed_id=feed_id))
# Create a new feed
- new_feed = FeedController(g.user.id).create(**feed_attr)
+ new_feed = feed_contr.create(**feed_attr)
flash(gettext('Feed %(feed_title)r successfully created.',
feed_title=new_feed.title), 'success')
bgstack15