diff options
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): |