-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout d'une commande pour la migration de Gravatar à jdenticon
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from hashlib import md5 | ||
|
||
import requests | ||
from django.core.management.base import BaseCommand | ||
|
||
from zds.member.models import Profile | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Migrate from Gravatar" | ||
|
||
def handle(self, *args, **options): | ||
for profile in Profile.objects.select_related("user").filter(avatar_url__isnull=True).iterator(): | ||
hash = md5(profile.user.email.lower().encode("utf-8")).hexdigest() | ||
gravatar_url = f"https://secure.gravatar.com/avatar/{hash}" | ||
r = requests.get(f"{gravatar_url}?d=404") | ||
if r.status_code == 200: | ||
profile.avatar_url = f"{gravatar_url}?s=200" | ||
profile.save() | ||
self.stdout.write(self.style.SUCCESS(f"Successfully migrated from Gravatar!")) |