Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Register custom __andz, __andnz lookups.
Anders Kaseorgbbca3d048cad
diff --git a/zerver/models.py b/zerver/models.pyindex 673cb836462..dd29f74fb6e 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -29,9 +29,11 @@ from django.contrib.contenttypes.fields import GenericRelationfrom django.core.exceptions import ValidationErrorfrom django.core.validators import MinLengthValidator, RegexValidator, URLValidator, validate_emailfrom django.db import models, transaction+from django.db.backends.base.base import BaseDatabaseWrapperfrom django.db.models import CASCADE, Manager, Q, Sumfrom django.db.models.query import QuerySetfrom django.db.models.signals import post_delete, post_save, pre_delete+from django.db.models.sql.compiler import SQLCompilerfrom django.utils.functional import Promisefrom django.utils.timezone import now as timezone_nowfrom django.utils.translation import gettext as _@@ -110,6 +112,30 @@ class EmojiInfo(TypedDict):still_url: Optional[str][email protected]_lookup+class AndZero(models.Lookup):+ lookup_name = "andz"++ def as_sql(+ self, compiler: SQLCompiler, connection: BaseDatabaseWrapper+ ) -> Tuple[str, List[object]]: # nocoverage # currently only used in migrations+ lhs, lhs_params = self.process_lhs(compiler, connection)+ rhs, rhs_params = self.process_rhs(compiler, connection)+ return f"{lhs} & {rhs} = 0", lhs_params + rhs_params++[email protected]_lookup+class AndNonZero(models.Lookup):+ lookup_name = "andnz"++ def as_sql(+ self, compiler: SQLCompiler, connection: BaseDatabaseWrapper+ ) -> Tuple[str, List[object]]: # nocoverage # currently only used in migrations+ lhs, lhs_params = self.process_lhs(compiler, connection)+ rhs, rhs_params = self.process_rhs(compiler, connection)+ return f"{lhs} & {rhs} != 0", lhs_params + rhs_params++def query_for_ids(query: QuerySet, user_ids: List[int], field: str) -> QuerySet:"""This function optimizes searches of the form