Peter Pfeufer a6b340c179
update code to reflect the new minimum python version 3.7
- update string format method
- remove redundant default arguments from function  calls
- remove unused imports
- remove unicode identifier from strings, it's default in py3 (see: https://stackoverflow.com/a/4182635/12201331)
2021-10-18 11:59:05 +02:00

21 lines
1.0 KiB
Python

from django.core.management.base import BaseCommand
from allianceauth.authentication.models import UserProfile
class Command(BaseCommand):
help = 'Ensures all main characters have an active ownership'
def handle(self, *args, **options):
profiles = UserProfile.objects.filter(main_character__isnull=False).filter(
main_character__character_ownership__isnull=True)
if profiles.exists():
for profile in profiles:
self.stdout.write(self.style.ERROR(
'{} does not have an ownership. Resetting user {} main character.'.format(profile.main_character,
profile.user)))
profile.main_character = None
profile.save()
self.stdout.write(self.style.WARNING(f'Reset {profiles.count()} main characters.'))
else:
self.stdout.write(self.style.SUCCESS('All main characters have active ownership.'))