aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-04-16 08:58:11 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-04-16 11:37:57 +0200
commita3c2bd47e6d9a64539000d4921ee58eed1ea3968 (patch)
tree479560e61f85ba2546ddb85f9a319a7625f85f9d /pyaggr3g470r
parentredoing full text search (diff)
downloadnewspipe-a3c2bd47e6d9a64539000d4921ee58eed1ea3968.tar.gz
newspipe-a3c2bd47e6d9a64539000d4921ee58eed1ea3968.tar.bz2
newspipe-a3c2bd47e6d9a64539000d4921ee58eed1ea3968.zip
introducing the or filter component
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/controllers/abstract.py9
-rw-r--r--pyaggr3g470r/templates/layout.html1
-rw-r--r--pyaggr3g470r/views/views.py9
3 files changed, 12 insertions, 7 deletions
diff --git a/pyaggr3g470r/controllers/abstract.py b/pyaggr3g470r/controllers/abstract.py
index 29905c0c..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__)
@@ -27,11 +28,11 @@ class AbstractController(object):
name of the parameter ends with either "__gt", "__lt", "__ge", "__le",
"__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)
@@ -50,6 +51,8 @@ class AbstractController(object):
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):
diff --git a/pyaggr3g470r/templates/layout.html b/pyaggr3g470r/templates/layout.html
index 06567953..a54125ea 100644
--- a/pyaggr3g470r/templates/layout.html
+++ b/pyaggr3g470r/templates/layout.html
@@ -106,6 +106,7 @@
<div class="input-group">
{% if filter_ %}<input type="hidden" name="filter_" value="{{ filter_ }}" />{% endif %}
{% if limit %}<input type="hidden" name="limit" value="{{ limit }}" />{% endif %}
+ {% if feed_id %}<input type="hidden" name="feed_id" value="{{ feed_id }}" />{% endif %}
<label for="search_title">{{ _("Title") }}</label>
<input type="checkbox" name="search_title" {% if search_title == 'on' or not (search_title == 'on' or search_content == 'on') %}checked{%endif%}/>
<label for="search_content">{{ _("Content") }}</label>
diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py
index 83012d7c..c681a94d 100644
--- a/pyaggr3g470r/views/views.py
+++ b/pyaggr3g470r/views/views.py
@@ -255,9 +255,8 @@ def render_home(filters={}, head_title='', page_to_render='home', **kwargs):
filters['readed'] = filter_ == 'read'
if feed_id:
filters['feed_id'] = feed_id
- if head_title:
- head_title += ' - '
- head_title += feed_contr.get(id=feed_id).title
+ head_title = "%s%s" % (feed_contr.get(id=feed_id).title,
+ (' - %s' % head_title) if head_title else '')
articles = arti_contr.read(**filters).order_by(Article.date.desc())
if limit != 'all':
@@ -275,7 +274,7 @@ def render_home(filters={}, head_title='', page_to_render='home', **kwargs):
articles = list(articles)
if (page_to_render == 'home' and feed_id or page_to_render == 'search') \
- and not articles:
+ and filter_ != 'all' and not articles:
return redirect(gen_url(filter_='all'))
if sort_ == "feed":
@@ -315,6 +314,8 @@ def search():
filters['title__like'] = "%%%s%%" % query
if search_content == 'on':
filters['content__like'] = "%%%s%%" % query
+ if len(filters) > 1:
+ filters = {"__or__": filters}
return render_home(filters, "%s %s" % (gettext('Search:'), query),
'search', search_query=query, search_title=search_title,
search_content=search_content)
bgstack15