aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/controllers/abstract.py17
-rw-r--r--pyaggr3g470r/lib/crawler.py6
-rw-r--r--pyaggr3g470r/models/__init__.py3
-rw-r--r--pyaggr3g470r/models/article.py11
-rw-r--r--pyaggr3g470r/views/views.py15
5 files changed, 29 insertions, 23 deletions
diff --git a/pyaggr3g470r/controllers/abstract.py b/pyaggr3g470r/controllers/abstract.py
index 3ea4fbff..f67f932c 100644
--- a/pyaggr3g470r/controllers/abstract.py
+++ b/pyaggr3g470r/controllers/abstract.py
@@ -19,9 +19,12 @@ class AbstractController(object):
allowing for a kind of "super user" mode.
"""
self.user_id = user_id
- if self.user_id is not None \
- and self.user_id != g.user.id and not g.user.is_admin():
- self.user_id = g.user.id
+ try:
+ if self.user_id is not None \
+ and self.user_id != g.user.id and not g.user.is_admin():
+ self.user_id = g.user.id
+ except RuntimeError: # passing on out of context errors
+ pass
def _to_filters(self, **filters):
"""
@@ -67,13 +70,13 @@ class AbstractController(object):
def get(self, **filters):
"""Will return one single objects corresponding to filters"""
obj = self._get(**filters).first()
- if not obj:
- raise NotFound({'message': 'No %r (%r)'
- % (self._db_cls.__class__.__name__, filters)})
- if not self._has_right_on(obj):
+ if obj and not self._has_right_on(obj):
raise Forbidden({'message': 'No authorized to access %r (%r)'
% (self._db_cls.__class__.__name__, filters)})
+ if not obj:
+ raise NotFound({'message': 'No %r (%r)'
+ % (self._db_cls.__class__.__name__, filters)})
return obj
def create(self, **attrs):
diff --git a/pyaggr3g470r/lib/crawler.py b/pyaggr3g470r/lib/crawler.py
index cae3bd8f..c4c80ad4 100644
--- a/pyaggr3g470r/lib/crawler.py
+++ b/pyaggr3g470r/lib/crawler.py
@@ -225,9 +225,9 @@ class FeedCrawler(AbstractCrawler):
response.raise_for_status()
except Exception as error:
error_count = self.feed['error_count'] + 1
- logger.warn('%r %r - an error occured while fetching feed; bumping'
- ' error count to %r', self.feed['id'],
- self.feed['title'], error_count)
+ logger.error('%r %r - an error occured while fetching '
+ 'feed; bumping error count to %r', self.feed['id'],
+ self.feed['title'], error_count)
future = self.query_pyagg('put', 'feed/%d' % self.feed['id'],
{'error_count': error_count,
'last_error': str(error)})
diff --git a/pyaggr3g470r/models/__init__.py b/pyaggr3g470r/models/__init__.py
index 42903f4e..ba52b0de 100644
--- a/pyaggr3g470r/models/__init__.py
+++ b/pyaggr3g470r/models/__init__.py
@@ -98,4 +98,5 @@ def db_create(db):
user1.roles.extend([role_admin, role_user])
db.session.add(user1)
- db.session.commit() \ No newline at end of file
+ db.session.commit()
+ return role_admin, role_user
diff --git a/pyaggr3g470r/models/article.py b/pyaggr3g470r/models/article.py
index 58cd0384..16f15b9e 100644
--- a/pyaggr3g470r/models/article.py
+++ b/pyaggr3g470r/models/article.py
@@ -66,14 +66,15 @@ class Article(db.Model):
.order_by(asc("Article.date")).first()
def __repr__(self):
- return json.dumps({
- "title": self.title,
- "link": self.link,
- "content": self.content
- })
+ return json.dumps({"title": self.title,
+ "link": self.link,
+ "content": self.content
+ })
def dump(self):
return {"id": self.id,
+ "user_id": self.user_id,
+ "entry_id": self.entry_id,
"title": self.title,
"link": self.link,
"content": self.content,
diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py
index 1b834d0e..3abc76df 100644
--- a/pyaggr3g470r/views/views.py
+++ b/pyaggr3g470r/views/views.py
@@ -169,7 +169,6 @@ def login():
session['email'] = form.email.data
identity_changed.send(current_app._get_current_object(),
identity=Identity(user.id))
- flash(gettext("Logged in successfully."), 'success')
return redirect(url_for('home'))
return render_template('login.html', form=form)
@@ -190,7 +189,8 @@ def logout():
session.pop(key, None)
# Tell Flask-Principal the user is anonymous
- identity_changed.send(current_app._get_current_object(), identity=AnonymousIdentity())
+ identity_changed.send(current_app._get_current_object(),
+ identity=AnonymousIdentity())
flash(gettext("Logged out successfully."), 'success')
return redirect(url_for('login'))
@@ -224,8 +224,9 @@ def signup():
# Send the confirmation email
try:
notifications.new_account_notification(user)
- except Exception as e:
- flash(gettext('Problem while sending activation email') + ': ' + str(e), 'danger')
+ except Exception as error:
+ flash(gettext('Problem while sending activation email: %(error)s',
+ error=error), 'danger')
return redirect(url_for('home'))
flash(gettext('Your account has been created. '
@@ -286,9 +287,9 @@ def render_home(filters=None, head_titles=None,
if page_to_render == 'search':
kwargs['query'] = request.args.get('query', '')
kwargs['search_title'] = request.args.get('search_title', 'off')
- kwargs['search_content'] = request.args.get('search_content', 'off')
- if kwargs['search_title']=='off' and \
- kwargs['search_content']=='off':
+ kwargs['search_content'] = request.args.get(
+ 'search_content', 'off')
+ if kwargs['search_title'] == kwargs['search_content'] == 'off':
kwargs['search_title'] = 'on'
return url_for(page_to_render, filter_=filter_, sort_=sort_,
limit=limit, feed_id=feed_id, **kwargs)
bgstack15