Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hugorodgerbrown committed Oct 5, 2023
1 parent 13fe7d8 commit 9813106
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions anonymiser/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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]]:
Expand All @@ -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()

0 comments on commit 9813106

Please sign in to comment.