diff options
author | Cédric Bonhomme <kimble.mandel+bitbucket@gmail.com> | 2015-04-17 00:34:45 +0200 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel+bitbucket@gmail.com> | 2015-04-17 00:34:45 +0200 |
commit | 6199b9ef59583d580f1b83afa436c0ccd60ddb76 (patch) | |
tree | 1f5aad5dd88763f791c7d27a16ed44d1684f229d /pyaggr3g470r/controllers | |
parent | 'CRAWLING_METHOD wasn't initialized on Heroku. (diff) | |
parent | facto on config and more option in log levels (diff) | |
download | newspipe-6199b9ef59583d580f1b83afa436c0ccd60ddb76.tar.gz newspipe-6199b9ef59583d580f1b83afa436c0ccd60ddb76.tar.bz2 newspipe-6199b9ef59583d580f1b83afa436c0ccd60ddb76.zip |
Merged in jaesivsm/pyaggr3g470r (pull request #10)
misc fix and search integration in the new style page
Diffstat (limited to 'pyaggr3g470r/controllers')
-rw-r--r-- | pyaggr3g470r/controllers/abstract.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/pyaggr3g470r/controllers/abstract.py b/pyaggr3g470r/controllers/abstract.py index 8f0a8e3f..9a9004af 100644 --- a/pyaggr3g470r/controllers/abstract.py +++ b/pyaggr3g470r/controllers/abstract.py @@ -1,5 +1,6 @@ import logging from bootstrap import db +from sqlalchemy import or_ from werkzeug.exceptions import Forbidden, NotFound logger = logging.getLogger(__name__) @@ -25,13 +26,13 @@ class AbstractController(object): each parameters of the function is treated as an equality unless the name of the parameter ends with either "__gt", "__lt", "__ge", "__le", - "__ne" or "__in". + "__ne", "__in" ir "__like". """ - if self.user_id is not None: - filters[self._user_id_key] = self.user_id db_filters = set() for key, value in filters.items(): - if key.endswith('__gt'): + if key == '__or__': + db_filters.add(or_(*self._to_filters(**value))) + elif key.endswith('__gt'): db_filters.add(getattr(self._db_cls, key[:-4]) > value) elif key.endswith('__lt'): db_filters.add(getattr(self._db_cls, key[:-4]) < value) @@ -43,11 +44,15 @@ class AbstractController(object): db_filters.add(getattr(self._db_cls, key[:-4]) != value) elif key.endswith('__in'): db_filters.add(getattr(self._db_cls, key[:-4]).in_(value)) + elif key.endswith('__like'): + db_filters.add(getattr(self._db_cls, key[:-6]).like(value)) else: db_filters.add(getattr(self._db_cls, key) == value) return db_filters def _get(self, **filters): + if self.user_id is not None: + filters[self._user_id_key] = self.user_id return self._db_cls.query.filter(*self._to_filters(**filters)) def get(self, **filters): |