From 7032a16ab9e8df723abbe2dc9baac60f72ecd48a Mon Sep 17 00:00:00 2001 From: Hugo Rodger-Brown Date: Thu, 5 Oct 2023 11:19:07 +0100 Subject: [PATCH] Change display_model_anonymisation to anonymisation_config --- ...l_anonymisation.py => anonymisation_config.py} | 15 ++++++++++++++- .../templates/anonymiser/anonymisation_config.csv | 2 ++ ...l_anonymisation.md => anonymisation_config.md} | 0 3 files changed, 16 insertions(+), 1 deletion(-) rename anonymiser/management/commands/{display_model_anonymisation.py => anonymisation_config.py} (75%) create mode 100644 anonymiser/templates/anonymiser/anonymisation_config.csv rename anonymiser/templates/anonymiser/{display_model_anonymisation.md => anonymisation_config.md} (100%) diff --git a/anonymiser/management/commands/display_model_anonymisation.py b/anonymiser/management/commands/anonymisation_config.py similarity index 75% rename from anonymiser/management/commands/display_model_anonymisation.py rename to anonymiser/management/commands/anonymisation_config.py index c48f000..a91bac9 100644 --- a/anonymiser/management/commands/display_model_anonymisation.py +++ b/anonymiser/management/commands/anonymisation_config.py @@ -40,9 +40,22 @@ def get_model_anonymisers() -> list[ModelAnonymiserSummary]: class Command(BaseCommand): + help = "Display anonymisation configuration" # noqa: A003 + + def add_arguments(self, parser: Any) -> None: + parser.add_argument( + "-t", + "--template", + default="anonymisation_config.md", + help=( + "Template to use for output (defaults to " "anonymisation_config.md)." + ), + ) + def handle(self, *args: Any, **options: Any) -> None: + template_name = options["template"] out = render_to_string( - "anonymiser/display_model_anonymisation.md", + f"anonymiser/{template_name}", { "model_anonymisers": get_model_anonymisers(), "model_fields": registry.get_all_model_fields(), diff --git a/anonymiser/templates/anonymiser/anonymisation_config.csv b/anonymiser/templates/anonymiser/anonymisation_config.csv new file mode 100644 index 0000000..6b8d6fb --- /dev/null +++ b/anonymiser/templates/anonymiser/anonymisation_config.csv @@ -0,0 +1,2 @@ +App,Model,Field,Type,Anonymise,Redact{% for model,fields in model_fields.items %}{% for field in fields %} +{{ field.app_label }},{{ field.model_name }},{{ field.field_name }},{{ field.field_type }},{% if field.is_anonymised %}X{% else %}-{% endif %},{{ field.redaction_strategy|default:"-"|upper }}{% endfor %}{% endfor %} diff --git a/anonymiser/templates/anonymiser/display_model_anonymisation.md b/anonymiser/templates/anonymiser/anonymisation_config.md similarity index 100% rename from anonymiser/templates/anonymiser/display_model_anonymisation.md rename to anonymiser/templates/anonymiser/anonymisation_config.md