Extract topic_match_sa() helper.

We'll also use this in zerver/views/messages.py, but
that's a bigger change.
This commit is contained in:
Steve Howell
2018-11-01 20:48:49 +00:00
committed by Tim Abbott
parent df743e8948
commit 79d5e36ca3
3 changed files with 18 additions and 3 deletions

View File

@@ -4,6 +4,11 @@ from django.db import connection
from django.db.models.query import QuerySet, Q
from django.utils.timezone import now as timezone_now
from sqlalchemy.sql import (
column,
func,
)
from zerver.models import (
Message,
Recipient,
@@ -18,6 +23,12 @@ TOPIC_NAME = "subject"
TOPIC_LINKS = "subject_links"
PREV_TOPIC = "prev_subject"
def topic_match_sa(topic_name: str) -> Any:
# _sa is short for Sql Alchemy, which we use mostly for
# queries that search messages
topic_cond = func.upper(column("subject")) == func.upper(topic_name)
return topic_cond
def filter_by_exact_message_topic(query: QuerySet, message: Message) -> QuerySet:
topic_name = message.topic_name()
return query.filter(subject=topic_name)