Skip to content

Commit 520b319

Browse files
committed
Code formatting, doc updates, CI updates
1 parent 698c0d9 commit 520b319

File tree

6 files changed

+61
-50
lines changed

6 files changed

+61
-50
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
django-version: ["4.2", "5.0", "5.1"]
30-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
30+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
3131
exclude:
32-
- python-version: "3.8"
33-
django-version: "5.0"
3432
- python-version: "3.9"
3533
django-version: "5.0"
36-
- python-version: "3.8"
37-
django-version: "5.1"
3834
- python-version: "3.9"
3935
django-version: "5.1"
4036
steps:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.0.2
44

55
* Added `Encrypt` and `Decrypt` Django functions (https://github.com/dcwatson/django-pgcrypto/pull/36)
6+
* Added `contains`, `icontains`, `startswith`, `istartswith`, `endswith`, and `iendswith` filter support (https://github.com/dcwatson/django-pgcrypto/pull/37)
67

78

89
## 3.0.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ You must also make sure the pgcrypto extension is installed in your database. Dj
3232

3333
## Querying
3434

35-
It is possible to filter on encrypted fields as you would normal fields via `exact`, `gt`, `gte`, `lt`, and `lte` lookups. For example, querying the model above is possible like so:
35+
It is possible to filter on encrypted fields as you would normal fields via `exact`, `gt`, `gte`, `lt`, `lte`, `contains`, `icontains`, `startswith`, `istartswith`, `endswith`, and `iendswith` lookups. For example, querying the model above is possible like so:
3636

3737
```python
3838
Employee.objects.filter(date_hired__gt="1981-01-01", salary__lt=60000)

pgcrypto/fields.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ def as_postgresql(self, qn, connection):
285285
)
286286
field_internal_type = self.lhs.output_field.get_internal_type()
287287
field_sql = (
288-
connection.ops.lookup_cast(self.lookup_name, field_internal_type) % field_sql
288+
connection.ops.lookup_cast(self.lookup_name, field_internal_type)
289+
% field_sql
289290
)
290291

291292
if (
@@ -294,9 +295,9 @@ def as_postgresql(self, qn, connection):
294295
and rhs_params
295296
and not self.bilateral_transforms
296297
):
297-
rhs_params[0] = self.patterns[self.lookup_name] % connection.ops.prep_for_like_query(
298-
rhs_params[0]
299-
)
298+
rhs_params[0] = self.patterns[
299+
self.lookup_name
300+
] % connection.ops.prep_for_like_query(rhs_params[0])
300301

301302
return (
302303
"%s%s %s"
@@ -317,7 +318,19 @@ class EncryptedInLookup(FieldGetDbPrepValueIterableMixin, EncryptedLookup):
317318
lookup_name = "in"
318319

319320

320-
for lookup_name in ("exact", "gt", "gte", "lt", "lte", 'contains', 'icontains', 'startswith', 'istartswith', 'endswith', 'iendswith'):
321+
for lookup_name in (
322+
"exact",
323+
"gt",
324+
"gte",
325+
"lt",
326+
"lte",
327+
"contains",
328+
"icontains",
329+
"startswith",
330+
"istartswith",
331+
"endswith",
332+
"iendswith",
333+
):
321334
class_name = "EncryptedLookup_%s" % lookup_name
322335
lookup_class = type(class_name, (EncryptedLookup,), {"lookup_name": lookup_name})
323336
BaseEncryptedField.register_lookup(lookup_class)

testapp/tests.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,27 +262,26 @@ def test_concat_decrypt(self):
262262
).get(ssn="999-05-6728")
263263
self.assertEqual(employee.value, "999-05-6728 - 42")
264264

265-
266265
def test_contains(self):
267-
employee = Employee.objects.filter(email__contains='sal').get()
266+
employee = Employee.objects.filter(email__contains="sal").get()
268267
self.assertEqual(employee.email, "[email protected]")
269268

270269
def test_icontains(self):
271-
employee = Employee.objects.filter(email__icontains='SAL').get()
270+
employee = Employee.objects.filter(email__icontains="SAL").get()
272271
self.assertEqual(employee.email, "[email protected]")
273272

274273
def test_startswith(self):
275-
employee = Employee.objects.filter(email__startswith='john').get()
274+
employee = Employee.objects.filter(email__startswith="john").get()
276275
self.assertEqual(employee.email, "[email protected]")
277276

278277
def test_istartswith(self):
279-
employee = Employee.objects.filter(email__istartswith='JOHN').get()
278+
employee = Employee.objects.filter(email__istartswith="JOHN").get()
280279
self.assertEqual(employee.email, "[email protected]")
281280

282281
def test_endswith(self):
283-
employee = Employee.objects.filter(email__endswith='com').get()
282+
employee = Employee.objects.filter(email__endswith="com").get()
284283
self.assertEqual(employee.email, "[email protected]")
285284

286285
def test_iendswith(self):
287-
employee = Employee.objects.filter(email__iendswith='COM').get()
286+
employee = Employee.objects.filter(email__iendswith="COM").get()
288287
self.assertEqual(employee.email, "[email protected]")

0 commit comments

Comments
 (0)