aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2015-04-01 22:57:15 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2015-04-01 22:57:15 +0200
commit854862e1c73bf0c521e08b8973721e8be7aeb82e (patch)
tree7f976931e7c9f121a5fe6791e61bb531ac401e72 /pyaggr3g470r
parentAdded customized-bootstrap.css file. (diff)
downloadnewspipe-854862e1c73bf0c521e08b8973721e8be7aeb82e.tar.gz
newspipe-854862e1c73bf0c521e08b8973721e8be7aeb82e.tar.bz2
newspipe-854862e1c73bf0c521e08b8973721e8be7aeb82e.zip
Bugfix.
Diffstat (limited to 'pyaggr3g470r')
-rwxr-xr-xpyaggr3g470r/utils.py16
-rw-r--r--pyaggr3g470r/views/views.py4
2 files changed, 15 insertions, 5 deletions
diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py
index 5f2d8707..ea8a87bf 100755
--- a/pyaggr3g470r/utils.py
+++ b/pyaggr3g470r/utils.py
@@ -56,11 +56,21 @@ from contextlib import contextmanager
import conf
from flask import g
+from bootstrap import application as app, db
from pyaggr3g470r import controllers
from pyaggr3g470r.models import User, Feed, Article
logger = logging.getLogger(__name__)
+ALLOWED_EXTENSIONS = set(['xml', 'opml', 'json'])
+
+def allowed_file(filename):
+ """
+ Check if the uploaded file is allowed.
+ """
+ return '.' in filename and \
+ filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
+
@contextmanager
def opened_w_error(filename, mode="r"):
try:
@@ -143,7 +153,7 @@ def import_opml(email, opml_content):
nb += 1
return nb
nb = read(subscriptions)
- g.db.session.commit()
+ db.session.commit()
return nb
def import_json(email, json_content):
@@ -167,7 +177,7 @@ def import_json(email, json_content):
enabled=feed["enabled"])
user.feeds.append(new_feed)
nb_feeds += 1
- g.db.session.commit()
+ db.session.commit()
# Create articles:
for feed in json_account["result"]:
user_feed = Feed.query.filter(Feed.user_id == user.id,
@@ -190,7 +200,7 @@ def import_json(email, json_content):
feed_id=user_feed.id)
user_feed.articles.append(new_article)
nb_articles += 1
- g.db.session.commit()
+ db.session.commit()
return nb_feeds, nb_articles
def clean_url(url):
diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py
index f77bdeba..3b39e9b0 100644
--- a/pyaggr3g470r/views/views.py
+++ b/pyaggr3g470r/views/views.py
@@ -510,7 +510,7 @@ def management():
if None != request.files.get('opmlfile', None):
# Import an OPML file
data = request.files.get('opmlfile', None)
- if not g.allowed_file(data.filename):
+ if not utils.allowed_file(data.filename):
flash(gettext('File not allowed.'), 'danger')
else:
try:
@@ -523,7 +523,7 @@ def management():
elif None != request.files.get('jsonfile', None):
# Import an account
data = request.files.get('jsonfile', None)
- if not g.allowed_file(data.filename):
+ if not utils.allowed_file(data.filename):
flash(gettext('File not allowed.'), 'danger')
else:
try:
bgstack15