Skip to content

Commit

Permalink
add func get_encrypted_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jul 20, 2023
1 parent 30c2713 commit abfbe54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
rev: 23.3.0
hooks:
- id: black
language_version: python3.9
language_version: python3.10

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
Expand Down
18 changes: 17 additions & 1 deletion django_crypto_fields/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
def has_encrypted_fields(model):
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .fields import BaseField


def has_encrypted_fields(model) -> bool:
for field in model._meta.get_fields():
if hasattr(field, "field_cryptor"):
return True
return False


def get_encrypted_fields(model) -> list[BaseField]:
encrypted_fields = []
for field in model._meta.get_fields():
if hasattr(field, "field_cryptor"):
encrypted_fields.append(field)
return encrypted_fields

0 comments on commit abfbe54

Please sign in to comment.