From 9813106f0fee4234900a2948a7490d8460a7f168 Mon Sep 17 00:00:00 2001 From: Hugo Rodger-Brown Date: Thu, 5 Oct 2023 10:43:43 +0100 Subject: [PATCH] Refactoring --- anonymiser/registry.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/anonymiser/registry.py b/anonymiser/registry.py index 21e67a7..7383eb7 100644 --- a/anonymiser/registry.py +++ b/anonymiser/registry.py @@ -18,12 +18,9 @@ def sort_by_name(models: list[type[models.Model]]) -> list[type[models.Model]]: class Registry(dict): - def anonymisable_models(self) -> list[type[models.Model]]: + def get_anonymisable_models(self) -> list[type[models.Model]]: return sort_by_name([m for m in self.keys() if self[m]]) - def non_anonymisable_models(self) -> list[type[models.Model]]: - return sort_by_name([m for m in self.keys() if self[m] is None]) - def is_model_anonymisable(self, model: type[models.Model]) -> bool: return bool(self[model]) @@ -48,6 +45,11 @@ def get_model_anonymiser(model: type[models.Model]) -> ModelAnonymiser | None: return None +def get_anonymisable_models() -> list[type[models.Model]]: + """Return all models that have an anonymiser.""" + return _registry.get_anonymisable_models() + + def get_all_model_fields( anonymised_only: bool = False, ) -> dict[str, list[ModelFieldSummary]]: @@ -73,5 +75,5 @@ def get_all_model_fields( return dict(output) -# Registry object - initialised in init_registry() -_registry: Registry = Registry() +# principle access point for the registry +_registry = Registry()