aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/controllers/abstract.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-05-15 07:24:18 +0200
committerCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-05-15 07:24:18 +0200
commitdd059ad8a7d94ea6d03639e10e4d41c95dd1cebd (patch)
tree8aa3c0bf481a67717987af0710540668d3467ab0 /pyaggr3g470r/controllers/abstract.py
parentThe list of inactive feeds is now sorted. (diff)
parenttesting special controller methods (diff)
downloadnewspipe-dd059ad8a7d94ea6d03639e10e4d41c95dd1cebd.tar.gz
newspipe-dd059ad8a7d94ea6d03639e10e4d41c95dd1cebd.tar.bz2
newspipe-dd059ad8a7d94ea6d03639e10e4d41c95dd1cebd.zip
Merged in jaesivsm/pyaggr3g470r (pull request #13)
introducing unittests !
Diffstat (limited to 'pyaggr3g470r/controllers/abstract.py')
-rw-r--r--pyaggr3g470r/controllers/abstract.py17
1 files changed, 10 insertions, 7 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):
bgstack15