Skip to content

Commit

Permalink
Merge pull request #62 from Aristotle-Metadata-Enterprises/json-support
Browse files Browse the repository at this point in the history
Add lookup support
  • Loading branch information
LegoStormtroopr authored Jan 1, 2022
2 parents c8166d1 + f71632f commit 728e398
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
73 changes: 71 additions & 2 deletions garnett/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,36 @@ def process_rhs(self, compiler, connection):


@TranslatedKeyTransform.register_lookup
class KeyTransformExact(json.KeyTransformExact):
class KeyTransformExact(json.KeyTransformTextLookupMixin, lookups.Exact):
def process_lhs(self, compiler, connection):
self.lhs = Cast(self.lhs, CharField())
return super().process_lhs(compiler, connection)

def process_rhs(self, compiler, connection):
self.rhs = Cast(self.lhs, CharField())
return super().process_rhs(compiler, connection)


@TranslatedKeyTransform.register_lookup
class KeyTransformGreaterThan(json.KeyTransformTextLookupMixin, lookups.GreaterThan):
def process_lhs(self, compiler, connection):
self.lhs = Cast(self.lhs, CharField())
return super().process_lhs(compiler, connection)

def process_rhs(self, compiler, connection):
return super().process_rhs(compiler, connection)


@TranslatedKeyTransform.register_lookup
class KeyTransformGreaterThanOrEqual(
json.KeyTransformTextLookupMixin, lookups.GreaterThanOrEqual
):
def process_lhs(self, compiler, connection):
self.lhs = Cast(self.lhs, CharField())
return super().process_lhs(compiler, connection)

def process_rhs(self, compiler, connection):
return super().process_rhs(compiler, connection)


@TranslatedField.register_lookup
class BaseLanguageStartsWith(CurrentLanguageMixin, json.KeyTransformStartsWith):
Expand Down Expand Up @@ -189,6 +210,54 @@ def process_rhs(self, compiler, connection):
return super().process_rhs(compiler, connection)


@TranslatedField.register_lookup
class BaseLanguageGreaterThan(
CurrentLanguageMixin, json.KeyTransformTextLookupMixin, lookups.GreaterThan
):
def process_lhs(self, compiler, connection):
self.lhs = Cast(self.lhs, CharField())
return super().process_lhs(compiler, connection)

def process_rhs(self, compiler, connection):
return super().process_rhs(compiler, connection)


@TranslatedField.register_lookup
class BaseLanguageGreaterThanOrEqual(
CurrentLanguageMixin, json.KeyTransformTextLookupMixin, lookups.GreaterThanOrEqual
):
def process_lhs(self, compiler, connection):
self.lhs = Cast(self.lhs, CharField())
return super().process_lhs(compiler, connection)

def process_rhs(self, compiler, connection):
return super().process_rhs(compiler, connection)


@TranslatedField.register_lookup
class BaseLanguageLessThan(
CurrentLanguageMixin, json.KeyTransformTextLookupMixin, lookups.LessThan
):
def process_lhs(self, compiler, connection):
self.lhs = Cast(self.lhs, CharField())
return super().process_lhs(compiler, connection)

def process_rhs(self, compiler, connection):
return super().process_rhs(compiler, connection)


@TranslatedField.register_lookup
class BaseLanguageLessThanOrEqual(
CurrentLanguageMixin, json.KeyTransformTextLookupMixin, lookups.LessThanOrEqual
):
def process_lhs(self, compiler, connection):
self.lhs = Cast(self.lhs, CharField())
return super().process_lhs(compiler, connection)

def process_rhs(self, compiler, connection):
return super().process_rhs(compiler, connection)


@TranslatedField.register_lookup
class BaseLanguageSearch(
CurrentLanguageMixin, json.KeyTransformTextLookupMixin, SearchLookup
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-garnett"
version = "0.4.1"
version = "0.4.2"
description = "Simple translatable Django fields"
authors = ["Aristotle Metadata Enterprises"]
license = "BSD-3-Clause"
Expand Down

0 comments on commit 728e398

Please sign in to comment.