From 82a935080d1c6a3214a63cbbee26a1827f6f368b Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 5 Mar 2014 12:41:01 -0500 Subject: [PATCH] Support has:* searches on the back end. (imported from commit a6a6f465ce0343d4a5313ee54f6ff427940a03ab) --- zerver/test_messages.py | 9 +++++++++ zerver/views/messages.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/zerver/test_messages.py b/zerver/test_messages.py index 23aa4901ee..5363f2eec8 100644 --- a/zerver/test_messages.py +++ b/zerver/test_messages.py @@ -96,6 +96,15 @@ class NarrowBuilderTest(AuthedTestCase): term = dict(operator='search', operand='"french fries"') check(term, 'WHERE (lower(content) LIKE lower(:content_1) OR lower(subject) LIKE lower(:subject_1)) AND (search_tsvector @@ plainto_tsquery(:param_2, :param_3))') + term = dict(operator='has', operand='attachment') + check(term, 'WHERE has_attachment') + + term = dict(operator='has', operand='image') + check(term, 'WHERE has_image') + + term = dict(operator='has', operand='link') + check(term, 'WHERE has_link') + class IncludeHistoryTest(AuthedTestCase): def test_ok_to_include_history(self): realm = get_realm('zulip.com') diff --git a/zerver/views/messages.py b/zerver/views/messages.py index e008b2402b..3888296923 100644 --- a/zerver/views/messages.py +++ b/zerver/views/messages.py @@ -111,6 +111,13 @@ class NarrowBuilder(object): return method(query, operand, maybe_negate) + def by_has(self, query, operand, maybe_negate): + if operand not in ['attachment', 'image', 'link']: + raise BadNarrowOperator("unknown 'has' operand " + operand) + col_name = 'has_' + operand + cond = column(col_name) + return query.where(maybe_negate(cond)) + def by_is(self, query, operand, maybe_negate): if operand == 'private': query = query.select_from(join(query.froms[0], "zerver_recipient",