Skip to main content

Your project description goes here

Project description

https://badge.fury.io/py/django-anonymizable-model.svg/?style=flat-square https://readthedocs.org/projects/pip/badge/?version=latest&style=flat-square Coverage Status

Your project description goes here

Documentation

The full documentation is at https://django-anonymizable-model.readthedocs.io.

Quickstart

Install django-anonymizable-model:

pip install django-anonymizable-model

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'anonymizable_model',
    ...
)

Use on your models like this:

@anonymizable(
    db_label_prefix="pa_",
    anonymizable_fields=["first_name", "last_name", "phone_number"]
)
class ExampleGDPRModel(models.Model):
    objects = ExampleGDPRModelManager.from_queryset(ExampleGDPRModelQuerySet)()

    first_name = models.CharField("First name", max_length=255)
    last_name = models.CharField("Last name", max_length=255)
    phone_number = models.CharField("Phone number", max_length=255, blank=True, default="")
    description = models.TextField("Description", blank=True, default="")

It is possible to change db_label_prefix with your own label and assign anonymizable fields from the model for export and visualization features.

And then run migrations:

$ python manage.py makemigrations
$ python manage.py migrate

For the admin visualization use AnonymizableAdminMixin class:

@admin.register(ExampleGDPRModel)
class ExampleGDPRModelAdmin(AnonymizableAdminMixin, admin.ModelAdmin):
    list_display = (
        "__str__",
        "first_name",
        "last_name",
        "phone_number",
        "description",
    )

    fieldsets = (
        (None, {"fields": (
            ("first_name", "last_name"),
            ("phone_number", "description"),
        )}),
    )

The admin can view all anonymized data in fields. If a staff user does not have can_view_anonymized_fields permission all the data in anonymizable_fields will be substituted with “…”.

Anonymize DATABASE

It is possible to anonymize data directly in database using:

$ python manage.py anonymize_database

Features

  • Remove or override __str__ method to display “…” if user does not have permission

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Development commands

pip install -r requirements_dev.txt
invoke -l

Credits

Tools used in rendering this package:

History

0.1.7 (2021-10-11)

  • First release on PyPI.

0.1.8 (2021-10-12)

  • Updated version for github actions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-anonymizable-model-0.1.8.tar.gz (10.8 kB view hashes)

Uploaded Source

Built Distribution

django_anonymizable_model-0.1.8-py2.py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page