From e3499ba1dab00c7f6fac834dcb8dbd5379e7f921 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 7 Jul 2014 21:30:45 +0200 Subject: It is now possible to add new feeds with a bookmarklet. --- pyaggr3g470r/models.py | 4 ++-- pyaggr3g470r/templates/about.html | 13 ++++++++++++- pyaggr3g470r/views.py | 12 +++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py index 63d547a9..5139c1d4 100644 --- a/pyaggr3g470r/models.py +++ b/pyaggr3g470r/models.py @@ -99,10 +99,10 @@ class Feed(db.Model): Represent a station. """ id = db.Column(db.Integer, primary_key = True) - title = db.Column(db.String(), default="New station") + title = db.Column(db.String(), default="No title") description = db.Column(db.String(), default="FR") link = db.Column(db.String()) - site_link = db.Column(db.String(), default="New station") + site_link = db.Column(db.String(), default="") email_notification = db.Column(db.Boolean(), default=False) enabled = db.Column(db.Boolean(), default=True) created_date = db.Column(db.DateTime(), default=datetime.now) diff --git a/pyaggr3g470r/templates/about.html b/pyaggr3g470r/templates/about.html index 3c4304e5..0a33e9aa 100644 --- a/pyaggr3g470r/templates/about.html +++ b/pyaggr3g470r/templates/about.html @@ -2,11 +2,22 @@ {% block content %}
+

{{ _('About') }}

{{ _('pyAggr3g470r is a simple news aggregator you can use everywhere.') }}

{{ _('This software is under AGPLv3 license. You are welcome to copy, modify or redistribute the source code according to the Affero GPL license.') }}

{{ _('Found a bug? Report it here.') }}

+
+

{{ _('Help') }}

+

{{ _('If you have any problem, contact the adminstrator.') }}

+

{{ _('The documentation of the RESTful API is here.') }}

+

{{ _('You can subscribe to new feeds with a bookmarklet. Drag this link to your browser bookmarks.', bookmarklet='javascript:window.location="https://pyaggr3g470r.herokuapp.com/bookmarklet?url="+encodeURIComponent(document.location)') }}

+
+
+

{{ _('Donation') }}

+

{{ _('If you wish and if you like pyAggr3g470r, you can donate via bitcoin 1GVmhR9fbBeEh7rP1qNq76jWArDdDQ3otZ. Thank you!') }}

+
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 9081795e..2478a86f 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -29,7 +29,7 @@ __license__ = "AGPLv3" import os import datetime from flask import abort, render_template, request, flash, session, \ - url_for, redirect, g, current_app, make_response + url_for, redirect, g, current_app, make_response, jsonify from flask.ext.login import LoginManager, login_user, logout_user, \ login_required, current_user, AnonymousUserMixin from flask.ext.principal import Principal, Identity, AnonymousIdentity, \ @@ -629,6 +629,7 @@ def history(): user = User.query.filter(User.id == g.user.id).first() return render_template('history.html') +@app.route('/bookmarklet', methods=['GET']) @app.route('/create_feed', methods=['GET', 'POST']) @app.route('/edit_feed/', methods=['GET', 'POST']) @login_required @@ -675,6 +676,15 @@ def edit_feed(feed_id=None): return render_template('edit_feed.html', action=gettext("Edit the feed"), form=form, feed=feed, \ not_on_heroku = not conf.ON_HEROKU) + # Enable the user to add a feed with a bookmarklet + if None is not request.args.get('url', None): + existing_feed = [feed for feed in g.user.feeds if feed.link == request.args.get('url', None)] + if len(existing_feed) == 0: + g.user.feeds.append(Feed(link=request.args.get('url', None))) + db.session.commit() + return jsonify({"message":"ok"}) + return jsonify({"message":"Feed already in the database."}) + # Return an empty form in order to create a new feed return render_template('edit_feed.html', action=gettext("Add a feed"), form=form, \ not_on_heroku = not conf.ON_HEROKU) -- cgit