aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/controllers/abstract.py
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-03-01 03:20:12 +0100
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-03-03 22:23:02 +0100
commit5572851eca3b2f1bc56aed7232284acc436d2f49 (patch)
treeb8f425333804ca06a4a16600b4c4c0bfcdf4cff7 /pyaggr3g470r/controllers/abstract.py
parentcontinuing refacto (diff)
downloadnewspipe-5572851eca3b2f1bc56aed7232284acc436d2f49.tar.gz
newspipe-5572851eca3b2f1bc56aed7232284acc436d2f49.tar.bz2
newspipe-5572851eca3b2f1bc56aed7232284acc436d2f49.zip
new crawler with cache control and error handling
Diffstat (limited to 'pyaggr3g470r/controllers/abstract.py')
-rw-r--r--pyaggr3g470r/controllers/abstract.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/pyaggr3g470r/controllers/abstract.py b/pyaggr3g470r/controllers/abstract.py
index 6fe45461..ebb73e30 100644
--- a/pyaggr3g470r/controllers/abstract.py
+++ b/pyaggr3g470r/controllers/abstract.py
@@ -1,5 +1,9 @@
+import logging
from bootstrap import db
-from pyaggr3g470r.lib.exceptions import Forbidden, NotFound
+from sqlalchemy import update
+from werkzeug.exceptions import Forbidden, NotFound
+
+logger = logging.getLogger(__name__)
class AbstractController(object):
@@ -9,7 +13,7 @@ class AbstractController(object):
def __init__(self, user_id):
self.user_id = user_id
- def _get(self, **filters):
+ def _to_filters(self, **filters):
if self.user_id:
filters[self._user_id_key] = self.user_id
db_filters = set()
@@ -28,7 +32,10 @@ class AbstractController(object):
db_filters.add(getattr(self._db_cls, key[:-4]).in_(value))
else:
db_filters.add(getattr(self._db_cls, key) == value)
- return self._db_cls.query.filter(*db_filters)
+ return db_filters
+
+ def _get(self, **filters):
+ return self._db_cls.query.filter(*self._to_filters(**filters))
def get(self, **filters):
obj = self._get(**filters).first()
@@ -41,7 +48,9 @@ class AbstractController(object):
return obj
def create(self, **attrs):
+ attrs['user_id'] = self.user_id
obj = self._db_cls(**attrs)
+ db.session.add(obj)
db.session.commit()
return obj
bgstack15