forked from Kamva-Academy/Kamva-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
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
7b7e784
commit eccdb0c
Showing
1 changed file
with
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.core.management.base import BaseCommand | ||
from apps.accounts.models import UserWebsite | ||
from django.db import transaction | ||
import uuid | ||
|
||
|
||
def is_username_uuid(username): | ||
try: | ||
# Try to create a UUID from the username | ||
uuid_obj = uuid.UUID(username) | ||
# If successful, check that it matches the original (to ensure valid format) | ||
return str(uuid_obj) == username | ||
except ValueError: | ||
# If an error occurs, it's not a valid UUID | ||
return False | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def handle(self, *args, **options): | ||
|
||
user_websites = UserWebsite.objects.exclude(website='filmbazi') | ||
|
||
@transaction.atomic | ||
def do(): | ||
for user_website in user_websites: | ||
user = user_website.user | ||
if is_username_uuid(user.username): | ||
if UserWebsite.objects.filter(user=user, website='filmbazi').exists(): | ||
user_website.delete() | ||
else: | ||
user_website.website = 'filmbazi' | ||
user_website.save() | ||
|
||
do() |