2018-07-22 10:20:16 +00:00
|
|
|
"""
|
|
|
|
Compute different sizes of image used for Album covers and User avatars
|
|
|
|
"""
|
|
|
|
from django.db.utils import IntegrityError
|
|
|
|
|
|
|
|
from funkwhale_api.users.models import User, create_actor
|
|
|
|
|
|
|
|
|
|
|
|
def main(command, **kwargs):
|
|
|
|
qs = User.objects.filter(actor__isnull=True).order_by("username")
|
|
|
|
total = len(qs)
|
2022-11-23 21:36:56 +00:00
|
|
|
command.stdout.write(f"{total} users found without actors")
|
2018-07-22 10:20:16 +00:00
|
|
|
for i, user in enumerate(qs):
|
2022-11-23 21:36:56 +00:00
|
|
|
command.stdout.write(f"{i + 1}/{total} creating actor for {user.username}")
|
2018-07-22 10:20:16 +00:00
|
|
|
try:
|
|
|
|
user.actor = create_actor(user)
|
|
|
|
except IntegrityError as e:
|
|
|
|
# somehow, an actor with the the url exists in the database
|
2022-11-23 21:36:56 +00:00
|
|
|
command.stderr.write(f"Error while creating actor: {str(e)}")
|
2018-07-22 10:20:16 +00:00
|
|
|
continue
|
|
|
|
user.save(update_fields=["actor"])
|