You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
907 B
28 lines
907 B
from django.core.management.base import BaseCommand
|
|
from django.db import transaction
|
|
from django.db.models import Q
|
|
|
|
from apps.account.models import User
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Assign slugs to all professor users that currently lack one."
|
|
|
|
def handle(self, *args, **options):
|
|
professors = User.objects.filter(
|
|
user_type=User.UserType.PROFESSOR
|
|
).filter(Q(slug__isnull=True) | Q(slug=""))
|
|
|
|
if not professors.exists():
|
|
self.stdout.write(self.style.SUCCESS("All professor users already have slugs."))
|
|
return
|
|
|
|
updated = 0
|
|
with transaction.atomic():
|
|
for professor in professors.iterator():
|
|
if professor.ensure_professor_profile():
|
|
updated += 1
|
|
|
|
self.stdout.write(
|
|
self.style.SUCCESS(f"Assigned slugs to {updated} professor user(s).")
|
|
)
|