generated from yunojuno/poetry-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6cbc52
commit a45225f
Showing
6 changed files
with
139 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any, Callable | ||
|
||
from django.db import models | ||
from django.utils import timezone | ||
|
||
from anonymiser.db.functions import GenerateUuid4 | ||
|
||
|
||
def default_redact_charfield(field: models.CharField) -> str: | ||
return "X" * field.max_length | ||
|
||
|
||
def default_redact_textfield(field: models.TextField) -> str: | ||
return "X" * 400 | ||
|
||
|
||
def default_redact_datefield(field: models.DateField) -> str: | ||
return timezone.now().date().isoformat() | ||
|
||
|
||
def default_redact_datetimefield(field: models.DateTimeField) -> str: | ||
return timezone.now().isoformat() | ||
|
||
|
||
def default_redact_jsonfield(field: models.JSONField) -> dict[str, Any]: | ||
return {} | ||
|
||
|
||
def default_redact_uuidfield(field: models.UUIDField) -> str: | ||
return GenerateUuid4() | ||
|
||
|
||
def get_default_field_redacter( | ||
field: models.Field, | ||
) -> Callable[[models.Field], Any] | None: | ||
"""Return default redacter for basic Django field types.""" | ||
if isinstance(field, models.CharField): | ||
return default_redact_charfield | ||
if isinstance(field, models.TextField): | ||
return default_redact_textfield | ||
if isinstance(field, models.DateField): | ||
return default_redact_datefield | ||
if isinstance(field, models.DateTimeField): | ||
return default_redact_datetimefield | ||
if isinstance(field, models.JSONField): | ||
return default_redact_jsonfield | ||
if isinstance(field, models.UUIDField): | ||
return default_redact_uuidfield | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2.5 on 2023-10-02 15:40 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("tests", "0003_user_biography_user_date_of_birth_user_location"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="user", | ||
name="extra_info", | ||
field=models.JSONField(default=dict), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters