Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GDPR + Django Model Collector

GDPR + Django Model Collector

Slides for lightning talk, given at the Python DBBUG Meetup (Potato Bristol, Nov 2018)

More detailed description + additional practical stuff at:

https://blog.eleni.co/gdpr-django-collector/

Eleni Lixourioti

November 15, 2018
Tweet

More Decks by Eleni Lixourioti

Other Decks in Technology

Transcript

  1. "Umm yeah, if you could you fetch their data that'd

    be great" — a manager Eleni Lixourio, | @geekfish_ | Python DBBUG
  2. It's not that I'm lazy... ...it's just that there's an

    easier way! Eleni Lixourio, | @geekfish_ | Python DBBUG
  3. class Book(models.Model): author = models.ForeignKey(User, on_delete=CASCADE) vs CREATE TABLE books

    ( FOREIGN KEY (author_id) REFERENCES users (id) ON DELETE CASCADE ); Eleni Lixourio, | @geekfish_ | Python DBBUG
  4. ON DELETE CASCADE "No, thanks. I like mine be3er" —

    Django Eleni Lixourio, | @geekfish_ | Python DBBUG
  5. Django admin • Please don't use it. ... but it

    does some things pre1y well Eleni Lixourio, | @geekfish_ | Python DBBUG
  6. from django.contrib.admin.utils import NestedObjects def collect_user_data(user): collector = NestedObjects(using="replica") collector.collect([user])

    return collector.data > pprint(collect_user_data(user)) > OrderedDict([(<class 'my_app.models.User'>, > {<User: [email protected]>}), > (<class 'my_app.models.Event'>, > {<Event: Python DBBUG>, <Event: Python Dojo>})]) Eleni Lixourio, | @geekfish_ | Python DBBUG
  7. from django.contrib.admin.utils import NestedObjects class CustomUserCollector(NestedObjects): def __init__(self, user, *args,

    **kwargs): self.user = user kwargs['using'] = "replica" super(CustomUserCollector, self).__init__(*args, **kwargs) def collect_all(): self.collect_from_db() self.collect_from_nonrel() self.collect_remote() # ... Eleni Lixourio, | @geekfish_ | Python DBBUG
  8. # from myapp.housekeeping import collect, IP_ASSOCIATED_MODELS # class CustomUserCollector(NestedObjects): #

    ... def collect_from_db(self): self.collect([self.user]) for model in IP_ASSOCIATED_MODELS: self.collect( model.objects.filter(ip__in=self.user.known_ips)) def collect_from_nonrel(self): self.data['couchdb'] = collect.from_couchdb(user) self.data['redis_temp'] = collect.from_redis(user) def collect_remote(self): self.data['some_ext_service'] = collect.from_api(user) Eleni Lixourio, | @geekfish_ | Python DBBUG
  9. Thank you! • Ques&ons? • Read more: h"ps:/ /blog.eleni.co/gdpr-django-collector/ Eleni

    Lixourio, [email protected] @geekfish_ PS: Python Code Dojo: 21/11 via Bristol Codehub