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
2db5ac2
commit 327d210
Showing
5 changed files
with
43 additions
and
31 deletions.
There are no files selected for viewing
14 changes: 3 additions & 11 deletions
14
anonymiser/management/commands/display_model_anonymisation.py
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 |
---|---|---|
@@ -1,24 +1,16 @@ | ||
from typing import Any | ||
|
||
from django.apps import apps | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Model | ||
from django.template.loader import render_to_string | ||
|
||
from anonymiser.registry import get_model_anonymiser | ||
from anonymiser import registry | ||
|
||
|
||
class Command(BaseCommand): | ||
def get_models(self) -> list[type[Model]]: | ||
"""Force alphabetical order of models.""" | ||
return sorted(apps.get_models(), key=lambda m: m._meta.label) | ||
|
||
def handle(self, *args: Any, **options: Any) -> None: | ||
for model in self.get_models(): | ||
if anonymiser := get_model_anonymiser(model): | ||
data = anonymiser.get_model_field_summary() | ||
model_fields = registry.get_all_model_fields() | ||
out = render_to_string( | ||
"display_model_anonymisation.md", | ||
{"anonymised_models": data}, | ||
{"model_fields": model_fields}, | ||
) | ||
self.stdout.write(out) |
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
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 |
---|---|---|
@@ -1,11 +1,4 @@ | ||
# Model Anonymisation Snapshot | ||
|
||
## Registered model anonymisers | ||
Model | Anonymiser | ||
--- | ---{% for model,anonymiser in model_anonymisers.items %} | ||
{{ model }} | {{ anonymiser|default:"-" }} {% endfor %} | ||
|
||
## Model field anonymisation | ||
App | Model | Field | Type | Anonymise | Redacte | ||
--- | --- | --- | --- | --- | ---{% for field in anonymised_models %} | ||
{{ field.app }} | {{ field.model }} | {{ field.field_name }} | {{ field.field_type }} | {% if field.is_anonymised %}X{% else %}-{% endif %} | {{ field.redaction_strategy|default:"-" }}{% endfor %} | ||
--- | --- | --- | --- | --- | ---{% for model,fields in anonymised_models.items %}{% for field in fields %} | ||
{{ field.app }} | {{ field.model }} | {{ field.field_name }} | {{ field.field_type }} | {{ field.is_anonymised|default:"-" }} | {{ field.redaction_strategy|default:"-"|upper }}{% endfor %}{% endfor %} |
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