Skip to content

Commit

Permalink
fix: fix incorrect user-websites
Browse files Browse the repository at this point in the history
  • Loading branch information
AmooHashem committed Nov 26, 2024
1 parent 7b7e784 commit eccdb0c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions apps/accounts/management/commands/fix_userwebsites.py
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()

0 comments on commit eccdb0c

Please sign in to comment.