Fundraising in PDF.
[wolnelektury.git] / src / wolnelektury / management / commands / clean_social_accounts.py
1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 from allauth.socialaccount.models import SocialAccount
5 from django.core.management.base import BaseCommand
6
7
8 KEPT_FIELDS = {
9     'facebook': ['link', 'name', 'id', 'locale', 'timezone', 'updated_time', 'verified'],
10     'google': ['name', 'picture', 'locale', 'id', 'verified_email', 'link'],
11 }
12
13
14 class Command(BaseCommand):
15     def handle(self, *args, **options):
16         for provider, kept_fields in KEPT_FIELDS.items():
17             for sa in SocialAccount.objects.filter(provider=provider):
18                 trimmed_data = {k: v for k, v in sa.extra_data.items() if k in kept_fields}
19                 sa.extra_data = trimmed_data
20                 sa.save()