aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/static/js/feed.js22
-rw-r--r--pyaggr3g470r/templates/article.html2
-rw-r--r--pyaggr3g470r/templates/edit_feed.html23
-rw-r--r--pyaggr3g470r/templates/layout.html1
-rw-r--r--pyaggr3g470r/views/feed.py103
5 files changed, 101 insertions, 50 deletions
diff --git a/pyaggr3g470r/static/js/feed.js b/pyaggr3g470r/static/js/feed.js
new file mode 100644
index 00000000..b1e3110e
--- /dev/null
+++ b/pyaggr3g470r/static/js/feed.js
@@ -0,0 +1,22 @@
+$('.container').on('click', '#add-feed-filter-row', function() {
+ $('#filters-container').append(
+ '<div class="col-sm-9">'
+ + ' <input value="-" type="button" class="del-feed-filter-row" />'
+ + ' <select name="type">'
+ + ' <option value="simple match" selected>simple match</option>'
+ + ' <option value="regex">regex</option>'
+ + ' </select/>'
+ + ' <input type="text" size="50%" name="pattern" />'
+ + ' <select name="action_on">'
+ + ' <option value="match" selected>match</option>'
+ + ' <option value="no match">no match</option>'
+ + ' </select/>'
+ + ' <select name="action">'
+ + ' <option value="mark as read" selected>mark as read</option>'
+ + ' <option value="mark as favorite">mark as favorite</option>'
+ + ' </select/>'
+ + '</div>');
+});
+$('.container').on('click', '.del-feed-filter-row', function() {
+ $(this).parent().remove();
+});
diff --git a/pyaggr3g470r/templates/article.html b/pyaggr3g470r/templates/article.html
index 92014599..97fb3fbf 100644
--- a/pyaggr3g470r/templates/article.html
+++ b/pyaggr3g470r/templates/article.html
@@ -16,7 +16,7 @@
{% endif %}
{% if article.readed %}
<a href="#"><i class="glyphicon glyphicon-unchecked readed" title="{{ _('Mark this article as unread') }}"></i></a>
- {% elseĀ %}
+ {% else %}
<a href="#"><i class="glyphicon glyphicon-check readed" title="{{ _('Mark this article as read') }}"></i></a>
{% endif %}
<h6>{{ article.date | datetime }}</h6>
diff --git a/pyaggr3g470r/templates/edit_feed.html b/pyaggr3g470r/templates/edit_feed.html
index a56238d5..22aab58b 100644
--- a/pyaggr3g470r/templates/edit_feed.html
+++ b/pyaggr3g470r/templates/edit_feed.html
@@ -37,6 +37,29 @@
</div>
</div>
</div>
+ <div class="form-group" id="filters-container">
+ <label class="col-sm-3 control-label">{{ _("Filters") }} <input value="+" type="button" id="add-feed-filter-row" /></label>
+ {% if feed %}
+ {% for filter_ in feed.filters or [] %}
+ <div class="col-sm-9">
+ <input value="-" type="button" class="del-feed-filter-row" />
+ <select name="type">
+ <option value="simple match" {% if filter_.get("type") == "simple match" %}selected{% endif %}>{{ _("simple match") }}</option>
+ <option value="regex" {% if filter_.get("type") == "regex" %}selected{% endif %}>{{ _("regex") }}</option>
+ </select/>
+ <input type="text" value="{{ filter_.get("pattern") }}" size="50%" name="pattern" />
+ <select name="action_on">
+ <option value="match" {% if filter_.get("action on") == "match" %}selected{% endif %}>{{ _("match") }}</option>
+ <option value="no match" {% if filter_.get("action on") == "no match" %}selected{% endif %}>{{ _("no match") }}</option>
+ </select/>
+ <select name="action">
+ <option value="mark as read" {% if filter_.get("action") == "mark as read" %}selected{% endif %}>{{ _("mark as read") }}</option>
+ <option value="mark as favorite" {% if filter_.get("action") == "mark as favorite" %}selected{% endif %}>{{ _("mark as favorite") }}</option>
+ </select/>
+ </div>
+ {% endfor %}
+ {% endif %}
+ </div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
{{ form.submit(class_="btn btn-default") }}
diff --git a/pyaggr3g470r/templates/layout.html b/pyaggr3g470r/templates/layout.html
index c66cce3e..fcdbee32 100644
--- a/pyaggr3g470r/templates/layout.html
+++ b/pyaggr3g470r/templates/layout.html
@@ -153,6 +153,7 @@
<script type="text/javascript" src="{{ url_for('static', filename = 'js/jquery.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename = 'js/bootstrap.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename = 'js/articles.js') }}"></script>
+ <script type="text/javascript" src="{{ url_for('static', filename = 'js/feed.js') }}"></script>
<script type="text/javascript" class="source">
var filter_ = {% if filter_ %}"{{ filter_ }}"{% else %}undefined{% endif %};
if (filter_ == undefined) {
diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py
index 022980f4..8bd2f8e9 100644
--- a/pyaggr3g470r/views/feed.py
+++ b/pyaggr3g470r/views/feed.py
@@ -122,59 +122,64 @@ def update(action, feed_id=None):
return redirect(request.referrer or url_for('home'))
-@feed_bp.route('/create', methods=['GET', 'POST', 'PUT'])
-@feed_bp.route('/edit/<int:feed_id>', methods=['GET', 'POST'])
+@feed_bp.route('/create', methods=['GET'])
+@feed_bp.route('/edit/<int:feed_id>', methods=['GET'])
@login_required
def form(feed_id=None):
+ action = gettext("Add a feed")
+ head_titles = [action]
+ if feed_id is None:
+ return render_template('edit_feed.html', action=action,
+ head_titles=head_titles, form=AddFeedForm())
+ feed = FeedController(g.user.id).get(id=feed_id)
+ 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)
+
+
+@feed_bp.route('/create', methods=['POST'])
+@feed_bp.route('/edit/<int:feed_id>', methods=['POST'])
+@login_required
+def process_form(feed_id=None):
form = AddFeedForm()
feed_contr = FeedController(g.user.id)
- if request.method == 'POST':
- if not form.validate():
- return render_template('edit_feed.html', form=form)
- existing_feeds = list(feed_contr.read(link=form.link.data))
- if existing_feeds and feed_id is None:
- flash(gettext("Couldn't add feed: feed already exists."),
- "warning")
- return redirect(url_for('feed.form',
- feed_id=existing_feeds[0].id))
- # Edit an existing feed
- if feed_id is not None:
- feed_contr.update({'id': feed_id},
- {'title': form.title.data,
- 'link': form.link.data,
- 'enabled': form.enabled.data,
- 'site_link': form.site_link.data})
- flash(gettext('Feed %(feed_title)r successfully updated.',
- feed_title=form.title.data), 'success')
- return redirect(url_for('feed.form', feed_id=feed_id))
-
- # Create a new feed
- new_feed = FeedController(g.user.id).create(
- title=form.title.data,
- description="",
- link=form.link.data,
- site_link=form.site_link.data,
- enabled=form.enabled.data)
-
- flash(gettext('Feed %(feed_title)r successfully created.',
- feed_title=new_feed.title), 'success')
-
- if conf.CRAWLING_METHOD == "classic":
- utils.fetch(g.user.id, new_feed.id)
- flash(gettext("Downloading articles for the new feed..."), 'info')
-
- return redirect(url_for('feed.form',
- feed_id=new_feed.id))
+ if not form.validate():
+ return render_template('edit_feed.html', form=form)
+ existing_feeds = list(feed_contr.read(link=form.link.data))
+ if existing_feeds and feed_id is None:
+ flash(gettext("Couldn't add feed: feed already exists."), "warning")
+ return redirect(url_for('feed.form', feed_id=existing_feeds[0].id))
+ # 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': []}
+
+ for filter_attr in ('type', 'pattern', 'action on', 'action'):
+ for i, value in enumerate(
+ request.form.getlist(filter_attr.replace(' ', '_'))):
+ if i >= len(feed_attr['filters']):
+ feed_attr['filters'].append({})
+ feed_attr['filters'][i][filter_attr] = value
- # Getting the form for an existing feed
if feed_id is not None:
- feed = FeedController(g.user.id).get(id=feed_id)
- form = AddFeedForm(obj=feed)
- return render_template('edit_feed.html',
- action=gettext("Edit the feed"),
- form=form, feed=feed)
-
- # Return an empty form in order to create a new feed
- return render_template('edit_feed.html', action=gettext("Add a feed"),
- form=form)
+ feed_contr.update({'id': feed_id}, feed_attr)
+ flash(gettext('Feed %(feed_title)r successfully updated.',
+ feed_title=feed_attr['title']), 'success')
+ return redirect(url_for('feed.form', feed_id=feed_id))
+
+ # Create a new feed
+ new_feed = FeedController(g.user.id).create(**feed_attr)
+
+ flash(gettext('Feed %(feed_title)r successfully created.',
+ feed_title=new_feed.title), 'success')
+
+ if conf.CRAWLING_METHOD == "classic":
+ utils.fetch(g.user.id, new_feed.id)
+ flash(gettext("Downloading articles for the new feed..."), 'info')
+
+ return redirect(url_for('feed.form', feed_id=new_feed.id))
bgstack15