Changeset View
Changeset View
Standalone View
Standalone View
profiles/management/commands/copy_avatars.py
- This file was added.
| """Fetch and save profile images from Blender ID.""" | |||||
| from django.contrib.auth.models import User | |||||
| from django.core.management.base import BaseCommand | |||||
| class CopyAvatarFromBlenderID(BaseCommand): | |||||
| """Command for fetching and saving profile images for accounts that don't have any.""" | |||||
| def handle(self, *args, **options): # noqa: D102 | |||||
| for user in User.objects.filter(last_login__isnull=False, image__isnull=True).order_by( | |||||
| '-last_login' | |||||
| ): | |||||
| print(user.last_login) | |||||
| break | |||||
| if getattr(user, 'profile', None): | |||||
| if user.profile.image: | |||||
| continue # already has profile image, skipping | |||||
| user.profile.copy_avatar_from_blender_id() | |||||