forked from doubaniux/boofilsic
-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cca52c
commit 620df78
Showing
4 changed files
with
48 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
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
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,31 @@ | ||
from datetime import timedelta | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
from tqdm import tqdm | ||
|
||
from users.models import User | ||
from users.models.user import _RESERVED_USERNAMES | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Generate unique username" | ||
|
||
def handle(self, *args, **options): | ||
count = 0 | ||
for user in User.objects.filter(username__isnull=True).order_by("date_joined"): | ||
if not user.is_active: | ||
un = f"-{user.pk}-" | ||
else: | ||
un = user.mastodon_username | ||
if not un: | ||
un = f"_{user.pk}" | ||
if un.lower() in _RESERVED_USERNAMES: | ||
un = f"__{un}" | ||
if User.objects.filter(username=un).exists(): | ||
un = f"{un}_{user.pk}" | ||
print(f"{user} -> un") | ||
user.username = un | ||
user.save(update_fields=["username"]) | ||
count += 1 | ||
print(f"{count} users updated") |
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